Project sequence origins from incoming to final item paths

This commit is contained in:
2026-10-23 23:51:33 +00:00
parent f8cbb2ed87
commit e6598810e0
5 changed files with 130 additions and 20 deletions

View File

@@ -340,7 +340,7 @@ func applyOverlaySequenceEvidence(
for _, projection := range combined.higherItems {
if higher != nil && higher.Kind == document.Sequence && projection.inputIndex >= 0 && projection.inputIndex < len(higher.Sequence) {
source := higher.Sequence[projection.inputIndex]
collectOverlayOriginsFrom(result.origins, incomingOrigins, source, path.Index(projection.outputIndex), layer)
collectOverlayOriginsAt(result.origins, incomingOrigins, source, path.Index(projection.inputIndex), path.Index(projection.outputIndex), layer)
}
}
if lower != nil {
@@ -366,7 +366,7 @@ func applyOverlaySequenceEvidence(
displaced := displacedOrigins(lowerItem, result.origins, lowerPath)
previous := cloneOrigin(result.origins[lowerPath.String()])
deleteOriginSubtree(result.origins, lowerPath, lowerItem)
collectOverlayOriginsFrom(result.origins, incomingOrigins, higherItem, outputPath, layer)
collectOverlayOriginsAt(result.origins, incomingOrigins, higherItem, higherPath, outputPath, layer)
result.overlays = append(result.overlays, overlayRecord{
change: Change{
Path: outputPath.clone(), Origin: incomingOrigin(incomingOrigins, higherPath, higherItem, layer),
@@ -378,7 +378,7 @@ func applyOverlaySequenceEvidence(
for _, projection := range combined.higherItems {
if higher != nil && higher.Kind == document.Sequence && projection.inputIndex >= 0 && projection.inputIndex < len(higher.Sequence) {
higherItem := higher.Sequence[projection.inputIndex]
collectOverlayOriginsFrom(result.origins, incomingOrigins, higherItem, path.Index(projection.outputIndex), layer)
collectOverlayOriginsAt(result.origins, incomingOrigins, higherItem, path.Index(projection.inputIndex), path.Index(projection.outputIndex), layer)
}
}
}
@@ -416,17 +416,15 @@ func collectOverlayOrigins(origins map[string]Origin, node *document.Node, path
}
func collectOverlayOriginsFrom(origins, incomingOrigins map[string]Origin, node *document.Node, path Path, layer Layer) {
origins[path.String()] = incomingOrigin(incomingOrigins, path, node, layer)
switch node.Kind {
case document.Mapping:
for _, entry := range node.Mapping {
collectOverlayOriginsFrom(origins, incomingOrigins, entry.Value, path.Key(entry.Key), layer)
}
case document.Sequence:
for index, child := range node.Sequence {
collectOverlayOriginsFrom(origins, incomingOrigins, child, path.Index(index), layer)
}
}
collectOverlayOriginsAt(origins, incomingOrigins, node, path, path, layer)
}
func collectOverlayOriginsAt(origins, incomingOrigins map[string]Origin, node *document.Node, from, to Path, layer Layer) {
walkDocument(node, Path{}, func(relative Path, value *document.Node) {
source := appendDestination(from, relative)
destination := appendDestination(to, relative)
origins[destination.String()] = incomingOrigin(incomingOrigins, source, value, layer)
})
}
func mergeOverlayOrigin(origins map[string]Origin, path Path, location document.Location, layer Layer) {