Skip to content

Commit f0d735b

Browse files
Yet another import case (#85)
* Yet another import case not working This adds a new test case that (hopefully) contains all the ways to reference something by import Fixed by doing recursive processing, I removed a "special" case to do so * oops, lint
1 parent dd39569 commit f0d735b

8 files changed

+45
-8
lines changed

pkg/ast/processing/find_field.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,11 @@ func extractObjectRangesFromDesugaredObjs(stack *nodestack.NodeStack, vm *jsonne
124124
return nil, err
125125
}
126126
// If the reference is an object, add it directly to the list of objects to look in
127-
if varReference := findChildDesugaredObject(varReference); varReference != nil {
128-
desugaredObjs = append(desugaredObjs, varReference)
129-
}
130-
// If the reference is a function, and the body of that function is an object, add it to the list of objects to look in
131-
if varReference, ok := varReference.(*ast.Function); ok {
132-
if funcBody := findChildDesugaredObject(varReference.Body); funcBody != nil {
133-
desugaredObjs = append(desugaredObjs, funcBody)
134-
}
127+
// Otherwise, add it back to the list for further processing
128+
if varReferenceObj := findChildDesugaredObject(varReference); varReferenceObj != nil {
129+
desugaredObjs = append(desugaredObjs, varReferenceObj)
130+
} else {
131+
fieldNodes = append(fieldNodes, varReference)
135132
}
136133
case *ast.DesugaredObject:
137134
desugaredObjs = append(desugaredObjs, fieldNode)

pkg/server/definition_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,22 @@ var definitionTestCases = []definitionTestCase{
894894
},
895895
}},
896896
},
897+
{
898+
name: "goto function nested multiple times in different ways",
899+
filename: "testdata/goto-multilevel-library-main.jsonnet",
900+
position: protocol.Position{Line: 2, Character: 34},
901+
results: []definitionResult{{
902+
targetFilename: "testdata/goto-multilevel-library-sub-1.1.libsonnet",
903+
targetRange: protocol.Range{
904+
Start: protocol.Position{Line: 1, Character: 2},
905+
End: protocol.Position{Line: 1, Character: 28},
906+
},
907+
targetSelectionRange: protocol.Range{
908+
Start: protocol.Position{Line: 1, Character: 2},
909+
End: protocol.Position{Line: 1, Character: 5},
910+
},
911+
}},
912+
},
897913
}
898914

899915
func TestDefinition(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
local library = import 'goto-multilevel-library-top.libsonnet';
2+
{
3+
my_item: library.sub1.subsub1.new(name='test'),
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
new(name='lib-1.1'):: name,
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
new(name='lib-1.2'):: name,
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
subsub1: import 'goto-multilevel-library-sub-1.1.libsonnet',
3+
subsub2: import 'goto-multilevel-library-sub-1.2.libsonnet',
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
new(name='lib-2'):: name,
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local sub1 = import 'goto-multilevel-library-sub-1.libsonnet';
2+
local sub2 = import 'goto-multilevel-library-sub-2.libsonnet';
3+
4+
{
5+
sub1:: sub1,
6+
sub2:: sub2,
7+
}

0 commit comments

Comments
 (0)