Share indexed fallback locations during effective projection

This commit is contained in:
2026-10-24 14:13:52 +00:00
parent 5c5f2af6cc
commit a0e5693d07
4 changed files with 114 additions and 13 deletions

View File

@@ -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) {