2017-09-11 23:00:31 +00:00
|
|
|
package hcled
|
2017-05-20 01:56:39 +00:00
|
|
|
|
|
|
|
import (
|
2019-09-09 23:08:19 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2017-05-20 01:56:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2017-09-11 23:40:37 +00:00
|
|
|
func ContextString(file *hcl.File, offset int) string {
|
2017-05-20 01:56:39 +00:00
|
|
|
if cser, ok := file.Nav.(contextStringer); ok {
|
|
|
|
return cser.ContextString(offset)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2018-11-26 23:35:46 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|