Skip to content

Commit 62a8b89

Browse files
authored
Add locale-sensitive sorting + completion fixes (#1456)
1 parent 008942f commit 62a8b89

37 files changed

+146
-92
lines changed

NOTICE.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,37 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
295295
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
296296

297297
---------------------------------------------------------
298+
299+
---------------------------------------------------------
300+
301+
golang.org/x/text v0.27.0 - BSD-3-Clause
302+
303+
Copyright 2009 The Go Authors.
304+
305+
Redistribution and use in source and binary forms, with or without
306+
modification, are permitted provided that the following conditions are
307+
met:
308+
309+
* Redistributions of source code must retain the above copyright
310+
notice, this list of conditions and the following disclaimer.
311+
* Redistributions in binary form must reproduce the above
312+
copyright notice, this list of conditions and the following disclaimer
313+
in the documentation and/or other materials provided with the
314+
distribution.
315+
* Neither the name of Google LLC nor the names of its
316+
contributors may be used to endorse or promote products derived from
317+
this software without specific prior written permission.
318+
319+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
320+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
321+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
323+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
324+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
325+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
327+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
328+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
329+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330+
331+
---------------------------------------------------------

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ require (
99
github.com/peter-evans/patience v0.3.0
1010
golang.org/x/sync v0.16.0
1111
golang.org/x/sys v0.34.0
12+
golang.org/x/text v0.27.0
1213
gotest.tools/v3 v3.5.2
1314
)
1415

1516
require (
1617
github.com/matryer/moq v0.5.3 // indirect
17-
golang.org/x/mod v0.24.0 // indirect
18-
golang.org/x/tools v0.32.0 // indirect
18+
golang.org/x/mod v0.25.0 // indirect
19+
golang.org/x/tools v0.34.0 // indirect
1920
mvdan.cc/gofumpt v0.8.0 // indirect
2021
)
2122

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
1818
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1919
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
2020
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
21-
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
22-
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
21+
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
22+
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
2323
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
2424
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
2525
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
2626
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
27-
golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU=
28-
golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s=
27+
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
28+
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
29+
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
30+
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
2931
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
3032
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
3133
mvdan.cc/gofumpt v0.8.0 h1:nZUCeC2ViFaerTcYKstMmfysj6uhQrA2vJe+2vwGU6k=

internal/astnav/tokens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func getTokenAtPosition(
5353
prevSubtree = node
5454
}
5555

56-
if node.End() <= position {
56+
if node.End() < position || node.Kind != ast.KindEndOfFile && node.End() == position {
5757
return -1
5858
}
5959
if getPosition(node, sourceFile, allowPositionInLeadingTrivia) > position {

internal/core/context.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package core
22

3-
import "context"
3+
import (
4+
"context"
5+
6+
"golang.org/x/text/language"
7+
)
48

59
type key int
610

7-
var requestIDKey key
11+
const (
12+
requestIDKey key = iota
13+
localeKey
14+
)
815

916
func WithRequestID(ctx context.Context, id string) context.Context {
1017
return context.WithValue(ctx, requestIDKey, id)
@@ -16,3 +23,14 @@ func GetRequestID(ctx context.Context) string {
1623
}
1724
return ""
1825
}
26+
27+
func WithLocale(ctx context.Context, locale language.Tag) context.Context {
28+
return context.WithValue(ctx, localeKey, locale)
29+
}
30+
31+
func GetLocale(ctx context.Context) language.Tag {
32+
if locale, ok := ctx.Value(localeKey).(language.Tag); ok {
33+
return locale
34+
}
35+
return language.Und
36+
}

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
TestAugmentedTypesClass1
2-
TestClosedCommentsInConstructor
32
TestCodeCompletionEscaping
43
TestCompletionAfterQuestionDot
54
TestCompletionAutoInsertQuestionDot
@@ -66,21 +65,13 @@ TestCompletionInNamedImportLocation
6665
TestCompletionInUncheckedJSFile
6766
TestCompletionInfoWithExplicitTypeArguments
6867
TestCompletionJSDocNamePath
69-
TestCompletionListAndMemberListOnCommentedDot
70-
TestCompletionListAndMemberListOnCommentedWhiteSpace
7168
TestCompletionListBuilderLocations_VariableDeclarations
72-
TestCompletionListClassMembers
7369
TestCompletionListForDerivedType1
74-
TestCompletionListForExportEquals
75-
TestCompletionListForTransitivelyExportedMembers01
7670
TestCompletionListForTransitivelyExportedMembers04
7771
TestCompletionListFunctionExpression
78-
TestCompletionListFunctionMembers
7972
TestCompletionListInArrowFunctionInUnclosedCallSite01
8073
TestCompletionListInClassExpressionWithTypeParameter
8174
TestCompletionListInClassStaticBlocks
82-
TestCompletionListInComments
83-
TestCompletionListInExtendsClause
8475
TestCompletionListInImportClause01
8576
TestCompletionListInImportClause05
8677
TestCompletionListInImportClause06
@@ -103,10 +94,6 @@ TestCompletionListInvalidMemberNames_withExistingIdentifier
10394
TestCompletionListObjectMembersInTypeLocationWithTypeof
10495
TestCompletionListOfGenericSymbol
10596
TestCompletionListOnAliases
106-
TestCompletionListOnAliases2
107-
TestCompletionListStaticMembers
108-
TestCompletionListStaticProtectedMembers2
109-
TestCompletionListStaticProtectedMembers3
11097
TestCompletionListStringParenthesizedExpression
11198
TestCompletionListStringParenthesizedType
11299
TestCompletionListWithoutVariableinitializer
@@ -119,12 +106,10 @@ TestCompletionOfInterfaceAndVar
119106
TestCompletionPreferredSuggestions1
120107
TestCompletionWithConditionalOperatorMissingColon
121108
TestCompletionsAfterJSDoc
122-
TestCompletionsAugmentedTypesClass2
123109
TestCompletionsBeforeRestArg1
124110
TestCompletionsExportImport
125111
TestCompletionsGenericTypeWithMultipleBases1
126112
TestCompletionsInRequire
127-
TestCompletionsInterfaceElement
128113
TestCompletionsJSDocImportTagAttributesEmptyModuleSpecifier1
129114
TestCompletionsJSDocImportTagAttributesErrorModuleSpecifier1
130115
TestCompletionsJSDocImportTagEmptyModuleSpecifier1
@@ -141,7 +126,6 @@ TestCompletionsKeyof
141126
TestCompletionsLiteralFromInferenceWithinInferredType3
142127
TestCompletionsLiterals
143128
TestCompletionsMergedDeclarations1
144-
TestCompletionsNamespaceMergedWithClass
145129
TestCompletionsNewTarget
146130
TestCompletionsOptionalMethod
147131
TestCompletionsOverridingMethod1
@@ -161,21 +145,17 @@ TestCompletionsPaths_kinds
161145
TestCompletionsPaths_pathMapping
162146
TestCompletionsPaths_pathMapping_nonTrailingWildcard1
163147
TestCompletionsPaths_pathMapping_parentDirectory
164-
TestCompletionsPropertiesPriorities
165148
TestCompletionsRecommended_union
166149
TestCompletionsRedeclareModuleAsGlobal
167150
TestCompletionsStringLiteral_fromTypeConstraint
168151
TestCompletionsStringsWithTriggerCharacter
169152
TestCompletionsSymbolMembers
170153
TestCompletionsTriggerCharacter
171-
TestCompletionsTypeOnlyNamespace
172154
TestCompletionsUniqueSymbol1
173-
TestCompletionsWithDeprecatedTag5
174155
TestCompletionsWithStringReplacementMode1
175156
TestDoubleUnderscoreCompletions
176157
TestExportDefaultClass
177158
TestExportDefaultFunction
178-
TestExportEqualCallableInterface
179159
TestFindAllReferencesTripleSlash
180160
TestFindAllReferencesUmdModuleAsGlobalConst
181161
TestFindAllRefsCommonJsRequire
@@ -222,7 +202,6 @@ TestImportCompletions_importsMap5
222202
TestImportStatementCompletions4
223203
TestImportStatementCompletions_noPatternAmbient
224204
TestImportStatementCompletions_pnpmTransitive
225-
TestImportTypeMemberCompletions
226205
TestJavascriptModules20
227206
TestJavascriptModules21
228207
TestJavascriptModulesTypeImport
@@ -250,10 +229,7 @@ TestJsxFindAllReferencesOnRuntimeImportWithPaths1
250229
TestLocalGetReferences
251230
TestMemberListInReopenedEnum
252231
TestMemberListInWithBlock
253-
TestMemberListOfClass
254232
TestMemberListOfExportedClass
255-
TestMemberListOfModuleAfterInvalidCharater
256-
TestMemberListOnConstructorType
257233
TestNodeModulesImportCompletions1
258234
TestPathCompletionsAllowModuleAugmentationExtensions
259235
TestPathCompletionsAllowTsExtensions
@@ -326,4 +302,3 @@ TestTsxCompletion14
326302
TestTsxCompletion15
327303
TestTsxCompletion8
328304
TestTsxCompletionNonTagLessThan
329-
TestUnclosedCommentsInConstructor

internal/fourslash/fourslash.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ func (f *FourslashTest) nextID() int32 {
228228
}
229229

230230
func (f *FourslashTest) initialize(t *testing.T, capabilities *lsproto.ClientCapabilities) {
231-
params := &lsproto.InitializeParams{}
231+
params := &lsproto.InitializeParams{
232+
Locale: ptrTo("en-US"),
233+
}
232234
params.Capabilities = getCapabilitiesWithDefaults(capabilities)
233235
// !!! check for errors?
234236
sendRequest(t, f, lsproto.InitializeInfo, params)

internal/fourslash/tests/gen/closedCommentsInConstructor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestClosedCommentsInConstructor(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `class Foo {
1515
constructor(/* /**/ */) { }

internal/fourslash/tests/gen/completionListAndMemberListOnCommentedDot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestCompletionListAndMemberListOnCommentedDot(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `module M {
1515
export class C { public pub = 0; private priv = 1; }

internal/fourslash/tests/gen/completionListAndMemberListOnCommentedWhiteSpace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestCompletionListAndMemberListOnCommentedWhiteSpace(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `module M {
1515
export class C { public pub = 0; private priv = 1; }

0 commit comments

Comments
 (0)