@@ -30,6 +30,7 @@ namespace ts.Completions {
30
30
ConstructorParameterKeywords , // Keywords at constructor parameter
31
31
FunctionLikeBodyKeywords , // Keywords at function like body
32
32
TypeKeywords ,
33
+ Last = TypeKeywords
33
34
}
34
35
35
36
const enum GlobalsSearch { Continue , Success , Fail }
@@ -77,7 +78,7 @@ namespace ts.Completions {
77
78
}
78
79
79
80
function completionInfoFromData ( sourceFile : SourceFile , typeChecker : TypeChecker , compilerOptions : CompilerOptions , log : Log , completionData : CompletionData , preferences : UserPreferences ) : CompletionInfo | undefined {
80
- const { symbols, completionKind, isInSnippetScope, isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, literals, symbolToOriginInfoMap, recommendedCompletion, isJsxInitializer } = completionData ;
81
+ const { symbols, completionKind, isInSnippetScope, isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, literals, symbolToOriginInfoMap, recommendedCompletion, isJsxInitializer, insideJsDocTagTypeExpression } = completionData ;
81
82
82
83
if ( location && location . parent && isJsxClosingElement ( location . parent ) ) {
83
84
// In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag,
@@ -113,7 +114,7 @@ namespace ts.Completions {
113
114
114
115
if ( keywordFilters !== KeywordCompletionFilters . None ) {
115
116
const entryNames = arrayToSet ( entries , e => e . name ) ;
116
- for ( const keywordEntry of getKeywordCompletions ( keywordFilters ) ) {
117
+ for ( const keywordEntry of getKeywordCompletions ( keywordFilters , ! insideJsDocTagTypeExpression && isSourceFileJS ( sourceFile ) ) ) {
117
118
if ( ! entryNames . has ( keywordEntry . name ) ) {
118
119
entries . push ( keywordEntry ) ;
119
120
}
@@ -510,6 +511,7 @@ namespace ts.Completions {
510
511
readonly recommendedCompletion : Symbol | undefined ;
511
512
readonly previousToken : Node | undefined ;
512
513
readonly isJsxInitializer : IsJsxInitializer ;
514
+ readonly insideJsDocTagTypeExpression : boolean ;
513
515
}
514
516
type Request = { readonly kind : CompletionDataKind . JsDocTagName | CompletionDataKind . JsDocTag } | { readonly kind : CompletionDataKind . JsDocParameterName , tag : JSDocParameterTag } ;
515
517
@@ -837,7 +839,22 @@ namespace ts.Completions {
837
839
const literals = mapDefined ( contextualType && ( contextualType . isUnion ( ) ? contextualType . types : [ contextualType ] ) , t => t . isLiteral ( ) ? t . value : undefined ) ;
838
840
839
841
const recommendedCompletion = previousToken && contextualType && getRecommendedCompletion ( previousToken , contextualType , typeChecker ) ;
840
- return { kind : CompletionDataKind . Data , symbols, completionKind, isInSnippetScope, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, literals, symbolToOriginInfoMap, recommendedCompletion, previousToken, isJsxInitializer } ;
842
+ return {
843
+ kind : CompletionDataKind . Data ,
844
+ symbols,
845
+ completionKind,
846
+ isInSnippetScope,
847
+ propertyAccessToConvert,
848
+ isNewIdentifierLocation,
849
+ location,
850
+ keywordFilters,
851
+ literals,
852
+ symbolToOriginInfoMap,
853
+ recommendedCompletion,
854
+ previousToken,
855
+ isJsxInitializer,
856
+ insideJsDocTagTypeExpression
857
+ } ;
841
858
842
859
type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag ;
843
860
@@ -1929,7 +1946,18 @@ namespace ts.Completions {
1929
1946
}
1930
1947
return res ;
1931
1948
} ) ;
1932
- function getKeywordCompletions ( keywordFilter : KeywordCompletionFilters ) : ReadonlyArray < CompletionEntry > {
1949
+
1950
+ function getKeywordCompletions ( keywordFilter : KeywordCompletionFilters , filterOutTsOnlyKeywords : boolean ) : ReadonlyArray < CompletionEntry > {
1951
+ if ( ! filterOutTsOnlyKeywords ) return getTypescriptKeywordCompletions ( keywordFilter ) ;
1952
+
1953
+ const index = keywordFilter + KeywordCompletionFilters . Last + 1 ;
1954
+ return _keywordCompletions [ index ] ||
1955
+ ( _keywordCompletions [ index ] = getTypescriptKeywordCompletions ( keywordFilter )
1956
+ . filter ( entry => ! isTypeScriptOnlyKeyword ( stringToToken ( entry . name ) ! ) )
1957
+ ) ;
1958
+ }
1959
+
1960
+ function getTypescriptKeywordCompletions ( keywordFilter : KeywordCompletionFilters ) : ReadonlyArray < CompletionEntry > {
1933
1961
return _keywordCompletions [ keywordFilter ] || ( _keywordCompletions [ keywordFilter ] = allKeywordsCompletions ( ) . filter ( entry => {
1934
1962
const kind = stringToToken ( entry . name ) ! ;
1935
1963
switch ( keywordFilter ) {
@@ -1954,6 +1982,40 @@ namespace ts.Completions {
1954
1982
} ) ) ;
1955
1983
}
1956
1984
1985
+ function isTypeScriptOnlyKeyword ( kind : SyntaxKind ) {
1986
+ switch ( kind ) {
1987
+ case SyntaxKind . AbstractKeyword :
1988
+ case SyntaxKind . AnyKeyword :
1989
+ case SyntaxKind . BigIntKeyword :
1990
+ case SyntaxKind . BooleanKeyword :
1991
+ case SyntaxKind . DeclareKeyword :
1992
+ case SyntaxKind . EnumKeyword :
1993
+ case SyntaxKind . GlobalKeyword :
1994
+ case SyntaxKind . ImplementsKeyword :
1995
+ case SyntaxKind . InferKeyword :
1996
+ case SyntaxKind . InterfaceKeyword :
1997
+ case SyntaxKind . IsKeyword :
1998
+ case SyntaxKind . KeyOfKeyword :
1999
+ case SyntaxKind . ModuleKeyword :
2000
+ case SyntaxKind . NamespaceKeyword :
2001
+ case SyntaxKind . NeverKeyword :
2002
+ case SyntaxKind . NumberKeyword :
2003
+ case SyntaxKind . ObjectKeyword :
2004
+ case SyntaxKind . PrivateKeyword :
2005
+ case SyntaxKind . ProtectedKeyword :
2006
+ case SyntaxKind . PublicKeyword :
2007
+ case SyntaxKind . ReadonlyKeyword :
2008
+ case SyntaxKind . StringKeyword :
2009
+ case SyntaxKind . SymbolKeyword :
2010
+ case SyntaxKind . TypeKeyword :
2011
+ case SyntaxKind . UniqueKeyword :
2012
+ case SyntaxKind . UnknownKeyword :
2013
+ return true ;
2014
+ default :
2015
+ return false ;
2016
+ }
2017
+ }
2018
+
1957
2019
function isInterfaceOrTypeLiteralCompletionKeyword ( kind : SyntaxKind ) : boolean {
1958
2020
return kind === SyntaxKind . ReadonlyKeyword ;
1959
2021
}
0 commit comments