aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go
diff options
context:
space:
mode:
authorAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
committerAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
commit15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go
parent07971ca38143c5faf951d152fba370ddcbe26ad5 (diff)
downloadterraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
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}