microsoft / microsoft/TypeScript

When Invoking "Go To Implementation" For Parameters, Go To Arguments

Offen
#55,094 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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:

Code_-_Insiders_f7EoFPs8cb

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)

Code_-_Insiders_LGZpHeaJJF

Ideally, this would also work for named tuples:

Code_-_Insiders_3WPPBeW6Lh

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie damit, die TypeScript-Sprachserver-Implementierung für Go To Implementation und den Referenzsuchpfad nachzuverfolgen. Untersuchen Sie die Behandlung von CallExpression mit checker.getResolvedSignature(s) und wie Parametersymbole verknüpft werden. Als abgeschlossen gilt die Aufgabe, wenn Parameterimplementierungen zu den entsprechenden Argumenten springen, einschließlich des named-tuple-Beispiels, und die dokumentierten Fälle validiert sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.