microsoft / microsoft/TypeScript

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

Abierto
#55,094 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza rastreando la implementación del servidor de lenguaje de TypeScript para Go To Implementation y la ruta de búsqueda de referencias. Investiga el manejo de CallExpression con checker.getResolvedSignature(s) y cómo se vinculan los símbolos de los parámetros. Se considera terminado cuando las implementaciones de parámetros saltan a los argumentos correspondientes, incluido el ejemplo de named-tuple, y los casos documentados están validados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
tooling
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.