Skip to content

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

Closed

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)

Activity

  1. added
    Domain: API
    Domain: LS: TSServer
    Suggestion
    on Jul 8, 2020
  2. added
    Committed
    VS Code Priority
    on Oct 28, 2020
  3. removed
    VS Code Priority
    on Oct 28, 2020
  4. added
    Fix Available
    on Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CommittedDomain: APIDomain: LS: TSServerFix AvailableSuggestion

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions