terraform-provider-gitea/vendor/github.com/hashicorp/hcl/v2/hclsyntax/navigation.go
dependabot[bot] 84c9110a24
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.24.1 to 2.26.0
Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.24.1 to 2.26.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.24.1...v2.26.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-20 20:25:53 +00:00

63 lines
1.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package hclsyntax
import (
"bytes"
"fmt"
"github.com/hashicorp/hcl/v2"
)
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()
}