diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcled/navigation.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcled/navigation.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcled/navigation.go b/vendor/github.com/hashicorp/hcl2/hcled/navigation.go new file mode 100644 index 0000000..5d10cd8 --- /dev/null +++ b/vendor/github.com/hashicorp/hcl2/hcled/navigation.go | |||
@@ -0,0 +1,34 @@ | |||
1 | package hcled | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/hcl2/hcl" | ||
5 | ) | ||
6 | |||
7 | type contextStringer interface { | ||
8 | ContextString(offset int) string | ||
9 | } | ||
10 | |||
11 | // ContextString returns a string describing the context of the given byte | ||
12 | // offset, if available. An empty string is returned if no such information | ||
13 | // is available, or otherwise the returned string is in a form that depends | ||
14 | // on the language used to write the referenced file. | ||
15 | func ContextString(file *hcl.File, offset int) string { | ||
16 | if cser, ok := file.Nav.(contextStringer); ok { | ||
17 | return cser.ContextString(offset) | ||
18 | } | ||
19 | return "" | ||
20 | } | ||
21 | |||
22 | type contextDefRanger interface { | ||
23 | ContextDefRange(offset int) hcl.Range | ||
24 | } | ||
25 | |||
26 | func ContextDefRange(file *hcl.File, offset int) hcl.Range { | ||
27 | if cser, ok := file.Nav.(contextDefRanger); ok { | ||
28 | defRange := cser.ContextDefRange(offset) | ||
29 | if !defRange.Empty() { | ||
30 | return defRange | ||
31 | } | ||
32 | } | ||
33 | return file.Body.MissingItemRange() | ||
34 | } | ||