🐛 Keep a nested final-block foot comment at its indent on edit#215
Conversation
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a round-trip fidelity bug in the composer's trailing-comment attachment. Previously, all comments left after the AST walk were attached to the outermost (root) node's foot, which the emitter renders at column 0. For an unmodified document this was hidden by the verbatim source cache, but once the document was edited (forcing the AST re-emit path), a comment at the end of a nested final block would flatten to column 0 instead of keeping the block's indent. The fix introduces a bounded descent (foot_target) that routes each trailing comment to the deepest block collection it is indented into, so it re-emits at the correct indent. This is a follow-up to #213 (writable foot comments).
Changes:
- Added
foot_target/foot_target_innerto descend the last-child spine and attribute each trailing comment to the deepest block collection whose column is<=the comment's column. - Added
is_block_collectionhelper to identify non-empty block mappings/sequences that can carry a foot comment. - Added tests for the edit-keeps-indent case, nested read-back attribution, and multi-level trailing-comment routing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/roundtrip/composer.rs |
Routes trailing comments to the deepest indented block via a new bounded, stack-guarded descent instead of always the root node. |
tests/roundtrip/test_roundtrip.py |
Adds a test that an edited nested final-block foot comment keeps its indent. |
tests/roundtrip/test_node.py |
Adds tests that nested/multi-level trailing comments read back as the owning block's comment_after. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
==========================================
+ Coverage 92.62% 92.64% +0.01%
==========================================
Files 40 40
Lines 12155 12188 +33
==========================================
+ Hits 11259 11291 +32
- Misses 896 897 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
81080ea to
a830d98
Compare
Breaking change
None. Fixes a round-trip fidelity bug; no API change.
Proposed change
Fixes a foot-comment fidelity bug exposed while adding
comment_after(#213). A comment at the end of a nested final block round-trips byte-for-byte when untouched, but the moment the document is edited it re-emits at column 0 instead of the block's indent:The cause was in the composer: every trailing comment left after the walk was attached to the outermost (root) node's foot, which the emitter renders at indent 0. On the AST re-emit path (taken after an edit) the comment therefore detached from the block it belongs to.
The fix routes each trailing comment to the deepest block it is indented into, by descending the last-child spine while the child is a block collection no more indented than the comment. A comment aligned with a nested block's contents now lands on that block (and re-emits at its indent); a comment at the document's own indent still stays on the outermost node. Multi-level trailing comments each attach to their own level. The descent is bounded by the document's nesting depth and stack-guarded, consistent with the other composer walks.
Because unmodified documents re-emit their trailing comment verbatim (independent of which node owns it), this changes only the post-edit path: the full compliance suite and the entire real-world round-trip corpus stay byte-for-byte. New tests cover the edit-keeps-indent case, the nested read-back attribution, and multi-level routing.
Type of change
Additional information
Checklist
uv run pytestpasses locally. A pull request cannot be merged unless CI is green.uv run ruff check .anduv run ruff format --check .pass.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.If the change is user-facing:
docs/is added or updated, anddocs/verify_examples.pystill passes.