fix(nvim): keep End path shortening on a char boundary - #860
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe ChangesPath shortening
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to End-strategy path shortening now preserves UTF-8 character boundaries, preventing crashes for non-ASCII paths while retaining ASCII behavior. The change is ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
The crash
With
layout.path_shorten_strategy = 'end', rendering a result whose directorycolumn has to be cut inside its first path component panics the Rust module when
that component is not ASCII:
shorten_pathreaches it whenevercomponents[0].len() > max_size— the pickerwindow is narrow, or the filename is long, since
path_max_widthinrenderer.luaismax_width - strdisplaywidth(filename) - 1.Root cause
PathShortenStrategy::Endis the one place in the file that cuts a componentwith
String::truncate, which takes a byte length and panics off a charboundary:
Every other cut in this module goes through
Self::truncate_str/Self::truncate_str_keep_end, which count chars. The single-component brancha few lines up in the same function already calls
Self::truncate_str(components[0], max_size)for exactly this situation — the multi-component branch was missed.
Chars are also the right unit here:
max_sizearrives fromlua/fff/picker_ui/renderer.luaas astrdisplaywidth-derived column budget,not a byte count.
The fix
Use the existing helper, matching the sibling branch.
Verification (Windows, default
ripgrepfeatures)RUSTUP_TOOLCHAINwas pinned to1.98.0-x86_64-pc-windows-msvcbecauserust-toolchain.toml'sstablechannel could not update on this machine.New test
end_strategy_truncates_multibyte_first_component_on_char_boundaryfeeds
документы/файл.txt(9 chars / 18 bytes in the first component) withmax_size = 15, which lands inside a character.Before,
cargo test -p fff-nvim --lib -- path_shortening:After:
The same test pins the ASCII behaviour that must not change —
core_workflow_service/db/modelatmax_size = 15still yields exactlycore_workflow_s— and it passes both before and after, as does the existingtest_path_shroten_strategy_end. For ASCII the two helpers are identical, sonothing widens.
cargo test -p fff-nvim --lib— 9 passed, 0 failed.cargo fmt --all -- --check— clean.cargo clippy -p fff-nvim --lib— no new warnings.Summary by CodeRabbit