Skip to content

Commit

Permalink
decoder: Display Tuple hover data on invalid element (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Apr 18, 2023
1 parent cf2813f commit 34c0b60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion decoder/expr_tuple_hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func (tuple Tuple) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData

for i, elemExpr := range eType.Exprs {
if i+1 > len(tuple.cons.Elems) {
return nil
// fall back to details about whole tuple
// for invalid (unknown) elements
break
}

if elemExpr.Range().ContainsPos(pos) {
Expand Down
24 changes: 24 additions & 0 deletions decoder/expr_tuple_hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,30 @@ func TestHoverAtPos_exprTuple(t *testing.T) {
},
},
},
{
"trailing unknown element",
map[string]*schema.AttributeSchema{
"attr": {
Constraint: schema.Tuple{
Elems: []schema.Constraint{
schema.Keyword{
Keyword: "keyword",
},
},
},
},
},
`attr = [ keyword, foobar ]`,
hcl.Pos{Line: 1, Column: 21, Byte: 20},
&lang.HoverData{
Content: lang.Markdown("_tuple_"),
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{Line: 1, Column: 8, Byte: 7},
End: hcl.Pos{Line: 1, Column: 27, Byte: 26},
},
},
},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 34c0b60

Please sign in to comment.