Skip to content

Commit

Permalink
add links for dependecy key attribute expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Apr 19, 2022
1 parent f24c834 commit f72f9ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
26 changes: 17 additions & 9 deletions decoder/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,24 @@ func (d *PathDecoder) linksInBody(body *hclsyntax.Body, bodySchema *schema.BodyS
if block.Body != nil {
depSchema, dk, ok := NewBlockSchema(blockSchema).DependentBodySchema(block.AsHCLBlock())
if ok && depSchema.DocsLink != nil {
link := depSchema.DocsLink
u, err := d.docsURL(link.URL, "documentLink")
if err != nil {
continue
}
for _, labelDep := range dk.Labels {
link := depSchema.DocsLink
u, err := d.docsURL(link.URL, "documentLink")
if err == nil {
links = append(links, lang.Link{
URI: u.String(),
Tooltip: link.Tooltip,
Range: block.LabelRanges[labelDep.Index],
})
}
links = append(links, lang.Link{
URI: u.String(),
Tooltip: link.Tooltip,
Range: block.LabelRanges[labelDep.Index],
})
}
for _, attrDep := range dk.Attributes {
links = append(links, lang.Link{
URI: u.String(),
Tooltip: link.Tooltip,
Range: block.Body.Attributes[attrDep.Name].Expr.Range(),
})
}
}
}
Expand Down
1 change: 1 addition & 0 deletions decoder/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestLinksInFile_json(t *testing.T) {
},
})

// We never want to provide links in JSON configs
_, err := d.LinksInFile("test.tf.json")
unknownFormatErr := &UnknownFileFormatError{}
if !errors.As(err, &unknownFormatErr) {
Expand Down

0 comments on commit f72f9ef

Please sign in to comment.