Skip to content

Commit 89ae392

Browse files
committed
Enable go-to-definition for computed field names.
When finding node by position, push `field.Name` to the search stack. This allows us to now search through the field names as well when finding definitions.
1 parent 1081444 commit 89ae392

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

pkg/ast_processing/find_position.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func FindNodeByPosition(node ast.Node, location ast.Location) (*nodestack.NodeSt
4646
funcBody.LocRange = field.LocRange
4747
stack.Push(funcBody)
4848
} else {
49+
stack.Push(field.Name)
4950
stack.Push(body)
5051
}
5152
}

pkg/server/definition_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,22 @@ var definitionTestCases = []definitionTestCase{
723723
},
724724
}},
725725
},
726+
{
727+
name: "goto computed field name object field",
728+
filename: "testdata/goto-computed-field-names.jsonnet",
729+
position: protocol.Position{Line: 3, Character: 9},
730+
results: []definitionResult{{
731+
targetFilename: "testdata/goto-computed-field-names.jsonnet",
732+
targetRange: protocol.Range{
733+
Start: protocol.Position{Line: 0, Character: 14},
734+
End: protocol.Position{Line: 0, Character: 26},
735+
},
736+
targetSelectionRange: protocol.Range{
737+
Start: protocol.Position{Line: 0, Character: 14},
738+
End: protocol.Position{Line: 0, Character: 17},
739+
},
740+
}},
741+
},
726742
}
727743

728744
func TestDefinition(t *testing.T) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local obj = { bar: 'hello'};
2+
3+
{
4+
[obj.bar]: 'world!'
5+
}

0 commit comments

Comments
 (0)