Skip to content

Commit 3560492

Browse files
committed
tests, fix scanner usage in findPrecedingToken
1 parent fe4ab58 commit 3560492

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

internal/ast/ast.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ func (n *Node) PropertyList() *NodeList {
779779
switch n.Kind {
780780
case KindObjectLiteralExpression:
781781
return n.AsObjectLiteralExpression().Properties
782-
case KindJsxAttribute:
782+
case KindJsxAttributes:
783783
return n.AsJsxAttributes().Properties
784784
}
785785
panic("Unhandled case in Node.PropertyList: " + n.Kind.String())

internal/astnav/tokens.go

+1
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

+54-10
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"
@@ -1214,18 +1215,10 @@ class Foo {
12141215
},
12151216
expectedResult: map[string]*testCaseResult{
12161217
"1": {
1217-
list: &lsproto.CompletionList{
1218-
IsIncomplete: false,
1219-
ItemDefaults: itemDefaults,
1220-
Items: []*lsproto.CompletionItem{},
1221-
},
1218+
list: nil, // !!! jsx
12221219
},
12231220
"2": {
1224-
list: &lsproto.CompletionList{
1225-
IsIncomplete: false,
1226-
ItemDefaults: itemDefaults,
1227-
Items: []*lsproto.CompletionItem{},
1228-
},
1221+
list: nil, // !!! jsx
12291222
},
12301223
},
12311224
},
@@ -1729,6 +1722,50 @@ x./**/;`,
17291722
},
17301723
},
17311724
},
1725+
{
1726+
name: "completionsDotDotDotInObjectLiteral1",
1727+
files: map[string]string{
1728+
defaultMainFileName: `const foo = { b: 100 };
1729+
const bar: {
1730+
a: number;
1731+
b: number;
1732+
} = {
1733+
a: 42,
1734+
.../*1*/
1735+
};`,
1736+
},
1737+
expectedResult: map[string]*testCaseResult{
1738+
"1": {
1739+
list: &lsproto.CompletionList{
1740+
IsIncomplete: false,
1741+
ItemDefaults: itemDefaults,
1742+
Items: []*lsproto.CompletionItem{
1743+
{
1744+
Label: "foo",
1745+
Kind: variableKind,
1746+
SortText: sortTextLocationPriority,
1747+
InsertTextFormat: insertTextFormatPlainText,
1748+
TextEdit: &lsproto.TextEditOrInsertReplaceEdit{
1749+
InsertReplaceEdit: &lsproto.InsertReplaceEdit{
1750+
NewText: "foo",
1751+
Insert: lsproto.Range{
1752+
Start: lsproto.Position{Line: 6, Character: 5},
1753+
End: lsproto.Position{Line: 6, Character: 5},
1754+
},
1755+
Replace: lsproto.Range{
1756+
Start: lsproto.Position{Line: 6, Character: 5},
1757+
End: lsproto.Position{Line: 6, Character: 5},
1758+
},
1759+
},
1760+
},
1761+
},
1762+
},
1763+
},
1764+
isIncludes: true,
1765+
excludes: []string{"b"},
1766+
},
1767+
},
1768+
},
17321769
}
17331770
for _, testCase := range testCases {
17341771
t.Run(testCase.name, func(t *testing.T) {
@@ -1788,6 +1825,13 @@ func runTest(t *testing.T, files map[string]string, expected map[string]*testCas
17881825
} else {
17891826
assert.DeepEqual(t, completionList, expectedResult.list)
17901827
}
1828+
for _, excludedLabel := range expectedResult.excludes {
1829+
for _, item := range completionList.Items {
1830+
if item.Label == excludedLabel {
1831+
t.Fatalf("Label %s should not be included in completion list", excludedLabel)
1832+
}
1833+
}
1834+
}
17911835
}
17921836
}
17931837

0 commit comments

Comments
 (0)