Skip to content
Permalink
Browse files
fix(51222): Go-to-definition on return statements should jump to the …
…containing function declaration (#51227)

* fix(51222): add go-to-definition return statement to containing function

* add additional tests
  • Loading branch information
a-tarasyuk committed Oct 19, 2022
1 parent 2dff34e commit 245a02cbed7ad50a21289730159abc8d19a66f40
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
@@ -26,6 +26,12 @@ namespace ts.GoToDefinition {
return label ? [createDefinitionInfoFromName(typeChecker, label, ScriptElementKind.label, node.text, /*containerName*/ undefined!)] : undefined; // TODO: GH#18217
}

if (node.kind === SyntaxKind.ReturnKeyword) {
const functionDeclaration = findAncestor(node.parent, n =>
isClassStaticBlockDeclaration(n) ? "quit" : isFunctionLikeDeclaration(n)) as FunctionLikeDeclaration;
return functionDeclaration ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
}

if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) {
const classDecl = node.parent.parent;
const { symbol, failedAliasResolution } = getSymbol(classDecl, typeChecker, stopAtAlias);
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

////function /*end*/foo() {
//// [|/*start*/return|] 10;
////}

verify.goToDefinition("start", "end");
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

////function foo() {
//// return /*end*/() => {
//// [|/*start*/return|] 10;
//// }
////}

verify.goToDefinition("start", "end");
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

////class C {
//// /*end*/m() {
//// [|/*start*/return|] 1;
//// }
////}

verify.goToDefinition("start", "end");
@@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />

////[|/*start*/return|];

verify.goToDefinition("start", []);
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

////function foo() {
//// class Foo {
//// static { [|/*start*/return|]; }
//// }
////}

verify.goToDefinition("start", []);
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

////function foo() {
//// return /*end*/function () {
//// [|/*start*/return|] 10;
//// }
////}

verify.goToDefinition("start", "end");
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

////function foo(a: string, b: string): string;
////function foo(a: number, b: number): number;
////function /*end*/foo(a: any, b: any): any {
//// [|/*start*/return|] a + b;
////}

verify.goToDefinition("start", "end");

0 comments on commit 245a02c

Please sign in to comment.