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

@@ -171,16 +171,23 @@ func documentWithMetadataLocations(root *document.Node, metadata Metadata, fallb
if len(fallback) != 0 {
fallbackRoot = fallback[0]
}
var lookup *documentLookup
fallbackLocation := func(path Path) (document.Location, bool) {
if lookup == nil {
lookup = buildDocumentLookup(fallbackRoot)
}
return nearestDocumentLocationWithLookup(fallbackRoot, path, lookup)
}
var visit func(*document.Node, Path)
visit = func(node *document.Node, path Path) {
pointer := path.String()
if info, exists := metadata.fields[pointer]; exists {
if location, ok := metadataFieldLocation(metadata, pointer, info.Origin); ok {
node.Location = location
} else if location, ok := nearestDocumentLocation(fallbackRoot, path); ok {
} else if location, ok := fallbackLocation(path); ok {
node.Location = location
}
} else if location, ok := nearestDocumentLocation(fallbackRoot, path); ok {
} else if location, ok := fallbackLocation(path); ok {
node.Location = location
}
switch node.Kind {
@@ -192,11 +199,11 @@ func documentWithMetadataLocations(root *document.Node, metadata Metadata, fallb
if location, ok := metadataFieldLocation(metadata, childPath.String(), info.Origin); ok {
entry.KeyLocation = location
entry.ValueLocation = location
} else if location, ok := nearestDocumentLocation(fallbackRoot, childPath); ok {
} else if location, ok := fallbackLocation(childPath); ok {
entry.KeyLocation = location
entry.ValueLocation = location
}
} else if location, ok := nearestDocumentLocation(fallbackRoot, childPath); ok {
} else if location, ok := fallbackLocation(childPath); ok {
entry.KeyLocation = location
entry.ValueLocation = location
}