Skip to content

Commit

Permalink
add links for dependecy key attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Apr 13, 2022
1 parent c79ebdb commit dc815fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions decoder/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ func (d *PathDecoder) linksInBody(body hcl.Body, bodySchema *schema.BodySchema)
content := decodeBody(body, bodySchema)
links := make([]lang.Link, 0)

// Attributes acting as dependency keys can have links associated
for _, attr := range content.Attributes {
aSchema, ok := bodySchema.Attributes[attr.Name]

if !ok {
if bodySchema.AnyAttribute == nil {
// skip unknown attribute
continue
}
aSchema = bodySchema.AnyAttribute
}

if aSchema.IsDepKey && bodySchema.DocsLink != nil {
u, err := d.docsURL(bodySchema.DocsLink.URL, "documentLink")
if err == nil {
links = append(links, lang.Link{
URI: u.String(),
Tooltip: bodySchema.DocsLink.Tooltip,
Range: attr.Expr.Range(),
})
}
}
}

for _, block := range content.Blocks {
blockSchema, ok := bodySchema.Blocks[block.Type]
if !ok {
Expand Down
6 changes: 3 additions & 3 deletions decoder/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func TestLinksInFile_json(t *testing.T) {
})

_, err := d.LinksInFile("test.tf.json")
unknownFormatErr := &UnknownFileFormatError{}
if !errors.As(err, &unknownFormatErr) {
t.Fatal("expected UnknownFileFormatError for JSON body")
noSchemaErr := &NoSchemaError{}
if !errors.As(err, &noSchemaErr) {
t.Fatal("expected NoSchemaError for JSON body")
}
}

0 comments on commit dc815fd

Please sign in to comment.