Skip to content

Commit 245a02c

Browse files
authoredOct 19, 2022
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
1 parent 2dff34e commit 245a02c

8 files changed

+63
-0
lines changed
 

‎src/services/goToDefinition.ts

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ namespace ts.GoToDefinition {
2626
return label ? [createDefinitionInfoFromName(typeChecker, label, ScriptElementKind.label, node.text, /*containerName*/ undefined!)] : undefined; // TODO: GH#18217
2727
}
2828

29+
if (node.kind === SyntaxKind.ReturnKeyword) {
30+
const functionDeclaration = findAncestor(node.parent, n =>
31+
isClassStaticBlockDeclaration(n) ? "quit" : isFunctionLikeDeclaration(n)) as FunctionLikeDeclaration;
32+
return functionDeclaration ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
33+
}
34+
2935
if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) {
3036
const classDecl = node.parent.parent;
3137
const { symbol, failedAliasResolution } = getSymbol(classDecl, typeChecker, stopAtAlias);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function /*end*/foo() {
4+
//// [|/*start*/return|] 10;
5+
////}
6+
7+
verify.goToDefinition("start", "end");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function foo() {
4+
//// return /*end*/() => {
5+
//// [|/*start*/return|] 10;
6+
//// }
7+
////}
8+
9+
verify.goToDefinition("start", "end");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class C {
4+
//// /*end*/m() {
5+
//// [|/*start*/return|] 1;
6+
//// }
7+
////}
8+
9+
verify.goToDefinition("start", "end");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////[|/*start*/return|];
4+
5+
verify.goToDefinition("start", []);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function foo() {
4+
//// class Foo {
5+
//// static { [|/*start*/return|]; }
6+
//// }
7+
////}
8+
9+
verify.goToDefinition("start", []);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function foo() {
4+
//// return /*end*/function () {
5+
//// [|/*start*/return|] 10;
6+
//// }
7+
////}
8+
9+
verify.goToDefinition("start", "end");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function foo(a: string, b: string): string;
4+
////function foo(a: number, b: number): number;
5+
////function /*end*/foo(a: any, b: any): any {
6+
//// [|/*start*/return|] a + b;
7+
////}
8+
9+
verify.goToDefinition("start", "end");

0 commit comments

Comments
 (0)