Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mjbvz opened this issue Jul 8, 2020 · 1 comment · Fixed by #41805
Closed

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

mjbvz opened this issue Jul 8, 2020 · 1 comment · Fixed by #41805
Assignees
Labels
API Relates to the public API for TypeScript Committed The team has roadmapped this issue Domain: TSServer Issues related to the TSServer Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jul 8, 2020

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)

@DanielRosenwasser DanielRosenwasser added API Relates to the public API for TypeScript Domain: TSServer Issues related to the TSServer Suggestion An idea for TypeScript labels Jul 8, 2020
@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone labels Oct 28, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.0 milestone Oct 28, 2020
@sheetalkamat
Copy link
Member

https://github.com/microsoft/TypeScript/blob/master/src/compiler/program.ts#L758 this should have list where file is referenced from

@mjbvz mjbvz removed the VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone label Oct 28, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Committed The team has roadmapped this issue Domain: TSServer Issues related to the TSServer Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants