@@ -28,6 +28,7 @@ import (
28
28
"github.com/microsoft/typescript-go/internal/scanner"
29
29
"github.com/microsoft/typescript-go/internal/stringutil"
30
30
"golang.org/x/text/collate"
31
+ "golang.org/x/text/language"
31
32
)
32
33
33
34
func (l * LanguageService ) ProvideCompletion (
@@ -3094,6 +3095,25 @@ func getCompletionsSymbolKind(kind ScriptElementKind) lsproto.CompletionItemKind
3094
3095
}
3095
3096
}
3096
3097
3098
+ var collatorCache collections.SyncMap [language.Tag , * sync.Pool ]
3099
+
3100
+ func getCollator (tag language.Tag ) * collate.Collator {
3101
+ pool , ok := collatorCache .Load (tag )
3102
+ if ! ok {
3103
+ pool , _ = collatorCache .LoadOrStore (tag , & sync.Pool {
3104
+ New : func () any {
3105
+ return collate .New (tag )
3106
+ },
3107
+ })
3108
+ }
3109
+ return pool .Get ().(* collate.Collator )
3110
+ }
3111
+
3112
+ func putCollator (tag language.Tag , collator * collate.Collator ) {
3113
+ pool , _ := collatorCache .Load (tag )
3114
+ pool .Put (collator )
3115
+ }
3116
+
3097
3117
// Editors will use the `sortText` and then fall back to `name` for sorting, but leave ties in response order.
3098
3118
// So, it's important that we sort those ties in the order we want them displayed if it matters. We don't
3099
3119
// strictly need to sort by name or SortText here since clients are going to do it anyway, but we have to
@@ -3103,7 +3123,10 @@ func getCompletionsSymbolKind(kind ScriptElementKind) lsproto.CompletionItemKind
3103
3123
// this made tests really weird, since most fourslash tests don't use the server.
3104
3124
func getCompareCompletionEntries (ctx context.Context ) func (entryInSlice * lsproto.CompletionItem , entryToInsert * lsproto.CompletionItem ) int {
3105
3125
return func (entryInSlice * lsproto.CompletionItem , entryToInsert * lsproto.CompletionItem ) int {
3106
- compareStrings := collate .New (core .GetLocale (ctx )).CompareString
3126
+ locale := core .GetLocale (ctx )
3127
+ collator := getCollator (locale )
3128
+ defer putCollator (locale , collator )
3129
+ compareStrings := collator .CompareString
3107
3130
result := compareStrings (* entryInSlice .SortText , * entryToInsert .SortText )
3108
3131
if result == stringutil .ComparisonEqual {
3109
3132
result = compareStrings (entryInSlice .Label , entryToInsert .Label )
0 commit comments