diff options
author | appilon <apilon@hashicorp.com> | 2019-02-27 16:43:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 16:43:31 -0500 |
commit | 844b5a68d8af4791755b8f0ad293cc99f5959183 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go | |
parent | 303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff) | |
parent | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff) | |
download | terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip |
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go | 41 |
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 @@ | |||
1 | package hclsyntax | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "fmt" | ||
6 | ) | ||
7 | |||
8 | type navigation struct { | ||
9 | root *Body | ||
10 | } | ||
11 | |||
12 | // Implementation of hcled.ContextString | ||
13 | func (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 | } | ||