Repository navigation
fix(high): keep document order of $ref'd path items and callbacks - #739
pcbeingused33 wants to merge 2 commits into
Conversation
Paths and Callback sorted their entries by the line of the value node. For a $ref'd item that is a line in the referenced file, so bundled and rendered output moved those entries around. Sort by the line of the key instead.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
daveshanley
left a comment
There was a problem hiding this comment.
Thanks for the regression test. I confirmed the bundle now keeps the path order from #733. I found three other cases where rendering changes the order.
| for lk := range p.low.PathItems.KeysFromOldest() { | ||
| if lk.Value == k { | ||
| // the key lives in this document, a $ref'd value may not. | ||
| ln = lk.KeyNode.Line |
There was a problem hiding this comment.
Keys can share a line in JSON or flow-style YAML. With an x-note extension followed by 16 $ref paths on one line, /p08 renders before /p00. Could we walk the parsed mapping in key order, including its extensions?
| for lk := range c.low.Expression.KeysFromOldest() { | ||
| if lk.Value == k { | ||
| // the key lives in this document, a $ref'd value may not. | ||
| ln = lk.KeyNode.Line |
There was a problem hiding this comment.
A callback expression inherited through << keeps its anchor’s line. If the anchor is above the callback, the inherited expression renders before the explicit one. c.low.RootNode.Content already has them in the expected order.
| for lk := range p.low.PathItems.KeysFromOldest() { | ||
| if lk.Value == k { | ||
| // the key lives in this document, a $ref'd value may not. | ||
| ln = lk.KeyNode.Line |
There was a problem hiding this comment.
If an existing $ref path is declared after line 9,999, a path added with PathItems.Set renders ahead of it because the new path gets the fallback 9999. Could we append new paths and callback expressions in insertion order after the parsed entries?
|
Thanks for finding these cases. Paths and callbacks now follow the parsed mapping order, including extensions and inherited expressions. Entries added with This comment was drafted with Claude Code. |
Fixes #733
Rendering paths and callbacks by source line can reorder keys that share a line or come from a YAML merge. Using line 9999 for new entries can also put them ahead of existing entries in long documents.
Walk the parsed mapping in key order, including extensions and merged expressions. Append new paths and callback expressions in insertion order. Apply the same ordering to standard and inline rendering.
The regression tests cover a flow-style mapping with an extension and 16 referenced paths, a callback with an inherited expression, and appending after a referenced path declared beyond line 9999. The composed bundle test also verifies the original cross-file reference case.
This change was prepared with the help of an AI coding assistant.