Skip to content

Commit fedcd3a

Browse files
KingwlAndy
authored and
Andy
committed
improve completions keyword for function like body (microsoft#25824)
1 parent 9891569 commit fedcd3a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/services/completions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ namespace ts.Completions {
21252125
case KeywordCompletionFilters.ConstructorParameterKeywords:
21262126
return isParameterPropertyModifier(kind);
21272127
case KeywordCompletionFilters.FunctionLikeBodyKeywords:
2128-
return !isClassMemberCompletionKeyword(kind);
2128+
return isFunctionLikeBodyKeyword(kind);
21292129
case KeywordCompletionFilters.TypeKeywords:
21302130
return isTypeKeyword(kind);
21312131
default:
@@ -2151,6 +2151,10 @@ namespace ts.Completions {
21512151
}
21522152
}
21532153

2154+
function isFunctionLikeBodyKeyword(kind: SyntaxKind) {
2155+
return kind === SyntaxKind.AsyncKeyword || !isClassMemberCompletionKeyword(kind);
2156+
}
2157+
21542158
function keywordForNode(node: Node): SyntaxKind {
21552159
return isIdentifier(node) ? node.originalKeywordKind || SyntaxKind.Unknown : node.kind;
21562160
}

tests/cases/fourslash/completionInFunctionLikeBody.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
goTo.marker("1");
18+
verify.completionListContains("async", "async", /*documentation*/ undefined, "keyword");
1819
verify.not.completionListContains("public", "public", /*documentation*/ undefined, "keyword");
1920
verify.not.completionListContains("private", "private", /*documentation*/ undefined, "keyword");
2021
verify.not.completionListContains("protected", "protected", /*documentation*/ undefined, "keyword");
@@ -26,6 +27,7 @@ verify.not.completionListContains("get", "get", /*documentation*/ undefined, "ke
2627
verify.not.completionListContains("set", "set", /*documentation*/ undefined, "keyword");
2728

2829
goTo.marker("2");
30+
verify.completionListContains("async", "async", /*documentation*/ undefined, "keyword");
2931
verify.not.completionListContains("public", "public", /*documentation*/ undefined, "keyword");
3032
verify.not.completionListContains("private", "private", /*documentation*/ undefined, "keyword");
3133
verify.not.completionListContains("protected", "protected", /*documentation*/ undefined, "keyword");
@@ -41,3 +43,4 @@ verify.completionListContainsClassElementKeywords();
4143

4244
goTo.marker("4");
4345
verify.completionListContainsClassElementKeywords();
46+

0 commit comments

Comments
 (0)