]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/navigation.go
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / hcl / hclsyntax / navigation.go
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 }