@@ -18,30 +18,6 @@ namespace ts.Completions {
18
18
GlobalsOrKeywords = "15" ,
19
19
AutoImportSuggestions = "16" ,
20
20
JavascriptIdentifiers = "17" ,
21
- DeprecatedLocalDeclarationPriority = "18" ,
22
- DeprecatedLocationPriority = "19" ,
23
- DeprecatedOptionalMember = "20" ,
24
- DeprecatedMemberDeclaredBySpreadAssignment = "21" ,
25
- DeprecatedSuggestedClassMembers = "22" ,
26
- DeprecatedGlobalsOrKeywords = "23" ,
27
- DeprecatedAutoImportSuggestions = "24"
28
- }
29
-
30
- const enum SortTextId {
31
- LocalDeclarationPriority = 10 ,
32
- LocationPriority = 11 ,
33
- OptionalMember = 12 ,
34
- MemberDeclaredBySpreadAssignment = 13 ,
35
- SuggestedClassMembers = 14 ,
36
- GlobalsOrKeywords = 15 ,
37
- AutoImportSuggestions = 16 ,
38
-
39
- // Don't use these directly.
40
- _JavaScriptIdentifiers = 17 ,
41
- _DeprecatedStart = 18 ,
42
- _First = LocalDeclarationPriority ,
43
-
44
- DeprecatedOffset = _DeprecatedStart - _First ,
45
21
}
46
22
47
23
/**
@@ -157,8 +133,8 @@ namespace ts.Completions {
157
133
*/
158
134
type SymbolOriginInfoMap = Record < number , SymbolOriginInfo > ;
159
135
160
- /** Map from symbol id -> SortTextId . */
161
- type SymbolSortTextIdMap = ( SortTextId | undefined ) [ ] ;
136
+ /** Map from symbol id -> SortText . */
137
+ type SymbolSortTextIdMap = ( SortText | undefined ) [ ] ;
162
138
163
139
const enum KeywordCompletionFilters {
164
140
None , // No keywords
@@ -288,7 +264,7 @@ namespace ts.Completions {
288
264
return getLabelCompletionAtPosition ( previousToken . parent ) ;
289
265
}
290
266
291
- const completionData = getCompletionData ( program , log , sourceFile , isUncheckedFile ( sourceFile , compilerOptions ) , position , preferences , /*detailsEntryId*/ undefined , host , cancellationToken ) ;
267
+ const completionData = getCompletionData ( program , log , sourceFile , compilerOptions , position , preferences , /*detailsEntryId*/ undefined , host , cancellationToken ) ;
292
268
if ( ! completionData ) {
293
269
return undefined ;
294
270
}
@@ -791,7 +767,7 @@ namespace ts.Completions {
791
767
}
792
768
( { insertText, isSnippet, importAdder, sourceDisplay } = entry ) ;
793
769
source = CompletionSource . ObjectLiteralMethodSnippet ;
794
- sortText = SortText . OptionalMember ;
770
+ sortText = sortText + "1" as SortText ;
795
771
if ( importAdder . hasFixes ( ) ) {
796
772
hasAction = true ;
797
773
}
@@ -1396,8 +1372,8 @@ namespace ts.Completions {
1396
1372
}
1397
1373
1398
1374
const { name, needsConvertPropertyAccess } = info ;
1399
- const sortTextId = symbolToSortTextIdMap ?. [ getSymbolId ( symbol ) ] ?? SortTextId . LocationPriority ;
1400
- const sortText = ( isDeprecated ( symbol , typeChecker ) ? SortTextId . DeprecatedOffset + sortTextId : sortTextId ) . toString ( ) as SortText ;
1375
+ const originalSortText = symbolToSortTextIdMap ?. [ getSymbolId ( symbol ) ] ?? SortText . LocationPriority ;
1376
+ const sortText = ( isDeprecated ( symbol , typeChecker ) ? "z" + originalSortText : originalSortText ) as SortText ;
1401
1377
const entry = createCompletionEntry (
1402
1378
symbol ,
1403
1379
sortText ,
@@ -1465,9 +1441,9 @@ namespace ts.Completions {
1465
1441
// Auto Imports are not available for scripts so this conditional is always false
1466
1442
if ( ! ! sourceFile . externalModuleIndicator
1467
1443
&& ! compilerOptions . allowUmdGlobalAccess
1468
- && symbolToSortTextIdMap [ getSymbolId ( symbol ) ] === SortTextId . GlobalsOrKeywords
1469
- && ( symbolToSortTextIdMap [ getSymbolId ( symbolOrigin ) ] === SortTextId . AutoImportSuggestions
1470
- || symbolToSortTextIdMap [ getSymbolId ( symbolOrigin ) ] === SortTextId . LocationPriority ) ) {
1444
+ && symbolToSortTextIdMap [ getSymbolId ( symbol ) ] === SortText . GlobalsOrKeywords
1445
+ && ( symbolToSortTextIdMap [ getSymbolId ( symbolOrigin ) ] === SortText . AutoImportSuggestions
1446
+ || symbolToSortTextIdMap [ getSymbolId ( symbolOrigin ) ] === SortText . LocationPriority ) ) {
1471
1447
return false ;
1472
1448
}
1473
1449
@@ -1559,7 +1535,7 @@ namespace ts.Completions {
1559
1535
}
1560
1536
1561
1537
const compilerOptions = program . getCompilerOptions ( ) ;
1562
- const completionData = getCompletionData ( program , log , sourceFile , isUncheckedFile ( sourceFile , compilerOptions ) , position , { includeCompletionsForModuleExports : true , includeCompletionsWithInsertText : true } , entryId , host ) ;
1538
+ const completionData = getCompletionData ( program , log , sourceFile , compilerOptions , position , { includeCompletionsForModuleExports : true , includeCompletionsWithInsertText : true } , entryId , host ) ;
1563
1539
if ( ! completionData ) {
1564
1540
return { type : "none" } ;
1565
1541
}
@@ -1892,15 +1868,15 @@ namespace ts.Completions {
1892
1868
program : Program ,
1893
1869
log : ( message : string ) => void ,
1894
1870
sourceFile : SourceFile ,
1895
- isUncheckedFile : boolean ,
1871
+ compilerOptions : CompilerOptions ,
1896
1872
position : number ,
1897
1873
preferences : UserPreferences ,
1898
1874
detailsEntryId : CompletionEntryIdentifier | undefined ,
1899
1875
host : LanguageServiceHost ,
1900
1876
cancellationToken ?: CancellationToken ,
1901
1877
) : CompletionData | Request | undefined {
1902
1878
const typeChecker = program . getTypeChecker ( ) ;
1903
-
1879
+ const inUncheckedFile = isUncheckedFile ( sourceFile , compilerOptions ) ;
1904
1880
let start = timestamp ( ) ;
1905
1881
let currentToken = getTokenAtPosition ( sourceFile , position ) ; // TODO: GH#15853
1906
1882
// We will check for jsdoc comments with insideComment and getJsDocTagAtPosition. (TODO: that seems rather inefficient to check the same thing so many times.)
@@ -2350,7 +2326,7 @@ namespace ts.Completions {
2350
2326
}
2351
2327
2352
2328
const propertyAccess = node . kind === SyntaxKind . ImportType ? node as ImportTypeNode : node . parent as PropertyAccessExpression | QualifiedName ;
2353
- if ( isUncheckedFile ) {
2329
+ if ( inUncheckedFile ) {
2354
2330
// In javascript files, for union types, we don't just get the members that
2355
2331
// the individual types have in common, we also include all the members that
2356
2332
// each individual type has. This is because we're going to add all identifiers
@@ -2437,7 +2413,7 @@ namespace ts.Completions {
2437
2413
2438
2414
function addSymbolSortInfo ( symbol : Symbol ) {
2439
2415
if ( isStaticProperty ( symbol ) ) {
2440
- symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortTextId . LocalDeclarationPriority ;
2416
+ symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortText . LocalDeclarationPriority ;
2441
2417
}
2442
2418
}
2443
2419
@@ -2557,7 +2533,7 @@ namespace ts.Completions {
2557
2533
const symbol = symbols [ i ] ;
2558
2534
if ( ! typeChecker . isArgumentsSymbol ( symbol ) &&
2559
2535
! some ( symbol . declarations , d => d . getSourceFile ( ) === sourceFile ) ) {
2560
- symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortTextId . GlobalsOrKeywords ;
2536
+ symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortText . GlobalsOrKeywords ;
2561
2537
}
2562
2538
if ( typeOnlyAliasNeedsPromotion && ! ( symbol . flags & SymbolFlags . Value ) ) {
2563
2539
const typeOnlyAliasDeclaration = symbol . declarations && find ( symbol . declarations , isTypeOnlyImportOrExportDeclaration ) ;
@@ -2575,7 +2551,7 @@ namespace ts.Completions {
2575
2551
for ( const symbol of getPropertiesForCompletion ( thisType , typeChecker ) ) {
2576
2552
symbolToOriginInfoMap [ symbols . length ] = { kind : SymbolOriginInfoKind . ThisType } ;
2577
2553
symbols . push ( symbol ) ;
2578
- symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortTextId . SuggestedClassMembers ;
2554
+ symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortText . SuggestedClassMembers ;
2579
2555
}
2580
2556
}
2581
2557
}
@@ -2762,12 +2738,12 @@ namespace ts.Completions {
2762
2738
2763
2739
function pushAutoImportSymbol ( symbol : Symbol , origin : SymbolOriginInfoResolvedExport | SymbolOriginInfoExport ) {
2764
2740
const symbolId = getSymbolId ( symbol ) ;
2765
- if ( symbolToSortTextIdMap [ symbolId ] === SortTextId . GlobalsOrKeywords ) {
2741
+ if ( symbolToSortTextIdMap [ symbolId ] === SortText . GlobalsOrKeywords ) {
2766
2742
// If an auto-importable symbol is available as a global, don't add the auto import
2767
2743
return ;
2768
2744
}
2769
2745
symbolToOriginInfoMap [ symbols . length ] = origin ;
2770
- symbolToSortTextIdMap [ symbolId ] = importCompletionNode ? SortTextId . LocationPriority : SortTextId . AutoImportSuggestions ;
2746
+ symbolToSortTextIdMap [ symbolId ] = importCompletionNode ? SortText . LocationPriority : SortText . AutoImportSuggestions ;
2771
2747
symbols . push ( symbol ) ;
2772
2748
}
2773
2749
@@ -3050,6 +3026,10 @@ namespace ts.Completions {
3050
3026
}
3051
3027
}
3052
3028
setSortTextToOptionalMember ( ) ;
3029
+ if ( objectLikeContainer . kind === SyntaxKind . ObjectLiteralExpression && preferences . includeCompletionsWithInsertText ) {
3030
+ // >> TODO: specify `symbols` range?
3031
+ transformObjectLiteralMembersSortText ( ) ;
3032
+ }
3053
3033
3054
3034
return GlobalsSearch . Success ;
3055
3035
}
@@ -3131,7 +3111,7 @@ namespace ts.Completions {
3131
3111
localsContainer . locals ?. forEach ( ( symbol , name ) => {
3132
3112
symbols . push ( symbol ) ;
3133
3113
if ( localsContainer . symbol ?. exports ?. has ( name ) ) {
3134
- symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortTextId . OptionalMember ;
3114
+ symbolToSortTextIdMap [ getSymbolId ( symbol ) ] = SortText . OptionalMember ;
3135
3115
}
3136
3116
} ) ;
3137
3117
return GlobalsSearch . Success ;
@@ -3571,7 +3551,7 @@ namespace ts.Completions {
3571
3551
symbols . forEach ( m => {
3572
3552
if ( m . flags & SymbolFlags . Optional ) {
3573
3553
const symbolId = getSymbolId ( m ) ;
3574
- symbolToSortTextIdMap [ symbolId ] = symbolToSortTextIdMap [ symbolId ] ?? SortTextId . OptionalMember ;
3554
+ symbolToSortTextIdMap [ symbolId ] = symbolToSortTextIdMap [ symbolId ] ?? SortText . OptionalMember ;
3575
3555
}
3576
3556
} ) ;
3577
3557
}
@@ -3583,7 +3563,32 @@ namespace ts.Completions {
3583
3563
}
3584
3564
for ( const contextualMemberSymbol of contextualMemberSymbols ) {
3585
3565
if ( membersDeclaredBySpreadAssignment . has ( contextualMemberSymbol . name ) ) {
3586
- symbolToSortTextIdMap [ getSymbolId ( contextualMemberSymbol ) ] = SortTextId . MemberDeclaredBySpreadAssignment ;
3566
+ symbolToSortTextIdMap [ getSymbolId ( contextualMemberSymbol ) ] = SortText . MemberDeclaredBySpreadAssignment ;
3567
+ }
3568
+ }
3569
+ }
3570
+
3571
+ function transformObjectLiteralMembersSortText ( ) : void {
3572
+ const pastSymbolIds : Set < number > = new Set ( ) ;
3573
+ for ( let i = 0 ; i < symbols . length ; i ++ ) {
3574
+ const symbol = symbols [ i ] ;
3575
+ const symbolId = getSymbolId ( symbol ) ;
3576
+ if ( pastSymbolIds . has ( symbolId ) ) {
3577
+ continue ;
3578
+ }
3579
+ pastSymbolIds . add ( symbolId ) ;
3580
+ const origin = symbolToOriginInfoMap ?. [ i ] ;
3581
+ const target = getEmitScriptTarget ( compilerOptions ) ;
3582
+ const displayName = getCompletionEntryDisplayNameForSymbol (
3583
+ symbol ,
3584
+ target ,
3585
+ origin ,
3586
+ CompletionKind . ObjectPropertyDeclaration ,
3587
+ /*jsxIdentifierExpected*/ false ) ;
3588
+ if ( displayName ) {
3589
+ const originalSortText = symbolToSortTextIdMap [ symbolId ] ?? SortText . LocationPriority ;
3590
+ const { name } = displayName ;
3591
+ symbolToSortTextIdMap [ symbolId ] = `${ originalSortText } \0${ name } \0` as SortText ;
3587
3592
}
3588
3593
}
3589
3594
}
0 commit comments