Repository navigation
fix(picker_ui): don't :edit the current buffer on select (E37 on modified file) - #907
Conversation
Selecting the file that is already open in the current window ran `:edit <path>`, which reloads the buffer from disk and fails with E37 when it has unsaved changes. The error aborted the select callback, so the jump to a `file:line` location never happened. Skip `:edit` when the selected path resolves to the current buffer. Identity is checked with bufadd(), which matches names the same way `:edit` does, so a symlink to the current file is handled too.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe picker’s ChangesEdit action
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The picker preserves unsaved edits when the current file is selected again, including through a symlink alias. No actionable merge-blocking issue remains. 🚥 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 |
…enko#907) Selecting the file that is already open in the current window ran `:edit <path>`, which reloads the buffer from disk and fails with E37 when it has unsaved changes. The error aborted the select callback, so the jump to a `file:line` location never happened. Skip `:edit` when the selected path resolves to the current buffer. Identity is checked with bufadd(), which matches names the same way `:edit` does, so a symlink to the current file is handled too.
Problem
Selecting the file that is already open in the current window fails when its
buffer has unsaved changes:
The error aborts the rest of the
vim.schedulecallback, so for afile:linequery the jump to the location never happens. Selecting any other file from a
modified buffer works.
Reproduction
foo.txtand change it without saving.:lua require('fff').find_files(), typefoo.txt:3.foo.txt(marked(current)).Expected: the picker closes, unsaved changes are kept, the cursor is on line 3.
Actual: E37, the cursor stays where it was.
Reproduced with
nvim --clean(Neovim 0.12.5, Linux) on currentmain(c188e7a).Cause
The
editaction always runs:edit <path>(picker_ui.lua:547). When<path>is the file of the current buffer,
:editmeans "reload from disk", which Neovimrefuses for a modified buffer with E37 regardless of 'hidden':
Fix
Skip
:editwhen the selected path resolves to the current buffer; only thelocation jump runs. Buffer identity is checked with
vim.fn.bufadd(path), whichresolves names the same way
:editdoes. A plain path comparison(
fnamemodify(path, ':p') == nvim_buf_get_name(0)) is not enough: selecting asymlink to the current file still hits E37.
Summary by CodeRabbit