microsoft / microsoft/TypeScript
When Invoking "Go To Implementation" For Parameters, Go To Arguments
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia tracciando l’implementazione del language server TypeScript per Go To Implementation e il percorso di ricerca dei riferimenti. Analizza la gestione di CallExpression con checker.getResolvedSignature(s) e il modo in cui vengono collegati i simboli dei parametri. Il lavoro è concluso quando le implementazioni dei parametri passano agli argomenti corrispondenti, incluso l’esempio di named-tuple, e i casi documentati sono validati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100