diff --git a/src/services/completions.ts b/src/services/completions.ts index 40053d2e87..18cb2ed9b7 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2209,8 +2209,9 @@ namespace ts.Completions { function isNewIdentifierDefinitionLocation(): boolean { if (contextToken) { const containingNodeKind = contextToken.parent.kind; + const tokenKind = keywordForNode(contextToken); // Previous token may have been a keyword that was converted to an identifier. - switch (keywordForNode(contextToken)) { + switch (tokenKind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.CallExpression // func( a, | || containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ @@ -2254,10 +2255,13 @@ namespace ts.Completions { case SyntaxKind.TemplateMiddle: return containingNodeKind === SyntaxKind.TemplateSpan; // `aa ${10} dd ${| - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - return containingNodeKind === SyntaxKind.PropertyDeclaration; // class A{ public | + case SyntaxKind.AsyncKeyword: + return containingNodeKind === SyntaxKind.MethodDeclaration // const obj = { async c|() + || containingNodeKind === SyntaxKind.ShorthandPropertyAssignment; // const obj = { async c| + } + + if (isClassMemberCompletionKeyword(tokenKind)) { + return true; } } diff --git a/tests/cases/fourslash/completionsAsyncMethodDeclaration.ts b/tests/cases/fourslash/completionsAsyncMethodDeclaration.ts new file mode 100644 index 0000000000..ddb3070d2d --- /dev/null +++ b/tests/cases/fourslash/completionsAsyncMethodDeclaration.ts @@ -0,0 +1,25 @@ +/// + +//// const obj = { +//// a() {}, +//// async b/*1*/ +//// }; +//// const obj2 = { +//// async /*2*/ +//// }; +//// class Foo { +//// async b/*3*/ +//// } +//// class Foo2 { +//// async /*4*/ +//// } +//// class Bar { +//// static async b/*5*/ +//// } + +test.markerNames().forEach(marker => { + verify.completions({ + marker, + isNewIdentifierLocation: true + }); +});