Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/ast/processing/find_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ func FindRangesFromIndexList(stack *nodestack.NodeStack, indexList []string, vm
if funcBody := findChildDesugaredObject(bodyNode.Body); funcBody != nil {
foundDesugaredObjects = append(foundDesugaredObjects, funcBody)
}
case *ast.Binary:
tmpStack := nodestack.NewNodeStack(bodyNode)
foundDesugaredObjects = FindTopLevelObjects(tmpStack, vm)
case *ast.Var:
varReference, err := FindVarReference(bodyNode, vm)
if err != nil {
return nil, err
}
// If the reference is an object, add it directly to the list of objects to look in
// Otherwise, add it back to the list for further processing
if varReferenceObj := findChildDesugaredObject(varReference); varReferenceObj != nil {
foundDesugaredObjects = append(foundDesugaredObjects, varReferenceObj)
}
//else {
// fieldNodes = append(fieldNodes, varReference)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from copy, not sure if/how to handle this

//}
default:
return nil, fmt.Errorf("unexpected node type when finding bind for '%s': %s", start, reflect.TypeOf(bind.Body))
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/server/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,55 @@ func TestCompletion(t *testing.T) {
},
},
},
{
name: "local assigned",
filename: "testdata/local_reassign.jsonnet",
replaceString: "a: newjob",
replaceByString: "a: job.",
expected: protocol.CompletionList{
IsIncomplete: false,
Items: []protocol.CompletionItem{
{
Label: "steps",
Kind: protocol.FieldCompletion,
Detail: "job.steps",
InsertText: "steps",
LabelDetails: protocol.CompletionItemLabelDetails{
Description: "object",
},
},
},
},
},
{
name: "local reassigned",
filename: "testdata/local_reassign.jsonnet",
replaceString: "a: newjob",
replaceByString: "a: newjob.",
expected: protocol.CompletionList{
IsIncomplete: false,
Items: []protocol.CompletionItem{
{
Label: "steps",
Kind: protocol.FieldCompletion,
Detail: "newjob.steps",
InsertText: "steps",
LabelDetails: protocol.CompletionItemLabelDetails{
Description: "object",
},
},
{
Label: "step",
Kind: protocol.FieldCompletion,
Detail: "newjob.step",
InsertText: "step",
LabelDetails: protocol.CompletionItemLabelDetails{
Description: "object",
},
},
},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/server/testdata/local_reassign.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local job = {
steps: { name: 'a', value: 'b' },
};

local newjob = job + {
steps: {},
step: super.steps,
};

{
a: newjob,
}