Skip to content

Commit

Permalink
validations: Validate only first 2 segments of a reference (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Sep 4, 2023
1 parent 7b2916e commit 2134933
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/decoder/validations/unreferenced_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ func UnreferencedOrigins(ctx context.Context, pathCtx *decoder.PathContext) lang
continue
}

address := matchableOrigin.Address()

if len(address) > 2 {
// We temporarily ignore references with more than 2 segments
// as these indicate references to complex types
// which we do not fully support yet.
// TODO: revisit as part of https://github.com/hashicorp/terraform-ls/issues/653
continue
}

// we only initially validate variables
// resources and data sources can have unknown schema
// and will be researched at a later point
firstStep := matchableOrigin.Address()[0]
firstStep := address[0]
if firstStep.String() != "var" {
continue
}
Expand All @@ -48,7 +58,7 @@ func UnreferencedOrigins(ctx context.Context, pathCtx *decoder.PathContext) lang
fileName := origin.OriginRange().Filename
d := &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("No declaration found for %q", matchableOrigin.Address()),
Summary: fmt.Sprintf("No declaration found for %q", address),
Subject: origin.OriginRange().Ptr(),
}
diagsMap[fileName] = diagsMap[fileName].Append(d)
Expand Down
18 changes: 18 additions & 0 deletions internal/decoder/validations/unreferenced_origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ func TestUnreferencedOrigins(t *testing.T) {
},
},
},
{
name: "unsupported variable of complex type",
origins: reference.Origins{
reference.LocalOrigin{
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{},
End: hcl.Pos{},
},
Addr: lang.Address{
lang.RootStep{Name: "var"},
lang.AttrStep{Name: "obj"},
lang.AttrStep{Name: "field"},
},
},
},
want: lang.DiagnosticsMap{},
},
{
name: "unsupported path origins (module input)",
origins: reference.Origins{
Expand Down

0 comments on commit 2134933

Please sign in to comment.