aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go')
-rw-r--r--vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go
new file mode 100644
index 0000000..4d41b6b
--- /dev/null
+++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go
@@ -0,0 +1,41 @@
1package hclsyntax
2
3import (
4 "bytes"
5 "fmt"
6)
7
8type navigation struct {
9 root *Body
10}
11
12// Implementation of hcled.ContextString
13func (n navigation) ContextString(offset int) string {
14 // We will walk our top-level blocks until we find one that contains
15 // the given offset, and then construct a representation of the header
16 // of the block.
17
18 var block *Block
19 for _, candidate := range n.root.Blocks {
20 if candidate.Range().ContainsOffset(offset) {
21 block = candidate
22 break
23 }
24 }
25
26 if block == nil {
27 return ""
28 }
29
30 if len(block.Labels) == 0 {
31 // Easy case!
32 return block.Type
33 }
34
35 buf := &bytes.Buffer{}
36 buf.WriteString(block.Type)
37 for _, label := range block.Labels {
38 fmt.Fprintf(buf, " %q", label)
39 }
40 return buf.String()
41}