Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(51222): Go-to-definition on return statements should jump to the containing function declaration #51227

Merged
merged 2 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/services/goToDefinition.ts
Expand Up @@ -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;
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
return functionDeclaration ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
}

if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) {
const classDecl = node.parent.parent;
const { symbol, failedAliasResolution } = getSymbol(classDecl, typeChecker, stopAtAlias);
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/fourslash/goToDefinitionReturn1.ts
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

////function /*end*/foo() {
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
//// [|/*start*/return|] 10;
////}

verify.goToDefinition("start", "end");
9 changes: 9 additions & 0 deletions tests/cases/fourslash/goToDefinitionReturn2.ts
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

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

verify.goToDefinition("start", "end");
9 changes: 9 additions & 0 deletions tests/cases/fourslash/goToDefinitionReturn3.ts
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

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

verify.goToDefinition("start", "end");
5 changes: 5 additions & 0 deletions tests/cases/fourslash/goToDefinitionReturn4.ts
@@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />

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

verify.goToDefinition("start", []);
9 changes: 9 additions & 0 deletions tests/cases/fourslash/goToDefinitionReturn5.ts
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

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

verify.goToDefinition("start", []);
9 changes: 9 additions & 0 deletions tests/cases/fourslash/goToDefinitionReturn6.ts
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

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

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