mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-19 17:50:00 +00:00
961c878e0d
Switch to using Go modules. This migrates our vendor.json to use Go 1.11's modules system, and replaces the vendor folder with the output of go mod vendor. The vendored code should remain basically the same; I believe some tree shaking of packages and support scripts/licenses/READMEs/etc. happened. This also fixes Travis and our Makefile to no longer use govendor.
60 lines
1.0 KiB
Go
60 lines
1.0 KiB
Go
package hclsyntax
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/hcl2/hcl"
|
|
)
|
|
|
|
type navigation struct {
|
|
root *Body
|
|
}
|
|
|
|
// Implementation of hcled.ContextString
|
|
func (n navigation) ContextString(offset int) string {
|
|
// We will walk our top-level blocks until we find one that contains
|
|
// the given offset, and then construct a representation of the header
|
|
// of the block.
|
|
|
|
var block *Block
|
|
for _, candidate := range n.root.Blocks {
|
|
if candidate.Range().ContainsOffset(offset) {
|
|
block = candidate
|
|
break
|
|
}
|
|
}
|
|
|
|
if block == nil {
|
|
return ""
|
|
}
|
|
|
|
if len(block.Labels) == 0 {
|
|
// Easy case!
|
|
return block.Type
|
|
}
|
|
|
|
buf := &bytes.Buffer{}
|
|
buf.WriteString(block.Type)
|
|
for _, label := range block.Labels {
|
|
fmt.Fprintf(buf, " %q", label)
|
|
}
|
|
return buf.String()
|
|
}
|
|
|
|
func (n navigation) ContextDefRange(offset int) hcl.Range {
|
|
var block *Block
|
|
for _, candidate := range n.root.Blocks {
|
|
if candidate.Range().ContainsOffset(offset) {
|
|
block = candidate
|
|
break
|
|
}
|
|
}
|
|
|
|
if block == nil {
|
|
return hcl.Range{}
|
|
}
|
|
|
|
return block.DefRange()
|
|
}
|