Skip to content

[tsserver] api to find references to a file  #39489

Closed
@mjbvz

Description

@mjbvz

Search Terms

  • find references (shift f12)
  • TypeScript server

Problem

If you run find all references on an import path, tsserver will return a list of locations where this file is imported:

Screen Shot 2020-07-07 at 5 18 53 PM

However it would also be useful to be able to run this command for a file without first having to find where it is imported. Some example use cases:

  • Add a command to find references for the currently active file.
  • Add a right click option in the explorer to find references to a selected file.

See microsoft/vscode#66150 for details on the VS Code side

Proposal

Add a new FileReferences request to the tsserver protocol. This command would take a file path (and optional project name) and return a list of references:

interface FileReferencesRequest extends FileRequest {
    // empty 
}

interface FileReferencesResponseBody {
	/**
	 * The file locations referencing the symbol.
	 */
	refs: readonly ReferencesResponseItem[];
	/**
	 * The name of the symbol.
	 */
	symbolName: string;
}

interface FileReferencesResponse extends Response {
	body?: FileReferencesResponseBody;
}

Running this command should return a list of locations where the given file is imported (this matches what running find all references on an import path does)

Metadata

Metadata

Assignees

Labels

APIRelates to the public API for TypeScriptCommittedThe team has roadmapped this issueDomain: TSServerIssues related to the TSServerFix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions