Skip to content

Commit 263cc4d

Browse files
committed
fix relevant tokens order
1 parent 3560492 commit 263cc4d

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
@@ -1766,6 +1766,43 @@ const bar: {
17661766
},
17671767
},
17681768
},
1769+
{
1770+
name: "extendsKeywordCompletion2",
1771+
files: map[string]string{
1772+
defaultMainFileName: `function f1<T /*1*/>() {}
1773+
function f2<T ext/*2*/>() {}`,
1774+
},
1775+
expectedResult: map[string]*testCaseResult{
1776+
// "1": {
1777+
// list: &lsproto.CompletionList{
1778+
// IsIncomplete: false,
1779+
// ItemDefaults: itemDefaults,
1780+
// Items: []*lsproto.CompletionItem{
1781+
// {
1782+
// Label: "extends",
1783+
// Kind: keywordKind,
1784+
// SortText: sortTextGlobalsOrKeywords,
1785+
// },
1786+
// },
1787+
// },
1788+
// isIncludes: true,
1789+
// },
1790+
"2": {
1791+
list: &lsproto.CompletionList{
1792+
IsIncomplete: false,
1793+
ItemDefaults: itemDefaults,
1794+
Items: []*lsproto.CompletionItem{
1795+
{
1796+
Label: "extends",
1797+
Kind: keywordKind,
1798+
SortText: sortTextGlobalsOrKeywords,
1799+
},
1800+
},
1801+
},
1802+
isIncludes: true,
1803+
},
1804+
},
1805+
},
17691806
}
17701807
for _, testCase := range testCases {
17711808
t.Run(testCase.name, func(t *testing.T) {

0 commit comments

Comments
 (0)