Skip to content

Commit 5ca12bc

Browse files
denikIsaac
andcommitted
GetLocationsOf on the location tree
Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 5065a17 commit 5ca12bc

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

‎bundle/config/root.go‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -565,34 +565,21 @@ func (r Root) GetLocations(path string) []diag.Location {
565565
if err != nil {
566566
return nil
567567
}
568-
return r.locations.Nearest(p)
569-
}
570-
571-
// GetLocationOf is [Root.GetLocation] for a path node.
572-
func (r Root) GetLocationOf(path *structpath.PathNode) diag.Location {
573-
v, ok := r.valueOf(path)
574-
if !ok {
575-
return diag.Location{}
576-
}
577-
return v.Location()
568+
return r.GetLocationsOf(p)
578569
}
579570

580571
// GetLocationsOf is [Root.GetLocations] for a path node.
581572
func (r Root) GetLocationsOf(path *structpath.PathNode) []diag.Location {
582-
v, ok := r.valueOf(path)
583-
if !ok {
584-
return nil
585-
}
586-
return v.Locations()
573+
return r.locations.Nearest(path)
587574
}
588575

589-
func (r Root) valueOf(path *structpath.PathNode) (dyn.Value, bool) {
590-
p, ok := dyn.FromStructPath(path)
591-
if !ok {
592-
return dyn.InvalidValue, false
576+
// GetLocationOf is [Root.GetLocation] for a path node.
577+
func (r Root) GetLocationOf(path *structpath.PathNode) diag.Location {
578+
locs := r.GetLocationsOf(path)
579+
if len(locs) == 0 {
580+
return diag.Location{}
593581
}
594-
v, err := dyn.GetByPath(r.value, p)
595-
return v, err == nil
582+
return locs[0]
596583
}
597584

598585
// DefinitionLocation returns the primary location the value at path is defined at,

0 commit comments

Comments
 (0)