@@ -20,6 +20,7 @@ namespace ts.Completions {
20
20
None ,
21
21
ClassElementKeywords , // Keywords at class keyword
22
22
ConstructorParameterKeywords , // Keywords at constructor parameter
23
+ FunctionLikeBodyKeywords // Keywords at function like body
23
24
}
24
25
25
26
export function getCompletionsAtPosition (
@@ -1060,6 +1061,10 @@ namespace ts.Completions {
1060
1061
return true ;
1061
1062
}
1062
1063
1064
+ if ( tryGetFunctionLikeBodyCompletionContainer ( contextToken ) ) {
1065
+ keywordFilters = KeywordCompletionFilters . FunctionLikeBodyKeywords ;
1066
+ }
1067
+
1063
1068
if ( classLikeContainer = tryGetClassLikeCompletionContainer ( contextToken ) ) {
1064
1069
// cursor inside class declaration
1065
1070
getGetClassLikeCompletionSymbols ( classLikeContainer ) ;
@@ -1688,6 +1693,22 @@ namespace ts.Completions {
1688
1693
return undefined ;
1689
1694
}
1690
1695
1696
+ function tryGetFunctionLikeBodyCompletionContainer ( contextToken : Node ) : FunctionLikeDeclaration {
1697
+ if ( contextToken ) {
1698
+ let prev : Node ;
1699
+ const container = findAncestor ( contextToken . parent , ( node : Node ) => {
1700
+ if ( isClassLike ( node ) ) {
1701
+ return "quit" ;
1702
+ }
1703
+ if ( isFunctionLikeDeclaration ( node ) && prev === node . body ) {
1704
+ return true ;
1705
+ }
1706
+ prev = node ;
1707
+ } ) ;
1708
+ return container && container as FunctionLikeDeclaration ;
1709
+ }
1710
+ }
1711
+
1691
1712
function tryGetContainingJsxElement ( contextToken : Node ) : JsxOpeningLikeElement {
1692
1713
if ( contextToken ) {
1693
1714
const parent = contextToken . parent ;
@@ -2126,6 +2147,8 @@ namespace ts.Completions {
2126
2147
return getFilteredKeywordCompletions ( isClassMemberCompletionKeywordText ) ;
2127
2148
case KeywordCompletionFilters . ConstructorParameterKeywords :
2128
2149
return getFilteredKeywordCompletions ( isConstructorParameterCompletionKeywordText ) ;
2150
+ case KeywordCompletionFilters . FunctionLikeBodyKeywords :
2151
+ return getFilteredKeywordCompletions ( isFunctionLikeBodyCompletionKeywordText ) ;
2129
2152
default :
2130
2153
Debug . assertNever ( keywordFilter ) ;
2131
2154
}
@@ -2188,6 +2211,26 @@ namespace ts.Completions {
2188
2211
return isConstructorParameterCompletionKeyword ( stringToToken ( text ) ) ;
2189
2212
}
2190
2213
2214
+ function isFunctionLikeBodyCompletionKeyword ( kind : SyntaxKind ) {
2215
+ switch ( kind ) {
2216
+ case SyntaxKind . PublicKeyword :
2217
+ case SyntaxKind . PrivateKeyword :
2218
+ case SyntaxKind . ProtectedKeyword :
2219
+ case SyntaxKind . ReadonlyKeyword :
2220
+ case SyntaxKind . ConstructorKeyword :
2221
+ case SyntaxKind . StaticKeyword :
2222
+ case SyntaxKind . AbstractKeyword :
2223
+ case SyntaxKind . GetKeyword :
2224
+ case SyntaxKind . SetKeyword :
2225
+ return false ;
2226
+ }
2227
+ return true ;
2228
+ }
2229
+
2230
+ function isFunctionLikeBodyCompletionKeywordText ( text : string ) {
2231
+ return isFunctionLikeBodyCompletionKeyword ( stringToToken ( text ) ) ;
2232
+ }
2233
+
2191
2234
function isEqualityOperatorKind ( kind : ts . SyntaxKind ) : kind is EqualityOperator {
2192
2235
switch ( kind ) {
2193
2236
case ts . SyntaxKind . EqualsEqualsEqualsToken :
0 commit comments