@@ -18,6 +18,7 @@ namespace ts.Completions {
18
18
None ,
19
19
ClassElementKeywords , // Keywords at class keyword
20
20
ConstructorParameterKeywords , // Keywords at constructor parameter
21
+ FunctionLikeBodyKeywords // Keywords at function like body
21
22
}
22
23
23
24
export function getCompletionsAtPosition (
@@ -1032,6 +1033,10 @@ namespace ts.Completions {
1032
1033
return true ;
1033
1034
}
1034
1035
1036
+ if ( tryGetFunctionLikeBodyCompletionContainer ( contextToken ) ) {
1037
+ keywordFilters = KeywordCompletionFilters . FunctionLikeBodyKeywords ;
1038
+ }
1039
+
1035
1040
if ( classLikeContainer = tryGetClassLikeCompletionContainer ( contextToken ) ) {
1036
1041
// cursor inside class declaration
1037
1042
getGetClassLikeCompletionSymbols ( classLikeContainer ) ;
@@ -1648,6 +1653,22 @@ namespace ts.Completions {
1648
1653
return undefined ;
1649
1654
}
1650
1655
1656
+ function tryGetFunctionLikeBodyCompletionContainer ( contextToken : Node ) : FunctionLikeDeclaration {
1657
+ if ( contextToken ) {
1658
+ let prev : Node ;
1659
+ const container = findAncestor ( contextToken . parent , ( node : Node ) => {
1660
+ if ( isClassLike ( node ) ) {
1661
+ return "quit" ;
1662
+ }
1663
+ if ( isFunctionLikeDeclaration ( node ) && prev === node . body ) {
1664
+ return true ;
1665
+ }
1666
+ prev = node ;
1667
+ } ) ;
1668
+ return container && container as FunctionLikeDeclaration ;
1669
+ }
1670
+ }
1671
+
1651
1672
function tryGetContainingJsxElement ( contextToken : Node ) : JsxOpeningLikeElement {
1652
1673
if ( contextToken ) {
1653
1674
const parent = contextToken . parent ;
@@ -2086,6 +2107,8 @@ namespace ts.Completions {
2086
2107
return getFilteredKeywordCompletions ( isClassMemberCompletionKeywordText ) ;
2087
2108
case KeywordCompletionFilters . ConstructorParameterKeywords :
2088
2109
return getFilteredKeywordCompletions ( isConstructorParameterCompletionKeywordText ) ;
2110
+ case KeywordCompletionFilters . FunctionLikeBodyKeywords :
2111
+ return getFilteredKeywordCompletions ( isFunctionLikeBodyCompletionKeywordText ) ;
2089
2112
default :
2090
2113
Debug . assertNever ( keywordFilter ) ;
2091
2114
}
@@ -2148,6 +2171,26 @@ namespace ts.Completions {
2148
2171
return isConstructorParameterCompletionKeyword ( stringToToken ( text ) ) ;
2149
2172
}
2150
2173
2174
+ function isFunctionLikeBodyCompletionKeyword ( kind : SyntaxKind ) {
2175
+ switch ( kind ) {
2176
+ case SyntaxKind . PublicKeyword :
2177
+ case SyntaxKind . PrivateKeyword :
2178
+ case SyntaxKind . ProtectedKeyword :
2179
+ case SyntaxKind . ReadonlyKeyword :
2180
+ case SyntaxKind . ConstructorKeyword :
2181
+ case SyntaxKind . StaticKeyword :
2182
+ case SyntaxKind . AbstractKeyword :
2183
+ case SyntaxKind . GetKeyword :
2184
+ case SyntaxKind . SetKeyword :
2185
+ return false ;
2186
+ }
2187
+ return true ;
2188
+ }
2189
+
2190
+ function isFunctionLikeBodyCompletionKeywordText ( text : string ) {
2191
+ return isFunctionLikeBodyCompletionKeyword ( stringToToken ( text ) ) ;
2192
+ }
2193
+
2151
2194
function isEqualityOperatorKind ( kind : ts . SyntaxKind ) : kind is EqualityOperator {
2152
2195
switch ( kind ) {
2153
2196
case ts . SyntaxKind . EqualsEqualsEqualsToken :
0 commit comments