From 6744f6d3874378a72d17c17f699301fa8d538757 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 19 Sep 2023 10:27:45 +0100 Subject: [PATCH] Fix unresolvedBlocks --- pkg/steampipeconfig/parse/parse_context.go | 6 +++--- pkg/steampipeconfig/parse/unresolved_block.go | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/steampipeconfig/parse/parse_context.go b/pkg/steampipeconfig/parse/parse_context.go index e9c90dca76..ec21033e8d 100644 --- a/pkg/steampipeconfig/parse/parse_context.go +++ b/pkg/steampipeconfig/parse/parse_context.go @@ -55,7 +55,7 @@ func (r *ParseContext) ClearDependencies() { func (r *ParseContext) AddDependencies(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) hcl.Diagnostics { var diags hcl.Diagnostics // store unresolved block - r.UnresolvedBlocks[name] = &unresolvedBlock{Name: name, Block: block, Dependencies: dependencies} + r.UnresolvedBlocks[name] = newUnresolvedBlock(block, name, dependencies) // store dependency in tree - d if !r.dependencyGraph.ContainsNode(name) { @@ -119,10 +119,10 @@ func (r *ParseContext) BlocksToDecode() (hcl.Blocks, error) { // depOrder is all the blocks required to resolve dependencies. // if this one is unparsed, added to list block, ok := r.UnresolvedBlocks[name] - if !blocksMap[hclhelpers.BlockRange(block.Block).String()] && ok { + if ok && !blocksMap[block.DeclRange.String()] && ok { blocksToDecode = append(blocksToDecode, block.Block) // add to map - blocksMap[hclhelpers.BlockRange(block.Block).String()] = true + blocksMap[block.DeclRange.String()] = true } } return blocksToDecode, nil diff --git a/pkg/steampipeconfig/parse/unresolved_block.go b/pkg/steampipeconfig/parse/unresolved_block.go index 365a4cb4b7..1884057719 100644 --- a/pkg/steampipeconfig/parse/unresolved_block.go +++ b/pkg/steampipeconfig/parse/unresolved_block.go @@ -4,17 +4,27 @@ import ( "fmt" "strings" - "github.com/turbot/steampipe/pkg/steampipeconfig/modconfig" - "github.com/hashicorp/hcl/v2" + "github.com/turbot/steampipe/pkg/steampipeconfig/hclhelpers" + "github.com/turbot/steampipe/pkg/steampipeconfig/modconfig" ) type unresolvedBlock struct { Name string Block *hcl.Block + DeclRange hcl.Range Dependencies map[string]*modconfig.ResourceDependency } +func newUnresolvedBlock(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) *unresolvedBlock { + return &unresolvedBlock{ + Name: name, + Block: block, + Dependencies: dependencies, + DeclRange: hclhelpers.BlockRange(block), + } +} + func (b unresolvedBlock) String() string { depStrings := make([]string, len(b.Dependencies)) idx := 0