@@ -23,7 +23,8 @@ namespace ts.Completions {
23
23
type SymbolOriginInfoMap = ( SymbolOriginInfo | undefined ) [ ] ;
24
24
25
25
const enum KeywordCompletionFilters {
26
- None ,
26
+ None , // No keywords
27
+ All , // Every possible keyword (TODO: This is never appropriate)
27
28
ClassElementKeywords , // Keywords inside class body
28
29
InterfaceElementKeywords , // Keywords inside interface body
29
30
ConstructorParameterKeywords , // Keywords at constructor parameter
@@ -143,21 +144,13 @@ namespace ts.Completions {
143
144
getCompletionEntriesFromSymbols ( symbols , entries , location , sourceFile , typeChecker , compilerOptions . target ! , log , completionKind , preferences , propertyAccessToConvert , isJsxInitializer , recommendedCompletion , symbolToOriginInfoMap ) ;
144
145
}
145
146
146
- // TODO add filter for keyword based on type/value/namespace and also location
147
-
148
- // Add all keywords if
149
- // - this is not a member completion list (all the keywords)
150
- // - other filters are enabled in required scenario so add those keywords
151
- const isMemberCompletion = isMemberCompletionKind ( completionKind ) ;
152
- if ( keywordFilters !== KeywordCompletionFilters . None || ! isMemberCompletion ) {
153
- addRange ( entries , getKeywordCompletions ( keywordFilters ) ) ;
154
- }
147
+ addRange ( entries , getKeywordCompletions ( keywordFilters ) ) ;
155
148
156
149
for ( const literal of literals ) {
157
150
entries . push ( createCompletionEntryForLiteral ( literal ) ) ;
158
151
}
159
152
160
- return { isGlobalCompletion : isInSnippetScope , isMemberCompletion, isNewIdentifierLocation, entries } ;
153
+ return { isGlobalCompletion : isInSnippetScope , isMemberCompletion : isMemberCompletionKind ( completionKind ) , isNewIdentifierLocation, entries } ;
161
154
}
162
155
163
156
function isUncheckedFile ( sourceFile : SourceFile , compilerOptions : CompilerOptions ) : boolean {
@@ -1014,6 +1007,7 @@ namespace ts.Completions {
1014
1007
tryGetGlobalSymbols ( ) ;
1015
1008
symbols = tagSymbols . concat ( symbols ) ;
1016
1009
completionKind = CompletionKind . MemberLike ;
1010
+ keywordFilters = KeywordCompletionFilters . None ;
1017
1011
}
1018
1012
else if ( isStartingCloseTag ) {
1019
1013
const tagName = ( < JsxElement > contextToken . parent . parent ) . openingElement . tagName ;
@@ -1022,6 +1016,7 @@ namespace ts.Completions {
1022
1016
symbols = [ tagSymbol ] ;
1023
1017
}
1024
1018
completionKind = CompletionKind . MemberLike ;
1019
+ keywordFilters = KeywordCompletionFilters . None ;
1025
1020
}
1026
1021
else {
1027
1022
// For JavaScript or TypeScript, if we're not after a dot, then just try to get the
@@ -1191,9 +1186,7 @@ namespace ts.Completions {
1191
1186
}
1192
1187
1193
1188
function getGlobalCompletions ( ) : void {
1194
- if ( tryGetFunctionLikeBodyCompletionContainer ( contextToken ) ) {
1195
- keywordFilters = KeywordCompletionFilters . FunctionLikeBodyKeywords ;
1196
- }
1189
+ keywordFilters = tryGetFunctionLikeBodyCompletionContainer ( contextToken ) ? KeywordCompletionFilters . FunctionLikeBodyKeywords : KeywordCompletionFilters . All ;
1197
1190
1198
1191
// Get all entities in the current scope.
1199
1192
completionKind = CompletionKind . Global ;
@@ -1648,7 +1641,8 @@ namespace ts.Completions {
1648
1641
completionKind = CompletionKind . MemberLike ;
1649
1642
// Declaring new property/method/accessor
1650
1643
isNewIdentifierLocation = true ;
1651
- keywordFilters = isClassLike ( decl ) ? KeywordCompletionFilters . ClassElementKeywords : KeywordCompletionFilters . InterfaceElementKeywords ;
1644
+ keywordFilters = contextToken . kind === SyntaxKind . AsteriskToken ? KeywordCompletionFilters . None :
1645
+ isClassLike ( decl ) ? KeywordCompletionFilters . ClassElementKeywords : KeywordCompletionFilters . InterfaceElementKeywords ;
1652
1646
1653
1647
// If you're in an interface you don't want to repeat things from super-interface. So just stop here.
1654
1648
if ( ! isClassLike ( decl ) ) return GlobalsSearch . Success ;
@@ -1686,14 +1680,16 @@ namespace ts.Completions {
1686
1680
*/
1687
1681
function tryGetObjectLikeCompletionContainer ( contextToken : Node ) : ObjectLiteralExpression | ObjectBindingPattern | undefined {
1688
1682
if ( contextToken ) {
1683
+ const { parent } = contextToken ;
1689
1684
switch ( contextToken . kind ) {
1690
1685
case SyntaxKind . OpenBraceToken : // const x = { |
1691
1686
case SyntaxKind . CommaToken : // const x = { a: 0, |
1692
- const parent = contextToken . parent ;
1693
1687
if ( isObjectLiteralExpression ( parent ) || isObjectBindingPattern ( parent ) ) {
1694
1688
return parent ;
1695
1689
}
1696
1690
break ;
1691
+ case SyntaxKind . AsteriskToken :
1692
+ return isMethodDeclaration ( parent ) ? tryCast ( parent . parent , isObjectLiteralExpression ) : undefined ;
1697
1693
}
1698
1694
}
1699
1695
@@ -1870,10 +1866,8 @@ namespace ts.Completions {
1870
1866
1871
1867
case SyntaxKind . GetKeyword :
1872
1868
case SyntaxKind . SetKeyword :
1873
- if ( isFromObjectTypeDeclaration ( contextToken ) ) {
1874
- return false ;
1875
- }
1876
- // falls through
1869
+ return ! isFromObjectTypeDeclaration ( contextToken ) ;
1870
+
1877
1871
case SyntaxKind . ClassKeyword :
1878
1872
case SyntaxKind . EnumKeyword :
1879
1873
case SyntaxKind . InterfaceKeyword :
@@ -1885,6 +1879,9 @@ namespace ts.Completions {
1885
1879
case SyntaxKind . YieldKeyword :
1886
1880
case SyntaxKind . TypeKeyword : // type htm|
1887
1881
return true ;
1882
+
1883
+ case SyntaxKind . AsteriskToken :
1884
+ return isFunctionLike ( contextToken . parent ) && ! isMethodDeclaration ( contextToken . parent ) ;
1888
1885
}
1889
1886
1890
1887
// If the previous token is keyword correspoding to class member completion keyword
@@ -2124,6 +2121,8 @@ namespace ts.Completions {
2124
2121
const kind = stringToToken ( entry . name ) ! ;
2125
2122
switch ( keywordFilter ) {
2126
2123
case KeywordCompletionFilters . None :
2124
+ return false ;
2125
+ case KeywordCompletionFilters . All :
2127
2126
return kind === SyntaxKind . AsyncKeyword || ! isContextualKeyword ( kind ) && ! isClassMemberCompletionKeyword ( kind ) || kind === SyntaxKind . DeclareKeyword || kind === SyntaxKind . ModuleKeyword
2128
2127
|| isTypeKeyword ( kind ) && kind !== SyntaxKind . UndefinedKeyword ;
2129
2128
case KeywordCompletionFilters . ClassElementKeywords :
@@ -2236,7 +2235,7 @@ namespace ts.Completions {
2236
2235
default :
2237
2236
if ( ! isFromObjectTypeDeclaration ( contextToken ) ) return undefined ;
2238
2237
const isValidKeyword = isClassLike ( contextToken . parent . parent ) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword ;
2239
- return ( isValidKeyword ( contextToken . kind ) || isIdentifier ( contextToken ) && isValidKeyword ( stringToToken ( contextToken . text ) ! ) ) // TODO: GH#18217
2238
+ return ( isValidKeyword ( contextToken . kind ) || contextToken . kind === SyntaxKind . AsteriskToken || isIdentifier ( contextToken ) && isValidKeyword ( stringToToken ( contextToken . text ) ! ) ) // TODO: GH#18217
2240
2239
? contextToken . parent . parent as ObjectTypeDeclaration : undefined ;
2241
2240
}
2242
2241
}
0 commit comments