Skip to content

fix(nvim): keep End path shortening on a char boundary - #860

Open
kevin9327 wants to merge 1 commit into
dmtrKovalenko:mainfrom
kevin9327:fix/path-shorten-end-char-boundary
Open

fix(nvim): keep End path shortening on a char boundary#860
kevin9327 wants to merge 1 commit into
dmtrKovalenko:mainfrom
kevin9327:fix/path-shorten-end-char-boundary

Conversation

@kevin9327

@kevin9327 kevin9327 commented Sep 9, 2026

Copy link
Copy Markdown

The crash

With layout.path_shorten_strategy = 'end', rendering a result whose directory
column has to be cut inside its first path component panics the Rust module when
that component is not ASCII:

thread 'path_shortening::tests::end_strategy_truncates_multibyte_first_component_on_char_boundary' (38540) panicked at crates\fff-nvim\src\path_shortening.rs:189:35:
assertion failed: self.is_char_boundary(new_len)

shorten_path reaches it whenever components[0].len() > max_size — the picker
window is narrow, or the filename is long, since path_max_width in
renderer.lua is max_width - strdisplaywidth(filename) - 1.

Root cause

PathShortenStrategy::End is the one place in the file that cuts a component
with String::truncate, which takes a byte length and panics off a char
boundary:

let mut component = component.to_string();
component.truncate(max_size);

Every other cut in this module goes through Self::truncate_str /
Self::truncate_str_keep_end, which count chars. The single-component branch
a 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_size arrives from
lua/fff/picker_ui/renderer.lua as a strdisplaywidth-derived column budget,
not a byte count.

The fix

Use the existing helper, matching the sibling branch.

Verification (Windows, default ripgrep features)

RUSTUP_TOOLCHAIN was pinned to 1.98.0-x86_64-pc-windows-msvc because
rust-toolchain.toml's stable channel could not update on this machine.

New test end_strategy_truncates_multibyte_first_component_on_char_boundary
feeds документы/файл.txt (9 chars / 18 bytes in the first component) with
max_size = 15, which lands inside a character.

Before, cargo test -p fff-nvim --lib -- path_shortening:

running 9 tests

thread 'path_shortening::tests::end_strategy_truncates_multibyte_first_component_on_char_boundary' (38540) panicked at crates\fff-nvim\src\path_shortening.rs:189:35:
assertion failed: self.is_char_boundary(new_len)

test result: FAILED. 8 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

After:

test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The same test pins the ASCII behaviour that must not change —
core_workflow_service/db/model at max_size = 15 still yields exactly
core_workflow_s — and it passes both before and after, as does the existing
test_path_shroten_strategy_end. For ASCII the two helpers are identical, so
nothing 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

  • Bug Fixes
    • Improved path shortening for long paths containing multibyte UTF-8 characters.
    • Prevented characters from being split incorrectly during truncation.
    • Preserved existing behavior for ASCII-only paths.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ee41ed14-e3e5-4f7a-b5ca-fea9b6dcb949

📥 Commits

Reviewing files that changed from the base of the PR and between 7f8537e and e702152.

📒 Files selected for processing (1)
  • crates/fff-nvim/src/path_shortening.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The End path-shortening strategy now avoids splitting multibyte UTF-8 characters. A regression test covers multibyte and ASCII first components.

Changes

Path shortening

Layer / File(s) Summary
Character-aware truncation and regression test
crates/fff-nvim/src/path_shortening.rs
The End fallback uses Self::truncate_str. Tests verify character-boundary handling for "документы" and exact ASCII truncation.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to e7021

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main fix: End path shortening now preserves UTF-8 character boundaries.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant