From 697cb78e35e53908f749b9953bc11e4aec41dccf Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 4 Sep 2023 16:18:45 +0100 Subject: [PATCH] validations: Validate only first 2 segments of a reference (#1380) --- .../decoder/validations/unreferenced_origin.go | 14 ++++++++++++-- .../validations/unreferenced_origin_test.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/internal/decoder/validations/unreferenced_origin.go b/internal/decoder/validations/unreferenced_origin.go index aa19bfdf7..046acc9a4 100644 --- a/internal/decoder/validations/unreferenced_origin.go +++ b/internal/decoder/validations/unreferenced_origin.go @@ -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 } @@ -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) diff --git a/internal/decoder/validations/unreferenced_origin_test.go b/internal/decoder/validations/unreferenced_origin_test.go index 2f0457a9c..fba76ecf2 100644 --- a/internal/decoder/validations/unreferenced_origin_test.go +++ b/internal/decoder/validations/unreferenced_origin_test.go @@ -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{