From 916e67a92c0c9d348ac74f8f3e78374d55964d78 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 Jan 2017 08:32:08 -0800 Subject: [PATCH] For goToDefinition, verify that tryGetSignatureDeclaration returns a signature declaration and not a FunctionType. --- src/services/goToDefinition.ts | 17 +++++++++++++++-- .../fourslash/goToDefinitionFunctionType.ts | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/goToDefinitionFunctionType.ts diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index ab35a17fcef..73cf06d31ef 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -187,7 +187,15 @@ namespace ts.GoToDefinition { } function isSignatureDeclaration(node: Node): boolean { - return node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature + switch (node.kind) { + case ts.SyntaxKind.Constructor: + case ts.SyntaxKind.FunctionDeclaration: + case ts.SyntaxKind.MethodDeclaration: + case ts.SyntaxKind.MethodSignature: + return true; + default: + return false; + } } /** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */ @@ -254,6 +262,11 @@ namespace ts.GoToDefinition { function tryGetSignatureDeclaration(typeChecker: TypeChecker, node: Node): SignatureDeclaration | undefined { const callLike = getAncestorCallLikeExpression(node); - return callLike && typeChecker.getResolvedSignature(callLike).declaration; + const decl = callLike && typeChecker.getResolvedSignature(callLike).declaration; + if (decl && isSignatureDeclaration(decl)) { + return decl; + } + // Don't go to a function type, go to the value having that type. + return undefined; } } diff --git a/tests/cases/fourslash/goToDefinitionFunctionType.ts b/tests/cases/fourslash/goToDefinitionFunctionType.ts new file mode 100644 index 00000000000..1b50de3af6d --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionFunctionType.ts @@ -0,0 +1,17 @@ +/// + +// Tests that goToDefinition does not go to a function type; it goes to the value. + +////const /*constDefinition*/c: () => void; +/////*constReference*/c(); +////function test(/*cbDefinition*/cb: () => void) { +//// /*cbReference*/cb(); +////} +////class C { +//// /*propDefinition*/prop: () => void; +//// m() { +//// this./*propReference*/prop(); +//// } +////} + +verify.goToDefinitionForMarkers("const", "cb", "prop");