Skip to content

Commit feb08b8

Browse files
author
Andy
authored
Merge pull request #13686 from Microsoft/goToDefinition_callback
For goToDefinition, verify that tryGetSignatureDeclaration returns a signature declaration and not a FunctionType.
2 parents 5644b01 + 916e67a commit feb08b8

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/services/goToDefinition.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,15 @@ namespace ts.GoToDefinition {
187187
}
188188

189189
function isSignatureDeclaration(node: Node): boolean {
190-
return node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature
190+
switch (node.kind) {
191+
case ts.SyntaxKind.Constructor:
192+
case ts.SyntaxKind.FunctionDeclaration:
193+
case ts.SyntaxKind.MethodDeclaration:
194+
case ts.SyntaxKind.MethodSignature:
195+
return true;
196+
default:
197+
return false;
198+
}
191199
}
192200

193201
/** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
@@ -254,6 +262,11 @@ namespace ts.GoToDefinition {
254262

255263
function tryGetSignatureDeclaration(typeChecker: TypeChecker, node: Node): SignatureDeclaration | undefined {
256264
const callLike = getAncestorCallLikeExpression(node);
257-
return callLike && typeChecker.getResolvedSignature(callLike).declaration;
265+
const decl = callLike && typeChecker.getResolvedSignature(callLike).declaration;
266+
if (decl && isSignatureDeclaration(decl)) {
267+
return decl;
268+
}
269+
// Don't go to a function type, go to the value having that type.
270+
return undefined;
258271
}
259272
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// Tests that goToDefinition does not go to a function type; it goes to the value.
4+
5+
////const /*constDefinition*/c: () => void;
6+
/////*constReference*/c();
7+
////function test(/*cbDefinition*/cb: () => void) {
8+
//// /*cbReference*/cb();
9+
////}
10+
////class C {
11+
//// /*propDefinition*/prop: () => void;
12+
//// m() {
13+
//// this./*propReference*/prop();
14+
//// }
15+
////}
16+
17+
verify.goToDefinitionForMarkers("const", "cb", "prop");

0 commit comments

Comments
 (0)