2
2
namespace ts . Completions {
3
3
export enum SortText {
4
4
LocationPriority = "0" ,
5
- SuggestedClassMembers = "1" ,
6
- GlobalsOrKeywords = "2" ,
7
- AutoImportSuggestions = "3" ,
8
- JavascriptIdentifiers = "4"
5
+ LocationPriorityOptional = "1" ,
6
+ LocationPriorityFulfilled = "2" ,
7
+ SuggestedClassMembers = "3" ,
8
+ GlobalsOrKeywords = "4" ,
9
+ AutoImportSuggestions = "5" ,
10
+ JavascriptIdentifiers = "6"
9
11
}
10
12
export type Log = ( message : string ) => void ;
11
13
@@ -103,6 +105,7 @@ namespace ts.Completions {
103
105
isJsxInitializer,
104
106
insideJsDocTagTypeExpression,
105
107
symbolToSortTextMap,
108
+ fulfilledSymbols,
106
109
} = completionData ;
107
110
108
111
if ( location && location . parent && isJsxClosingElement ( location . parent ) ) {
@@ -163,7 +166,8 @@ namespace ts.Completions {
163
166
isJsxInitializer ,
164
167
recommendedCompletion ,
165
168
symbolToOriginInfoMap ,
166
- symbolToSortTextMap
169
+ symbolToSortTextMap ,
170
+ fulfilledSymbols
167
171
) ;
168
172
}
169
173
@@ -240,6 +244,7 @@ namespace ts.Completions {
240
244
propertyAccessToConvert : PropertyAccessExpression | undefined ,
241
245
isJsxInitializer : IsJsxInitializer | undefined ,
242
246
preferences : UserPreferences ,
247
+ isFulfilled : boolean
243
248
) : CompletionEntry | undefined {
244
249
let insertText : string | undefined ;
245
250
let replacementSpan : TextSpan | undefined ;
@@ -286,6 +291,7 @@ namespace ts.Completions {
286
291
isRecommended : trueOrUndefined ( isRecommendedCompletionMatch ( symbol , recommendedCompletion , typeChecker ) ) ,
287
292
insertText,
288
293
replacementSpan,
294
+ isFulfilled
289
295
} ;
290
296
}
291
297
@@ -317,6 +323,7 @@ namespace ts.Completions {
317
323
recommendedCompletion ?: Symbol ,
318
324
symbolToOriginInfoMap ?: SymbolOriginInfoMap ,
319
325
symbolToSortTextMap ?: SymbolSortTextMap ,
326
+ fulfilledSymbols ?: ReadonlyArray < Symbol > ,
320
327
) : Map < true > {
321
328
const start = timestamp ( ) ;
322
329
// Tracks unique names.
@@ -335,9 +342,23 @@ namespace ts.Completions {
335
342
continue ;
336
343
}
337
344
345
+ let sortText = symbolToSortTextMap && symbolToSortTextMap [ getSymbolId ( symbol ) ] ;
346
+ let isFulfilled = false ;
347
+ if ( ! sortText ) {
348
+ fulfilledSymbols && fulfilledSymbols . forEach ( fulfilledSymbol => {
349
+ if ( fulfilledSymbol . name === symbol . name ) {
350
+ sortText = SortText . LocationPriorityFulfilled ;
351
+ isFulfilled = true ;
352
+ }
353
+ } ) ;
354
+ }
355
+ if ( ! sortText ) {
356
+ sortText = SymbolDisplay . getSymbolModifiers ( symbol ) === 'optional' ? SortText . LocationPriorityOptional : SortText . LocationPriority ;
357
+ }
358
+
338
359
const entry = createCompletionEntry (
339
360
symbol ,
340
- symbolToSortTextMap && symbolToSortTextMap [ getSymbolId ( symbol ) ] || SortText . LocationPriority ,
361
+ sortText ,
341
362
location ,
342
363
sourceFile ,
343
364
typeChecker ,
@@ -347,7 +368,8 @@ namespace ts.Completions {
347
368
recommendedCompletion ,
348
369
propertyAccessToConvert ,
349
370
isJsxInitializer ,
350
- preferences
371
+ preferences ,
372
+ isFulfilled
351
373
) ;
352
374
if ( ! entry ) {
353
375
continue ;
@@ -581,6 +603,7 @@ namespace ts.Completions {
581
603
readonly isJsxInitializer : IsJsxInitializer ;
582
604
readonly insideJsDocTagTypeExpression : boolean ;
583
605
readonly symbolToSortTextMap : SymbolSortTextMap ;
606
+ readonly fulfilledSymbols ?: ReadonlyArray < Symbol > ;
584
607
}
585
608
type Request = { readonly kind : CompletionDataKind . JsDocTagName | CompletionDataKind . JsDocTag } | { readonly kind : CompletionDataKind . JsDocParameterName , tag : JSDocParameterTag } ;
586
609
@@ -872,6 +895,7 @@ namespace ts.Completions {
872
895
let isNewIdentifierLocation = false ;
873
896
let keywordFilters = KeywordCompletionFilters . None ;
874
897
let symbols : Symbol [ ] = [ ] ;
898
+ let fulfilledSymbols : Symbol [ ] | undefined = [ ] ;
875
899
const symbolToOriginInfoMap : SymbolOriginInfoMap = [ ] ;
876
900
const symbolToSortTextMap : SymbolSortTextMap = [ ] ;
877
901
@@ -924,7 +948,8 @@ namespace ts.Completions {
924
948
previousToken,
925
949
isJsxInitializer,
926
950
insideJsDocTagTypeExpression,
927
- symbolToSortTextMap
951
+ symbolToSortTextMap,
952
+ fulfilledSymbols
928
953
} ;
929
954
930
955
type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag ;
@@ -1494,6 +1519,14 @@ namespace ts.Completions {
1494
1519
if ( typeMembers && typeMembers . length > 0 ) {
1495
1520
// Add filtered items to the completion list
1496
1521
symbols = filterObjectMembersList ( typeMembers , Debug . assertDefined ( existingMembers ) ) ;
1522
+ existingMembers && existingMembers . forEach ( member => {
1523
+ if ( member . kind === SyntaxKind . SpreadAssignment ) {
1524
+ const expression = ( < SpreadAssignment > member ) . expression ;
1525
+ const symbol = typeChecker . getSymbolAtLocation ( expression ) ;
1526
+ const type = symbol && typeChecker . getTypeOfSymbolAtLocation ( symbol , expression ) ;
1527
+ fulfilledSymbols = type && ( < ObjectType > type ) . properties ;
1528
+ }
1529
+ } ) ;
1497
1530
}
1498
1531
return GlobalsSearch . Success ;
1499
1532
}
0 commit comments