Share indexed fallback locations during effective projection
This commit is contained in:
@@ -124,6 +124,10 @@ func validationMutationDiagnostic(path Path) Diagnostic {
|
||||
}
|
||||
|
||||
func nearestDocumentLocation(root *document.Node, path Path) (document.Location, bool) {
|
||||
return nearestDocumentLocationWithLookup(root, path, nil)
|
||||
}
|
||||
|
||||
func nearestDocumentLocationWithLookup(root *document.Node, path Path, lookup *documentLookup) (document.Location, bool) {
|
||||
if root == nil || !path.valid() {
|
||||
return document.Location{}, false
|
||||
}
|
||||
@@ -135,18 +139,22 @@ func nearestDocumentLocation(root *document.Node, path Path) (document.Location,
|
||||
if segment.kind == pathSegmentIndex {
|
||||
return nearest, locationKnown(nearest)
|
||||
}
|
||||
found := false
|
||||
for _, entry := range current.Mapping {
|
||||
if entry.Key == segment.key {
|
||||
current = entry.Value
|
||||
nearest = current.Location
|
||||
found = true
|
||||
break
|
||||
position := -1
|
||||
if lookup != nil {
|
||||
position = lookup.find(current, segment.key)
|
||||
} else {
|
||||
for index, entry := range current.Mapping {
|
||||
if entry.Key == segment.key {
|
||||
position = index
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if position < 0 {
|
||||
return nearest, locationKnown(nearest)
|
||||
}
|
||||
current = current.Mapping[position].Value
|
||||
nearest = current.Location
|
||||
case document.Sequence:
|
||||
index, ok := schemaIndex(segment)
|
||||
if !ok || index >= len(current.Sequence) {
|
||||
|
||||
Reference in New Issue
Block a user