@@ -106,7 +106,7 @@ namespace ts.Completions {
106
106
}
107
107
108
108
function completionInfoFromData ( sourceFile : SourceFile , typeChecker : TypeChecker , compilerOptions : CompilerOptions , log : Log , completionData : CompletionData , includeInsertTextCompletions : boolean ) : CompletionInfo {
109
- const { symbols, completionKind, isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, isJsxInitializer } = completionData ;
109
+ const { symbols, completionKind, isInSnippetScope , isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, isJsxInitializer } = completionData ;
110
110
111
111
if ( sourceFile . languageVariant === LanguageVariant . JSX && location && location . parent && isJsxClosingElement ( location . parent ) ) {
112
112
// In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag,
@@ -148,7 +148,7 @@ namespace ts.Completions {
148
148
addRange ( entries , getKeywordCompletions ( keywordFilters ) ) ;
149
149
}
150
150
151
- return { isGlobalCompletion : completionKind === CompletionKind . Global , isMemberCompletion, isNewIdentifierLocation, entries } ;
151
+ return { isGlobalCompletion : isInSnippetScope , isMemberCompletion, isNewIdentifierLocation, entries } ;
152
152
}
153
153
154
154
function isMemberCompletionKind ( kind : CompletionKind ) : boolean {
@@ -635,6 +635,7 @@ namespace ts.Completions {
635
635
readonly kind : CompletionDataKind . Data ;
636
636
readonly symbols : ReadonlyArray < Symbol > ;
637
637
readonly completionKind : CompletionKind ;
638
+ readonly isInSnippetScope : boolean ;
638
639
/** Note that the presence of this alone doesn't mean that we need a conversion. Only do that if the completion is not an ordinary identifier. */
639
640
readonly propertyAccessToConvert : PropertyAccessExpression | undefined ;
640
641
readonly isNewIdentifierLocation : boolean ;
@@ -649,7 +650,6 @@ namespace ts.Completions {
649
650
650
651
const enum CompletionKind {
651
652
ObjectPropertyDeclaration ,
652
- /** Note that sometimes we access completions from global scope, but use "None" instead of this. See isGlobalCompletionScope. */
653
653
Global ,
654
654
PropertyAccess ,
655
655
MemberLike ,
@@ -753,6 +753,7 @@ namespace ts.Completions {
753
753
log ( "getCompletionData: Is inside comment: " + ( timestamp ( ) - start ) ) ;
754
754
755
755
let insideJsDocTagTypeExpression = false ;
756
+ let isInSnippetScope = false ;
756
757
if ( insideComment ) {
757
758
if ( hasDocComment ( sourceFile , position ) ) {
758
759
if ( sourceFile . text . charCodeAt ( position - 1 ) === CharacterCodes . at ) {
@@ -971,7 +972,7 @@ namespace ts.Completions {
971
972
log ( "getCompletionData: Semantic work: " + ( timestamp ( ) - semanticStart ) ) ;
972
973
973
974
const recommendedCompletion = previousToken && getRecommendedCompletion ( previousToken , position , sourceFile , typeChecker ) ;
974
- return { kind : CompletionDataKind . Data , symbols, completionKind, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken, isJsxInitializer } ;
975
+ return { kind : CompletionDataKind . Data , symbols, completionKind, isInSnippetScope , propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken, isJsxInitializer } ;
975
976
976
977
type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag ;
977
978
@@ -1098,7 +1099,7 @@ namespace ts.Completions {
1098
1099
}
1099
1100
1100
1101
// Get all entities in the current scope.
1101
- completionKind = CompletionKind . None ;
1102
+ completionKind = CompletionKind . Global ;
1102
1103
isNewIdentifierLocation = isNewIdentifierDefinitionLocation ( contextToken ) ;
1103
1104
1104
1105
if ( previousToken !== contextToken ) {
@@ -1134,9 +1135,7 @@ namespace ts.Completions {
1134
1135
position ;
1135
1136
1136
1137
const scopeNode = getScopeNode ( contextToken , adjustedPosition , sourceFile ) || sourceFile ;
1137
- if ( isGlobalCompletionScope ( scopeNode ) ) {
1138
- completionKind = CompletionKind . Global ;
1139
- }
1138
+ isInSnippetScope = isSnippetScope ( scopeNode ) ;
1140
1139
1141
1140
const symbolMeanings = SymbolFlags . Type | SymbolFlags . Value | SymbolFlags . Namespace | SymbolFlags . Alias ;
1142
1141
@@ -1161,7 +1160,7 @@ namespace ts.Completions {
1161
1160
return true ;
1162
1161
}
1163
1162
1164
- function isGlobalCompletionScope ( scopeNode : Node ) : boolean {
1163
+ function isSnippetScope ( scopeNode : Node ) : boolean {
1165
1164
switch ( scopeNode . kind ) {
1166
1165
case SyntaxKind . SourceFile :
1167
1166
case SyntaxKind . TemplateExpression :
@@ -2128,10 +2127,10 @@ namespace ts.Completions {
2128
2127
// TODO: GH#18169
2129
2128
return { name : JSON . stringify ( name ) , needsConvertPropertyAccess : false } ;
2130
2129
case CompletionKind . PropertyAccess :
2131
- case CompletionKind . None :
2132
2130
case CompletionKind . Global :
2133
2131
// Don't add a completion for a name starting with a space. See https://github.com/Microsoft/TypeScript/pull/20547
2134
2132
return name . charCodeAt ( 0 ) === CharacterCodes . space ? undefined : { name, needsConvertPropertyAccess : true } ;
2133
+ case CompletionKind . None :
2135
2134
case CompletionKind . String :
2136
2135
return validIdentiferResult ;
2137
2136
default :
0 commit comments