mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 10:32:45 -05:00
enable go-to-type-definition on type nodes (#46714)
* enable go-to-type-definition on type nodes * only go when symbol has no value meaning * Update formatting of src/services/goToDefinition.ts Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
@@ -198,14 +198,17 @@ namespace ts.GoToDefinition {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const symbol = typeChecker.getSymbolAtLocation(node);
|
||||
const symbol = getSymbol(node, typeChecker);
|
||||
if (!symbol) return undefined;
|
||||
|
||||
const typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
|
||||
const returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
|
||||
const fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
|
||||
// If a function returns 'void' or some other type with no definition, just return the function definition.
|
||||
return fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
|
||||
const typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
|
||||
return typeDefinitions.length ? typeDefinitions
|
||||
: !(symbol.flags & SymbolFlags.Value) && symbol.flags & SymbolFlags.Type ? getDefinitionFromSymbol(typeChecker, skipAlias(symbol, typeChecker), node)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function definitionFromType(type: Type, checker: TypeChecker, node: Node): readonly DefinitionInfo[] {
|
||||
|
||||
6
tests/cases/fourslash/goToTypeDefinition3.ts
Normal file
6
tests/cases/fourslash/goToTypeDefinition3.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////type /*definition*/T = string;
|
||||
////const x: /*reference*/T;
|
||||
|
||||
verify.goToType("reference", "definition");
|
||||
12
tests/cases/fourslash/goToTypeDefinition4.ts
Normal file
12
tests/cases/fourslash/goToTypeDefinition4.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: foo.ts
|
||||
////export type /*def0*/T = string;
|
||||
////export const /*def1*/T = "";
|
||||
|
||||
// @Filename: bar.ts
|
||||
////import { T } from "./foo";
|
||||
////let x: [|/*reference*/T|];
|
||||
|
||||
verify.goToType("reference", []);
|
||||
verify.goToDefinition("reference", ["def0", "def1"]);
|
||||
10
tests/cases/fourslash/goToTypeDefinition5.ts
Normal file
10
tests/cases/fourslash/goToTypeDefinition5.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: foo.ts
|
||||
////let Foo: /*definition*/unresolved;
|
||||
////type Foo = { x: string };
|
||||
|
||||
/////*reference*/Foo;
|
||||
|
||||
|
||||
verify.goToType("reference", []);
|
||||
Reference in New Issue
Block a user