summaryrefslogtreecommitdiff
path: root/hclsyntax
diff options
context:
space:
mode:
authorRadek Simko <radek.simko@gmail.com>2021-09-22 17:10:05 +0100
committerGitHub <noreply@github.com>2021-09-22 17:10:05 +0100
commite84201c45df4fce4e9dfaba9e8aaa8730d24dd25 (patch)
tree7b9350b1bf05f57397f4b591ebe37b114a940ef2 /hclsyntax
parentc5b722996dd572ea9330f9615d591bedfb7366b1 (diff)
parent1085e8de8e71da839c0b5d19625c350a353f375d (diff)
Merge pull request #487 from hashicorp/align-def-range
Align `hcl.Block` & `hclsyntax.Block` `DefRange`
Diffstat (limited to 'hclsyntax')
-rw-r--r--hclsyntax/navigation_test.go12
-rw-r--r--hclsyntax/structure.go13
2 files changed, 12 insertions, 13 deletions
diff --git a/hclsyntax/navigation_test.go b/hclsyntax/navigation_test.go
index f91c077..221f1b4 100644
--- a/hclsyntax/navigation_test.go
+++ b/hclsyntax/navigation_test.go
@@ -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{}},
}
diff --git a/hclsyntax/structure.go b/hclsyntax/structure.go
index 4526907..f42ae91 100644
--- a/hclsyntax/structure.go
+++ b/hclsyntax/structure.go
@@ -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,
}
@@ -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)
}