@@ -20,6 +20,7 @@ namespace ts.Completions {
2020 None ,
2121 ClassElementKeywords , // Keywords at class keyword
2222 ConstructorParameterKeywords , // Keywords at constructor parameter
23+ FunctionLikeBodyKeywords // Keywords at function like body
2324 }
2425
2526 export function getCompletionsAtPosition (
@@ -1060,6 +1061,10 @@ namespace ts.Completions {
10601061 return true ;
10611062 }
10621063
1064+ if ( tryGetFunctionLikeBodyCompletionContainer ( contextToken ) ) {
1065+ keywordFilters = KeywordCompletionFilters . FunctionLikeBodyKeywords ;
1066+ }
1067+
10631068 if ( classLikeContainer = tryGetClassLikeCompletionContainer ( contextToken ) ) {
10641069 // cursor inside class declaration
10651070 getGetClassLikeCompletionSymbols ( classLikeContainer ) ;
@@ -1688,6 +1693,22 @@ namespace ts.Completions {
16881693 return undefined ;
16891694 }
16901695
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+
16911712 function tryGetContainingJsxElement ( contextToken : Node ) : JsxOpeningLikeElement {
16921713 if ( contextToken ) {
16931714 const parent = contextToken . parent ;
@@ -2126,6 +2147,8 @@ namespace ts.Completions {
21262147 return getFilteredKeywordCompletions ( isClassMemberCompletionKeywordText ) ;
21272148 case KeywordCompletionFilters . ConstructorParameterKeywords :
21282149 return getFilteredKeywordCompletions ( isConstructorParameterCompletionKeywordText ) ;
2150+ case KeywordCompletionFilters . FunctionLikeBodyKeywords :
2151+ return getFilteredKeywordCompletions ( isFunctionLikeBodyCompletionKeywordText ) ;
21292152 default :
21302153 Debug . assertNever ( keywordFilter ) ;
21312154 }
@@ -2188,6 +2211,26 @@ namespace ts.Completions {
21882211 return isConstructorParameterCompletionKeyword ( stringToToken ( text ) ) ;
21892212 }
21902213
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+
21912234 function isEqualityOperatorKind ( kind : ts . SyntaxKind ) : kind is EqualityOperator {
21922235 switch ( kind ) {
21932236 case ts . SyntaxKind . EqualsEqualsEqualsToken :
0 commit comments