File: navigation.go

package info (click to toggle)
golang-github-hashicorp-hcl-v2 2.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 3,120 kB
  • sloc: ruby: 205; makefile: 72; python: 43; sh: 11
file content (34 lines) | stat: -rw-r--r-- 887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package hcled

import (
	"github.com/hashicorp/hcl/v2"
)

type contextStringer interface {
	ContextString(offset int) string
}

// ContextString returns a string describing the context of the given byte
// offset, if available. An empty string is returned if no such information
// is available, or otherwise the returned string is in a form that depends
// on the language used to write the referenced file.
func ContextString(file *hcl.File, offset int) string {
	if cser, ok := file.Nav.(contextStringer); ok {
		return cser.ContextString(offset)
	}
	return ""
}

type contextDefRanger interface {
	ContextDefRange(offset int) hcl.Range
}

func ContextDefRange(file *hcl.File, offset int) hcl.Range {
	if cser, ok := file.Nav.(contextDefRanger); ok {
		defRange := cser.ContextDefRange(offset)
		if !defRange.Empty() {
			return defRange
		}
	}
	return file.Body.MissingItemRange()
}