Skip to content

Commit

Permalink
Merge pull request #487 from hashicorp/align-def-range
Browse files Browse the repository at this point in the history
Align `hcl.Block` & `hclsyntax.Block` `DefRange`
  • Loading branch information
radeksimko authored Sep 22, 2021
2 parents c5b7229 + 1085e8d commit e84201c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions hclsyntax/navigation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ data "another" "baz" {
}{
{0, hcl.Range{}},
{2, hcl.Range{}},
{4, hcl.Range{Filename: "", Start: hcl.Pos{Line: 4, Column: 1, Byte: 3}, End: hcl.Pos{Line: 4, Column: 11, Byte: 13}}},
{17, hcl.Range{Filename: "", Start: hcl.Pos{Line: 7, Column: 1, Byte: 17}, End: hcl.Pos{Line: 7, Column: 25, Byte: 41}}},
{25, hcl.Range{Filename: "", Start: hcl.Pos{Line: 7, Column: 1, Byte: 17}, End: hcl.Pos{Line: 7, Column: 25, Byte: 41}}},
{45, hcl.Range{Filename: "", Start: hcl.Pos{Line: 10, Column: 1, Byte: 45}, End: hcl.Pos{Line: 10, Column: 33, Byte: 77}}},
{142, hcl.Range{Filename: "", Start: hcl.Pos{Line: 18, Column: 1, Byte: 142}, End: hcl.Pos{Line: 18, Column: 23, Byte: 164}}},
{180, hcl.Range{Filename: "", Start: hcl.Pos{Line: 18, Column: 1, Byte: 142}, End: hcl.Pos{Line: 18, Column: 23, Byte: 164}}},
{4, hcl.Range{Filename: "", Start: hcl.Pos{Line: 4, Column: 1, Byte: 3}, End: hcl.Pos{Line: 4, Column: 9, Byte: 11}}},
{17, hcl.Range{Filename: "", Start: hcl.Pos{Line: 7, Column: 1, Byte: 17}, End: hcl.Pos{Line: 7, Column: 23, Byte: 39}}},
{25, hcl.Range{Filename: "", Start: hcl.Pos{Line: 7, Column: 1, Byte: 17}, End: hcl.Pos{Line: 7, Column: 23, Byte: 39}}},
{45, hcl.Range{Filename: "", Start: hcl.Pos{Line: 10, Column: 1, Byte: 45}, End: hcl.Pos{Line: 10, Column: 31, Byte: 75}}},
{142, hcl.Range{Filename: "", Start: hcl.Pos{Line: 18, Column: 1, Byte: 142}, End: hcl.Pos{Line: 18, Column: 21, Byte: 162}}},
{180, hcl.Range{Filename: "", Start: hcl.Pos{Line: 18, Column: 1, Byte: 142}, End: hcl.Pos{Line: 18, Column: 21, Byte: 162}}},
{99999, hcl.Range{}},
}

Expand Down
13 changes: 6 additions & 7 deletions hclsyntax/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ func (b *Block) AsHCLBlock() *hcl.Block {
return nil
}

lastHeaderRange := b.TypeRange
if len(b.LabelRanges) > 0 {
lastHeaderRange = b.LabelRanges[len(b.LabelRanges)-1]
}

return &hcl.Block{
Type: b.Type,
Labels: b.Labels,
Body: b.Body,

DefRange: hcl.RangeBetween(b.TypeRange, lastHeaderRange),
DefRange: b.DefRange(),
TypeRange: b.TypeRange,
LabelRanges: b.LabelRanges,
}
Expand Down Expand Up @@ -390,5 +385,9 @@ func (b *Block) Range() hcl.Range {
}

func (b *Block) DefRange() hcl.Range {
return hcl.RangeBetween(b.TypeRange, b.OpenBraceRange)
lastHeaderRange := b.TypeRange
if len(b.LabelRanges) > 0 {
lastHeaderRange = b.LabelRanges[len(b.LabelRanges)-1]
}
return hcl.RangeBetween(b.TypeRange, lastHeaderRange)
}

0 comments on commit e84201c

Please sign in to comment.