Skip to content

Commit f508226

Browse files
Fix double completion bug
woops Closes #122
1 parent 9708978 commit f508226

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

pkg/ast/processing/find_field.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func extractObjectRangesFromDesugaredObjs(stack *nodestack.NodeStack, vm *jsonne
8888
for len(indexList) > 0 {
8989
index := indexList[0]
9090
indexList = indexList[1:]
91-
partialMatchFields := partialMatchFields && len(indexList) == 0 // Only partial match on the last index. Others are considered complete
92-
foundFields := findObjectFieldsInObjects(desugaredObjs, index, partialMatchFields)
91+
partialMatchCurrentField := partialMatchFields && len(indexList) == 0 // Only partial match on the last index. Others are considered complete
92+
foundFields := findObjectFieldsInObjects(desugaredObjs, index, partialMatchCurrentField)
9393
desugaredObjs = nil
9494
if len(foundFields) == 0 {
9595
return nil, fmt.Errorf("field %s was not found in ast.DesugaredObject", index)
@@ -99,8 +99,8 @@ func extractObjectRangesFromDesugaredObjs(stack *nodestack.NodeStack, vm *jsonne
9999
ranges = append(ranges, FieldToRange(*found))
100100

101101
// If the field is not PlusSuper (field+: value), we stop there. Other previous values are not relevant
102-
// If partialMatchFields is true, we can continue to look for other fields
103-
if !found.PlusSuper && !partialMatchFields {
102+
// If partialMatchCurrentField is true, we can continue to look for other fields
103+
if !found.PlusSuper && !partialMatchCurrentField {
104104
break
105105
}
106106
}

pkg/server/completion_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,26 @@ func TestCompletion(t *testing.T) {
566566
},
567567
},
568568
},
569+
{
570+
name: "autocomplete fix doubled index bug",
571+
filename: "testdata/doubled-index-bug-3.jsonnet",
572+
replaceString: "a: g.hello",
573+
replaceByString: "a: g.hello.",
574+
expected: protocol.CompletionList{
575+
IsIncomplete: false,
576+
Items: []protocol.CompletionItem{
577+
{
578+
Label: "to",
579+
Kind: protocol.FieldCompletion,
580+
Detail: "g.hello.to",
581+
InsertText: "to",
582+
LabelDetails: protocol.CompletionItemLabelDetails{
583+
Description: "object",
584+
},
585+
},
586+
},
587+
},
588+
},
569589
}
570590
for _, tc := range testCases {
571591
t.Run(tc.name, func(t *testing.T) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
hello: {
3+
to: {
4+
the: 'world',
5+
},
6+
},
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ hello: (import 'doubled-index-bug-1.jsonnet').hello }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local g = import 'doubled-index-bug-2.jsonnet';
2+
{
3+
// completing fields of `g.hello` should get use `g.hello.to`, not `g.hello.hello`
4+
a: g.hello,
5+
}

0 commit comments

Comments
 (0)