Skip to content

Commit a2321bc

Browse files
Zzzensandersn
authored andcommitted
enable go-to-type-definition on type nodes (microsoft#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 <[email protected]> Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 06988d4 commit a2321bc

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/services/goToDefinition.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,17 @@ namespace ts.GoToDefinition {
198198
return undefined;
199199
}
200200

201-
const symbol = typeChecker.getSymbolAtLocation(node);
201+
const symbol = getSymbol(node, typeChecker);
202202
if (!symbol) return undefined;
203203

204204
const typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
205205
const returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
206206
const fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
207207
// If a function returns 'void' or some other type with no definition, just return the function definition.
208-
return fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
208+
const typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
209+
return typeDefinitions.length ? typeDefinitions
210+
: !(symbol.flags & SymbolFlags.Value) && symbol.flags & SymbolFlags.Type ? getDefinitionFromSymbol(typeChecker, skipAlias(symbol, typeChecker), node)
211+
: undefined;
209212
}
210213

211214
function definitionFromType(type: Type, checker: TypeChecker, node: Node): readonly DefinitionInfo[] {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////type /*definition*/T = string;
4+
////const x: /*reference*/T;
5+
6+
verify.goToType("reference", "definition");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: foo.ts
4+
////export type /*def0*/T = string;
5+
////export const /*def1*/T = "";
6+
7+
// @Filename: bar.ts
8+
////import { T } from "./foo";
9+
////let x: [|/*reference*/T|];
10+
11+
verify.goToType("reference", []);
12+
verify.goToDefinition("reference", ["def0", "def1"]);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: foo.ts
4+
////let Foo: /*definition*/unresolved;
5+
////type Foo = { x: string };
6+
7+
/////*reference*/Foo;
8+
9+
10+
verify.goToType("reference", []);

0 commit comments

Comments
 (0)