Conversation
Replace the `panic!` path in `tui/src/wrapping.rs` with a recoverable flow. The mapper now skips synthetic leading characters, logs a warning on mid-line mismatch, and returns the mapped prefix range so wrapping continues instead of aborting. Add focused regression coverage for the recovery behavior. Tests now validate direct mismatch recovery and an end-to-end `wrap_ranges` case with non-space indents that forces owned wrapped lines and preserves round-trip source reconstruction.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated wrapping mapping to accept a synthetic prefix, strip it when mapping, and attempt partial recoverable mappings instead of panicking; mapping now tracks whether any source characters were seen and emits a tracing warning on partial recovery. Added tests for indentation and corner cases; function signature changed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Greptile SummaryReplaces a panic-on-mismatch in Key changes:
Confidence Score: 4/5
Important Files Changed
Last reviewed commit: c79eefc |
There was a problem hiding this comment.
Pull request overview
This PR replaces a panic in map_owned_wrapped_line_to_range with a graceful recovery mechanism that handles textwrap's synthetic indent prefixes. When textwrap produces owned wrapped lines with synthetic characters (e.g., from initial_indent/subsequent_indent options), the function now skips leading synthetic characters and returns partial source ranges with a warning instead of crashing the application.
Changes:
- Added
saw_source_charflag to track whether any source characters have been matched - Implemented logic to skip synthetic leading characters (e.g., indent prefixes) before matching source content
- Replaced panic with warning log and partial range return on mid-line mismatches
- Added two comprehensive tests: unit test for direct mismatch recovery and end-to-end test with non-space indents
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| continue; | ||
| } | ||
|
|
||
| tracing::warn!( |
There was a problem hiding this comment.
The tracing module is used but not imported. Add use tracing; or call the macro with the fully qualified path. Looking at the imports at the top of the file, there is no tracing import, which will cause a compilation error.
Update `map_owned_wrapped_line_to_range` to evaluate candidate starts in owned wrapped output and keep the longest source mapping. This avoids truncating ranges when synthetic indent prefixes share leading characters with source text. Add regression tests for the ambiguous prefix case and an end-to-end `wrap_ranges` reconstruction scenario so this edge case stays covered.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Pass the expected `initial_indent` or `subsequent_indent` into `map_owned_wrapped_line_to_range` and strip only that validated leading prefix before matching against source bytes. This avoids over-consuming source text when repeated prefix patterns appear in both indent and content. Add a focused regression test that reproduces the repeated `- ` pattern case on narrow widths and asserts the mapper does not over-advance.
Summary
panic!inmap_owned_wrapped_line_to_rangewith a recoverable flow that skips synthetic leading characters, logs a warning on mid-line mismatch, and returns the mapped prefix range instead of crashingtextwrapproduces owned lines with synthetic indent prefixes (e.g. non-space indents viainitial_indent/subsequent_indent)Test plan
map_owned_wrapped_line_to_range_recovers_on_non_prefix_mismatch)wrap_rangestest with non-space indents that forces owned wrapped lines and validates full source reconstructionwrapping.rstests (cargo test -p codex-tui)Summary by CodeRabbit
Bug Fixes
Tests