diff --git a/internal/terraform/lang/config_block_test.go b/internal/terraform/lang/config_block_test.go index 7a583cd41..50b9d7b5c 100644 --- a/internal/terraform/lang/config_block_test.go +++ b/internal/terraform/lang/config_block_test.go @@ -250,7 +250,7 @@ func TestCompletableBlock_CompletionCandidatesAtPos(t *testing.T) { cb := &completableBlock{ logger: testLogger(), - block: ParseBlock(block, []*Label{}, tc.sb), + block: ParseBlock(block, []*ParsedLabel{}, tc.sb), } list, err := cb.completionCandidatesAtPos(tc.pos) diff --git a/internal/terraform/lang/datasource_block.go b/internal/terraform/lang/datasource_block.go index b9fe9b9d4..dd52c595e 100644 --- a/internal/terraform/lang/datasource_block.go +++ b/internal/terraform/lang/datasource_block.go @@ -38,7 +38,7 @@ type datasourceBlock struct { logger *log.Logger labelSchema LabelSchema - labels []*Label + labels []*ParsedLabel hclBlock *hclsyntax.Block sr schema.Reader } @@ -64,7 +64,7 @@ func (r *datasourceBlock) Name() string { return fmt.Sprintf("%s.%s", firstLabel, secondLabel) } -func (r *datasourceBlock) Labels() []*Label { +func (r *datasourceBlock) Labels() []*ParsedLabel { if r.labels != nil { return r.labels } diff --git a/internal/terraform/lang/hcl_block.go b/internal/terraform/lang/hcl_block.go index 5bd642e1f..8f0015dde 100644 --- a/internal/terraform/lang/hcl_block.go +++ b/internal/terraform/lang/hcl_block.go @@ -7,7 +7,7 @@ import ( type parsedBlock struct { hclBlock *hclsyntax.Block - labels []*Label + labels []*ParsedLabel AttributesMap map[string]*Attribute BlockTypesMap map[string]*BlockType @@ -59,7 +59,7 @@ func (b *parsedBlock) PosInLabels(pos hcl.Pos) bool { return false } -func (b *parsedBlock) LabelAtPos(pos hcl.Pos) (*Label, bool) { +func (b *parsedBlock) LabelAtPos(pos hcl.Pos) (*ParsedLabel, bool) { for i, rng := range b.hclBlock.LabelRanges { if rng.ContainsPos(pos) { // TODO: Guard against crashes when user sets label where we don't expect it diff --git a/internal/terraform/lang/hcl_block_type.go b/internal/terraform/lang/hcl_block_type.go index 8edc80df9..6a48ef505 100644 --- a/internal/terraform/lang/hcl_block_type.go +++ b/internal/terraform/lang/hcl_block_type.go @@ -62,7 +62,7 @@ func (bt BlockTypes) AddBlock(name string, block *hclsyntax.Block, typeSchema *t if block != nil { // SDK doesn't support named blocks yet, so we expect no labels here for now - labels := make([]*Label, 0) + labels := make([]*ParsedLabel, 0) bt[name].BlockList = append(bt[name].BlockList, ParseBlock(block, labels, typeSchema.Block)) } } diff --git a/internal/terraform/lang/hcl_parser.go b/internal/terraform/lang/hcl_parser.go index bdb94072d..502f2a710 100644 --- a/internal/terraform/lang/hcl_parser.go +++ b/internal/terraform/lang/hcl_parser.go @@ -10,7 +10,7 @@ import ( // ParseBlock parses HCL configuration based on tfjson's SchemaBlock // and keeps hold of all tfjson schema details on block or attribute level -func ParseBlock(block *hclsyntax.Block, labels []*Label, schema *tfjson.SchemaBlock) Block { +func ParseBlock(block *hclsyntax.Block, labels []*ParsedLabel, schema *tfjson.SchemaBlock) Block { b := &parsedBlock{ hclBlock: block, labels: labels, diff --git a/internal/terraform/lang/hcl_parser_test.go b/internal/terraform/lang/hcl_parser_test.go index de95cb8a4..5e9b9c4f1 100644 --- a/internal/terraform/lang/hcl_parser_test.go +++ b/internal/terraform/lang/hcl_parser_test.go @@ -307,7 +307,7 @@ func TestParseBlock_attributesAndBlockTypes(t *testing.T) { t.Fatal(err) } - b := ParseBlock(block, []*Label{}, tc.schema) + b := ParseBlock(block, []*ParsedLabel{}, tc.schema) if diff := cmp.Diff(tc.expectedAttributes, b.Attributes(), opts...); diff != "" { t.Fatalf("Attributes don't match.\n%s", diff) @@ -471,7 +471,7 @@ func TestBlock_BlockAtPos(t *testing.T) { t.Fatal(err) } - b := ParseBlock(block, []*Label{}, schema) + b := ParseBlock(block, []*ParsedLabel{}, schema) fBlock, _ := b.BlockAtPos(tc.pos) if diff := cmp.Diff(tc.expectedBlock, fBlock, opts...); diff != "" { t.Fatalf("Block doesn't match.\n%s", diff) @@ -631,7 +631,7 @@ func TestBlock_PosInBody(t *testing.T) { t.Fatal(err) } - b := ParseBlock(block, []*Label{}, schema) + b := ParseBlock(block, []*ParsedLabel{}, schema) isInBody := b.PosInBody(tc.pos) if tc.expected != isInBody { if tc.expected { @@ -766,7 +766,7 @@ func TestBlock_PosInAttributes(t *testing.T) { t.Fatal(err) } - b := ParseBlock(block, []*Label{}, schema) + b := ParseBlock(block, []*ParsedLabel{}, schema) isInAttribute := b.PosInAttribute(tc.pos) if tc.expected != isInAttribute { if tc.expected { diff --git a/internal/terraform/lang/labels.go b/internal/terraform/lang/labels.go index 4193e95ac..0277840d9 100644 --- a/internal/terraform/lang/labels.go +++ b/internal/terraform/lang/labels.go @@ -1,14 +1,14 @@ package lang -func parseLabels(blockType string, schema LabelSchema, parsed []string) []*Label { - labels := make([]*Label, len(schema)) +func parseLabels(blockType string, schema LabelSchema, parsed []string) []*ParsedLabel { + labels := make([]*ParsedLabel, len(schema)) for i, labelName := range schema { var value string if len(parsed)-1 >= i { value = parsed[i] } - labels[i] = &Label{ + labels[i] = &ParsedLabel{ Name: labelName, Value: value, } diff --git a/internal/terraform/lang/provider_block.go b/internal/terraform/lang/provider_block.go index 72e46cf42..33a788830 100644 --- a/internal/terraform/lang/provider_block.go +++ b/internal/terraform/lang/provider_block.go @@ -37,7 +37,7 @@ type providerBlock struct { logger *log.Logger labelSchema LabelSchema - labels []*Label + labels []*ParsedLabel hclBlock *hclsyntax.Block sr schema.Reader } @@ -54,7 +54,7 @@ func (p *providerBlock) RawName() string { return p.Labels()[0].Value } -func (p *providerBlock) Labels() []*Label { +func (p *providerBlock) Labels() []*ParsedLabel { if p.labels != nil { return p.labels } diff --git a/internal/terraform/lang/resource_block.go b/internal/terraform/lang/resource_block.go index b227431cc..dbbabcdf5 100644 --- a/internal/terraform/lang/resource_block.go +++ b/internal/terraform/lang/resource_block.go @@ -38,7 +38,7 @@ type resourceBlock struct { logger *log.Logger labelSchema LabelSchema - labels []*Label + labels []*ParsedLabel hclBlock *hclsyntax.Block sr schema.Reader } @@ -64,7 +64,7 @@ func (r *resourceBlock) Name() string { return fmt.Sprintf("%s.%s", firstLabel, secondLabel) } -func (r *resourceBlock) Labels() []*Label { +func (r *resourceBlock) Labels() []*ParsedLabel { if r.labels != nil { return r.labels } diff --git a/internal/terraform/lang/types.go b/internal/terraform/lang/types.go index bb17635df..59e26f7fe 100644 --- a/internal/terraform/lang/types.go +++ b/internal/terraform/lang/types.go @@ -22,14 +22,14 @@ type ConfigBlock interface { CompletionCandidatesAtPos(pos hcl.Pos) (CompletionCandidates, error) Name() string BlockType() string - Labels() []*Label + Labels() []*ParsedLabel } // Block represents a decoded HCL block (by a Parser) // which keeps track of the related schema type Block interface { BlockAtPos(pos hcl.Pos) (Block, bool) - LabelAtPos(pos hcl.Pos) (*Label, bool) + LabelAtPos(pos hcl.Pos) (*ParsedLabel, bool) Range() hcl.Range PosInLabels(pos hcl.Pos) bool PosInBody(pos hcl.Pos) bool @@ -40,7 +40,7 @@ type Block interface { type LabelSchema []string -type Label struct { +type ParsedLabel struct { Name string Value string }