Skip to content

Commit 80fa3ba

Browse files
committed
Allow jumping to a target from a group block
Support textDocument/definition requests for jumping from a group block's targets attribute to the referenced target block. Signed-off-by: Remy Suen <[email protected]>
1 parent 60437d0 commit 80fa3ba

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

internal/bake/hcl/definition.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ func ResolveAttributeValue(ctx context.Context, definitionLinkSupport bool, mana
127127
if isInsideRange(e.Range(), position) {
128128
if templateExpr, ok := e.(*hclsyntax.TemplateExpr); ok {
129129
if templateExpr.IsStringLiteral() {
130-
if attribute.Name == "inherits" && sourceBlock.Type == "target" {
130+
// look up a target reference if it's inside a
131+
// target block's inherits attribute, or a
132+
// group block's targets attribute
133+
if (sourceBlock.Type == "target" && attribute.Name == "inherits") ||
134+
(sourceBlock.Type == "group" && attribute.Name == "targets") {
131135
value, _ := templateExpr.Value(&hcl.EvalContext{})
132136
target := value.AsString()
133137
return CalculateBlockLocation(input, body, documentURI, "target", target, false)

internal/bake/hcl/definition_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ func TestDefinition(t *testing.T) {
183183
},
184184
},
185185
},
186+
{
187+
name: "group block's targets attribute points to a valid target",
188+
content: "target \"t1\" {}\ngroup \"g1\" {\n targets = [ \"t1\" ]\n}",
189+
line: 2,
190+
character: 16,
191+
links: []protocol.Location{
192+
{
193+
URI: bakeFileURI,
194+
Range: protocol.Range{
195+
Start: protocol.Position{Line: 0, Character: 8},
196+
End: protocol.Position{Line: 0, Character: 10},
197+
},
198+
},
199+
},
200+
},
186201
{
187202
name: "inherits attribute points to an unquoted variable",
188203
content: "variable \"var\" {}\ntarget \"default\" {\n inherits = [ var ]\n}",

0 commit comments

Comments
 (0)