microsoft / microsoft/TypeScript
When Invoking "Go To Implementation" For Parameters, Go To Arguments
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Suggestion
🔍 Search Terms
Go To Implementation, Parameter, Go To Arguments
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Context
The TypeScript language server allows to go to implementation for properties. This is super useful, as it allows to quickly jump to possible property values:
function foobar(myArg: { myProperty: number }) {}
foobar({ myProperty: 4 });
⭐ Suggestion
It would be very useful if "Go To Implementation" would be supported for parameters as well, jumping to the corresponding argument: (ignore the comments in the code, they are just there to make the demo work)
Ideally, this would also work for named tuples:
function foobar(myArg1: number) { }
type GetParams<T extends (arg: any) => void> = T extends (...arg: infer P) => void ? P : never;
function f(...args: GetParams<typeof foobar>): void { }
f(/*def:myArg1*/ 1);
📃 Motivation
In VS Code, we use dependency injection and often delegate instantiation of a class to an instantiation service.
This can look like this:
export class TextMateWorkerHost implements IDisposable {
// ...
constructor(
private readonly _reportTokenizationTime: (timeMs: number, languageId: string, sourceExtensionId: string | undefined, lineLength: number, isRandomSample: boolean) => void,
@IExtensionResourceLoaderService private readonly _extensionResourceLoaderService: IExtensionResourceLoaderService,
@IModelService private readonly _modelService: IModelService,
@ILanguageConfigurationService private readonly _languageConfigurationService: ILanguageConfigurationService,
// ...
) {
}
}
This class can be instantiated like this:
class TextMateTokenizationFeature {
private readonly _workerHost = this._instantiationService.createInstance(
TextMateWorkerHost,
(timeMs, languageId, sourceExtensionId, lineLength, isRandomSample) => this.reportTokenizationTime(timeMs, languageId, sourceExtensionId, lineLength, true, isRandomSample)
);
}
I often want to jump from the _reportTokenizationTime field in TextMateWorkerHost to the arrow expression in TextMateTokenizationFeature.
Currently, this is not so easy, as I would need to list all references of TextMateWorkerHost to find this._instantiationService.createInstance(TextMateWorkerHost, .... Then I have to check all arguments and find the right callback.
This feature request would make this very easy, by just jumping to implementation of the parameter _reportTokenizationTime.
(here is a another example of this use-case)
Implementation
I don't know how reference search works in typescript, but using the typescript compiler API, one could traverse all CallExpressions, ask the checker for their signature, query checker.getResolvedSignature(s) and check the returned symbols.
Unfortunately it seems like the symbol with name myArg1 returned for the first parameter of f is not linked to the parameter symbol with name myArg1 of foobar.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the TypeScript language-server implementation for Go To Implementation and the reference-search path. Investigate CallExpression handling with checker.getResolvedSignature(s) and how parameter symbols are linked. Done means parameter implementations jump to corresponding arguments, including the named-tuple example, with the documented cases validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100