From f72f9ef115c2abe6331e8eac09c4cc1d750d0fa5 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Tue, 19 Apr 2022 15:55:22 +0200 Subject: [PATCH] add links for dependecy key attribute expressions --- decoder/links.go | 26 +++++++++++++++++--------- decoder/links_test.go | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/decoder/links.go b/decoder/links.go index fa2941f4..829c244a 100644 --- a/decoder/links.go +++ b/decoder/links.go @@ -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(), + }) } } } diff --git a/decoder/links_test.go b/decoder/links_test.go index fe8f253c..bba17b93 100644 --- a/decoder/links_test.go +++ b/decoder/links_test.go @@ -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) {