@@ -29,8 +29,6 @@ import (
29
29
"github.com/microsoft/typescript-go/internal/scanner"
30
30
"github.com/microsoft/typescript-go/internal/stringutil"
31
31
"github.com/microsoft/typescript-go/internal/tspath"
32
- "golang.org/x/text/collate"
33
- "golang.org/x/text/language"
34
32
)
35
33
36
34
func (l * LanguageService ) ProvideCompletion (
@@ -1884,7 +1882,6 @@ func (l *LanguageService) completionInfoFromData(
1884
1882
clientOptions ,
1885
1883
)
1886
1884
1887
- compareCompletionEntries := getCompareCompletionEntries (ctx )
1888
1885
if data .keywordFilters != KeywordCompletionFiltersNone {
1889
1886
keywordCompletions := getKeywordCompletions (data .keywordFilters , ! data .insideJSDocTagTypeExpression && ast .IsSourceFileJS (file ))
1890
1887
for _ , keywordEntry := range keywordCompletions {
@@ -1958,7 +1955,6 @@ func (l *LanguageService) getCompletionEntriesFromSymbols(
1958
1955
// true otherwise. Based on the order we add things we will always see locals first, then globals, then module exports.
1959
1956
// So adding a completion for a local will prevent us from adding completions for external module exports sharing the same name.
1960
1957
uniques := make (uniqueNamesMap )
1961
- compareCompletionEntries := getCompareCompletionEntries (ctx )
1962
1958
for _ , symbol := range data .symbols {
1963
1959
symbolId := ast .GetSymbolId (symbol )
1964
1960
origin := data .symbolToOriginInfoMap [symbolId ]
@@ -3295,59 +3291,35 @@ func getCompletionsSymbolKind(kind ScriptElementKind) lsproto.CompletionItemKind
3295
3291
}
3296
3292
}
3297
3293
3298
- var collatorCache collections.SyncMap [language.Tag , * sync.Pool ]
3299
-
3300
- func getCollator (tag language.Tag ) * collate.Collator {
3301
- pool , ok := collatorCache .Load (tag )
3302
- if ! ok {
3303
- pool , _ = collatorCache .LoadOrStore (tag , & sync.Pool {
3304
- New : func () any {
3305
- return collate .New (tag )
3306
- },
3307
- })
3308
- }
3309
- return pool .Get ().(* collate.Collator )
3310
- }
3311
-
3312
- func putCollator (tag language.Tag , collator * collate.Collator ) {
3313
- pool , _ := collatorCache .Load (tag )
3314
- pool .Put (collator )
3315
- }
3316
-
3317
3294
// Editors will use the `sortText` and then fall back to `name` for sorting, but leave ties in response order.
3318
3295
// So, it's important that we sort those ties in the order we want them displayed if it matters. We don't
3319
3296
// strictly need to sort by name or SortText here since clients are going to do it anyway, but we have to
3320
3297
// do the work of comparing them so we can sort those ties appropriately; plus, it makes the order returned
3321
3298
// by the language service consistent with what TS Server does and what editors typically do. This also makes
3322
3299
// completions tests make more sense. We used to sort only alphabetically and only in the server layer, but
3323
3300
// this made tests really weird, since most fourslash tests don't use the server.
3324
- func getCompareCompletionEntries (ctx context.Context ) func (entryInSlice * lsproto.CompletionItem , entryToInsert * lsproto.CompletionItem ) int {
3325
- return func (entryInSlice * lsproto.CompletionItem , entryToInsert * lsproto.CompletionItem ) int {
3326
- locale := core .GetLocale (ctx )
3327
- collator := getCollator (locale )
3328
- defer putCollator (locale , collator )
3329
- compareStrings := collator .CompareString
3330
- result := compareStrings (* entryInSlice .SortText , * entryToInsert .SortText )
3331
- if result == stringutil .ComparisonEqual {
3332
- result = compareStrings (entryInSlice .Label , entryToInsert .Label )
3333
- }
3334
- if result == stringutil .ComparisonEqual && entryInSlice .Data != nil && entryToInsert .Data != nil {
3335
- sliceEntryData , ok1 := (* entryInSlice .Data ).(* completionEntryData )
3336
- insertEntryData , ok2 := (* entryToInsert .Data ).(* completionEntryData )
3337
- if ok1 && ok2 && sliceEntryData .ModuleSpecifier != "" && insertEntryData .ModuleSpecifier != "" {
3338
- // Sort same-named auto-imports by module specifier
3339
- result = compareNumberOfDirectorySeparators (
3340
- sliceEntryData .ModuleSpecifier ,
3341
- insertEntryData .ModuleSpecifier ,
3342
- )
3343
- }
3344
- }
3345
- if result == stringutil .ComparisonEqual {
3346
- // Fall back to symbol order - if we return `EqualTo`, `insertSorted` will put later symbols first.
3347
- return stringutil .ComparisonLessThan
3301
+ func compareCompletionEntries (entryInSlice * lsproto.CompletionItem , entryToInsert * lsproto.CompletionItem ) int {
3302
+ compareStrings := stringutil .CompareStringsCaseInsensitiveThenSensitive
3303
+ result := compareStrings (* entryInSlice .SortText , * entryToInsert .SortText )
3304
+ if result == stringutil .ComparisonEqual {
3305
+ result = compareStrings (entryInSlice .Label , entryToInsert .Label )
3306
+ }
3307
+ if result == stringutil .ComparisonEqual && entryInSlice .Data != nil && entryToInsert .Data != nil {
3308
+ sliceEntryData , ok1 := (* entryInSlice .Data ).(* completionEntryData )
3309
+ insertEntryData , ok2 := (* entryToInsert .Data ).(* completionEntryData )
3310
+ if ok1 && ok2 && sliceEntryData .ModuleSpecifier != "" && insertEntryData .ModuleSpecifier != "" {
3311
+ // Sort same-named auto-imports by module specifier
3312
+ result = compareNumberOfDirectorySeparators (
3313
+ sliceEntryData .ModuleSpecifier ,
3314
+ insertEntryData .ModuleSpecifier ,
3315
+ )
3348
3316
}
3349
- return result
3350
3317
}
3318
+ if result == stringutil .ComparisonEqual {
3319
+ // Fall back to symbol order - if we return `EqualTo`, `insertSorted` will put later symbols first.
3320
+ return stringutil .ComparisonLessThan
3321
+ }
3322
+ return result
3351
3323
}
3352
3324
3353
3325
// True if the first character of `lowercaseCharacters` is the first character
@@ -3582,7 +3554,6 @@ func (l *LanguageService) getJSCompletionEntries(
3582
3554
uniqueNames * collections.Set [string ],
3583
3555
sortedEntries []* lsproto.CompletionItem ,
3584
3556
) []* lsproto.CompletionItem {
3585
- compareCompletionEntries := getCompareCompletionEntries (ctx )
3586
3557
nameTable := getNameTable (file )
3587
3558
for name , pos := range nameTable {
3588
3559
// Skip identifiers produced only from the current location
@@ -4929,11 +4900,6 @@ func hasCompletionItem(clientOptions *lsproto.CompletionClientCapabilities) bool
4929
4900
return clientOptions != nil && clientOptions .CompletionItem != nil
4930
4901
}
4931
4902
4932
- // strada TODO: this function is, at best, poorly named. Use sites are pretty suspicious.
4933
- func compilerOptionsIndicateEsModules (options * core.CompilerOptions ) bool {
4934
- return options .Module == core .ModuleKindNone || options .GetEmitScriptTarget () >= core .ScriptTargetES2015 || options .NoEmit .IsTrue ()
4935
- }
4936
-
4937
4903
func clientSupportsItemLabelDetails (clientOptions * lsproto.CompletionClientCapabilities ) bool {
4938
4904
return hasCompletionItem (clientOptions ) && ptrIsTrue (clientOptions .CompletionItem .LabelDetailsSupport )
4939
4905
}
0 commit comments