Skip to content

Commit 94476b9

Browse files
committed
fix relevant tokens order
1 parent 818d26b commit 94476b9

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

internal/ls/completions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (l *LanguageService) getCompletionsAtPosition(
264264
preferences *UserPreferences,
265265
clientOptions *lsproto.CompletionClientCapabilities,
266266
) *lsproto.CompletionList {
267-
previousToken, _ := getRelevantTokens(position, file)
267+
_, previousToken := getRelevantTokens(position, file)
268268
if context.TriggerCharacter != nil && !isInString(file, position, previousToken) && !isValidTrigger(file, *context.TriggerCharacter, previousToken, position) {
269269
return nil
270270
}
@@ -331,7 +331,7 @@ func getCompletionData(program *compiler.Program, file *ast.SourceFile, position
331331
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
332332
// Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file
333333
isJSOnlyLocation := !insideJSDocTagTypeExpression && !insideJsDocImportTag && ast.IsSourceFileJS(file)
334-
previousToken, contextToken := getRelevantTokens(position, file)
334+
contextToken, previousToken := getRelevantTokens(position, file)
335335

336336
// Find the node where completion is requested on.
337337
// Also determine whether we are trying to complete with members of that node

internal/ls/completions_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,43 @@ const bar: {
17571757
},
17581758
},
17591759
},
1760+
{
1761+
name: "extendsKeywordCompletion2",
1762+
files: map[string]string{
1763+
defaultMainFileName: `function f1<T /*1*/>() {}
1764+
function f2<T ext/*2*/>() {}`,
1765+
},
1766+
expectedResult: map[string]*testCaseResult{
1767+
// "1": {
1768+
// list: &lsproto.CompletionList{
1769+
// IsIncomplete: false,
1770+
// ItemDefaults: itemDefaults,
1771+
// Items: []*lsproto.CompletionItem{
1772+
// {
1773+
// Label: "extends",
1774+
// Kind: keywordKind,
1775+
// SortText: sortTextGlobalsOrKeywords,
1776+
// },
1777+
// },
1778+
// },
1779+
// isIncludes: true,
1780+
// },
1781+
"2": {
1782+
list: &lsproto.CompletionList{
1783+
IsIncomplete: false,
1784+
ItemDefaults: itemDefaults,
1785+
Items: []*lsproto.CompletionItem{
1786+
{
1787+
Label: "extends",
1788+
Kind: keywordKind,
1789+
SortText: sortTextGlobalsOrKeywords,
1790+
},
1791+
},
1792+
},
1793+
isIncludes: true,
1794+
},
1795+
},
1796+
},
17601797
}
17611798
for _, testCase := range testCases {
17621799
t.Run(testCase.name, func(t *testing.T) {

0 commit comments

Comments
 (0)