Skip to content

Commit 818d26b

Browse files
committed
tests, fix scanner usage in findPrecedingToken
1 parent ac2f853 commit 818d26b

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

internal/ast/ast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ func (n *Node) PropertyList() *NodeList {
799799
switch n.Kind {
800800
case KindObjectLiteralExpression:
801801
return n.AsObjectLiteralExpression().Properties
802-
case KindJsxAttribute:
802+
case KindJsxAttributes:
803803
return n.AsJsxAttributes().Properties
804804
}
805805
panic("Unhandled case in Node.PropertyList: " + n.Kind.String())

internal/astnav/tokens.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ func findRightmostValidToken(endPos int, sourceFile *ast.SourceFile, containingN
480480
}
481481
startPos = visitedNode.End()
482482
scanner.ResetPos(startPos)
483+
scanner.Scan()
483484
}
484485
// Trailing tokens after last visited node.
485486
for startPos < min(endPos, position) {

internal/ls/completions_test.go

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type testCase struct {
2626
type testCaseResult struct {
2727
list *lsproto.CompletionList
2828
isIncludes bool
29+
excludes []string
2930
}
3031

3132
const defaultMainFileName = "/index.ts"
@@ -1215,18 +1216,10 @@ class Foo {
12151216
},
12161217
expectedResult: map[string]*testCaseResult{
12171218
"1": {
1218-
list: &lsproto.CompletionList{
1219-
IsIncomplete: false,
1220-
ItemDefaults: itemDefaults,
1221-
Items: []*lsproto.CompletionItem{},
1222-
},
1219+
list: nil, // !!! jsx
12231220
},
12241221
"2": {
1225-
list: &lsproto.CompletionList{
1226-
IsIncomplete: false,
1227-
ItemDefaults: itemDefaults,
1228-
Items: []*lsproto.CompletionItem{},
1229-
},
1222+
list: nil, // !!! jsx
12301223
},
12311224
},
12321225
},
@@ -1720,6 +1713,50 @@ x./**/;`,
17201713
},
17211714
},
17221715
},
1716+
{
1717+
name: "completionsDotDotDotInObjectLiteral1",
1718+
files: map[string]string{
1719+
defaultMainFileName: `const foo = { b: 100 };
1720+
const bar: {
1721+
a: number;
1722+
b: number;
1723+
} = {
1724+
a: 42,
1725+
.../*1*/
1726+
};`,
1727+
},
1728+
expectedResult: map[string]*testCaseResult{
1729+
"1": {
1730+
list: &lsproto.CompletionList{
1731+
IsIncomplete: false,
1732+
ItemDefaults: itemDefaults,
1733+
Items: []*lsproto.CompletionItem{
1734+
{
1735+
Label: "foo",
1736+
Kind: variableKind,
1737+
SortText: sortTextLocationPriority,
1738+
InsertTextFormat: insertTextFormatPlainText,
1739+
TextEdit: &lsproto.TextEditOrInsertReplaceEdit{
1740+
InsertReplaceEdit: &lsproto.InsertReplaceEdit{
1741+
NewText: "foo",
1742+
Insert: lsproto.Range{
1743+
Start: lsproto.Position{Line: 6, Character: 5},
1744+
End: lsproto.Position{Line: 6, Character: 5},
1745+
},
1746+
Replace: lsproto.Range{
1747+
Start: lsproto.Position{Line: 6, Character: 5},
1748+
End: lsproto.Position{Line: 6, Character: 5},
1749+
},
1750+
},
1751+
},
1752+
},
1753+
},
1754+
},
1755+
isIncludes: true,
1756+
excludes: []string{"b"},
1757+
},
1758+
},
1759+
},
17231760
}
17241761
for _, testCase := range testCases {
17251762
t.Run(testCase.name, func(t *testing.T) {
@@ -1779,6 +1816,13 @@ func runTest(t *testing.T, files map[string]string, expected map[string]*testCas
17791816
} else {
17801817
assert.DeepEqual(t, completionList, expectedResult.list)
17811818
}
1819+
for _, excludedLabel := range expectedResult.excludes {
1820+
for _, item := range completionList.Items {
1821+
if item.Label == excludedLabel {
1822+
t.Fatalf("Label %s should not be included in completion list", excludedLabel)
1823+
}
1824+
}
1825+
}
17821826
}
17831827
}
17841828

0 commit comments

Comments
 (0)