mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(51223): Go-to-definition for yield and await keyword; jump to respective function definition (#51838)
This commit is contained in:
parent
e73a51d5d7
commit
8b6f8730c1
@ -131,6 +131,18 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
|
||||
return functionDeclaration ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.AwaitKeyword) {
|
||||
const functionDeclaration = findAncestor(node, n => isFunctionLikeDeclaration(n)) as FunctionLikeDeclaration | undefined;
|
||||
const isAsyncFunction = functionDeclaration && some(functionDeclaration.modifiers, (node) => node.kind === SyntaxKind.AsyncKeyword);
|
||||
return isAsyncFunction ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.YieldKeyword) {
|
||||
const functionDeclaration = findAncestor(node, n => isFunctionLikeDeclaration(n)) as FunctionLikeDeclaration | undefined;
|
||||
const isGeneratorFunction = functionDeclaration && functionDeclaration.asteriskToken;
|
||||
return isGeneratorFunction ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
|
||||
}
|
||||
|
||||
if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) {
|
||||
const classDecl = node.parent.parent;
|
||||
const { symbol, failedAliasResolution } = getSymbol(classDecl, typeChecker, stopAtAlias);
|
||||
|
||||
12
tests/cases/fourslash/goToDefinitionAwait1.ts
Normal file
12
tests/cases/fourslash/goToDefinitionAwait1.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// async function /*end1*/foo() {
|
||||
//// [|/*start1*/await|] Promise.resolve(0);
|
||||
//// }
|
||||
|
||||
//// function notAsync() {
|
||||
//// [|/*start2*/await|] Promise.resolve(0);
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start1", "end1");
|
||||
verify.goToDefinition("start2", []);
|
||||
5
tests/cases/fourslash/goToDefinitionAwait2.ts
Normal file
5
tests/cases/fourslash/goToDefinitionAwait2.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// [|/*start*/await|] Promise.resolve(0);
|
||||
|
||||
verify.goToDefinition("start", []);
|
||||
14
tests/cases/fourslash/goToDefinitionAwait3.ts
Normal file
14
tests/cases/fourslash/goToDefinitionAwait3.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// class C {
|
||||
//// notAsync() {
|
||||
//// [|/*start1*/await|] Promise.resolve(0);
|
||||
//// }
|
||||
////
|
||||
//// async /*end2*/foo() {
|
||||
//// [|/*start2*/await|] Promise.resolve(0);
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start1", []);
|
||||
verify.goToDefinition("start2", "end2");
|
||||
9
tests/cases/fourslash/goToDefinitionAwait4.ts
Normal file
9
tests/cases/fourslash/goToDefinitionAwait4.ts
Normal file
@ -0,0 +1,9 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// async function outerAsyncFun() {
|
||||
//// let /*end*/af = async () => {
|
||||
//// [|/*start*/await|] Promise.resolve(0);
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start", "end");
|
||||
12
tests/cases/fourslash/goToDefinitionYield1.ts
Normal file
12
tests/cases/fourslash/goToDefinitionYield1.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function* /*end1*/gen() {
|
||||
//// [|/*start1*/yield|] 0;
|
||||
//// }
|
||||
////
|
||||
//// const /*end2*/genFunction = function*() {
|
||||
//// [|/*start2*/yield|] 0;
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start1", "end1");
|
||||
verify.goToDefinition("start2", "end2");
|
||||
10
tests/cases/fourslash/goToDefinitionYield2.ts
Normal file
10
tests/cases/fourslash/goToDefinitionYield2.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function* outerGen() {
|
||||
//// function* /*end*/gen() {
|
||||
//// [|/*start*/yield|] 0;
|
||||
//// }
|
||||
//// return gen
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start", "end");
|
||||
14
tests/cases/fourslash/goToDefinitionYield3.ts
Normal file
14
tests/cases/fourslash/goToDefinitionYield3.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// class C {
|
||||
//// notAGenerator() {
|
||||
//// [|/*start1*/yield|] 0;
|
||||
//// }
|
||||
////
|
||||
//// foo*/*end2*/() {
|
||||
//// [|/*start2*/yield|] 0;
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start1", []);
|
||||
verify.goToDefinition("start2", "end2");
|
||||
7
tests/cases/fourslash/goToDefinitionYield4.ts
Normal file
7
tests/cases/fourslash/goToDefinitionYield4.ts
Normal file
@ -0,0 +1,7 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function* gen() {
|
||||
//// class C { [/*start*/yield 10]() {} }
|
||||
//// }
|
||||
|
||||
verify.goToDefinition("start", []);
|
||||
Loading…
x
Reference in New Issue
Block a user