fzf-lua
fzf-lua copied to clipboard
neovim swap file warning repeated by `FzfLua files`
Info
-
Operating System: ArchLinux
-
Shell: bash
-
Terminal: alacritty
-
nvim --version
: NVIM v0.9.5, Build type: Release, LuaJIT 2.1.1702233742 -
fzf --version
: 0.45.0 (20240101) -
[x] The issue is reproducible with
mini.sh
Description
Steps:
- open a file in a neovim instance
- open the same file with another instance via
:FzfLua files
Expected:
Shows the classic vim warning "Found a swap file by the name..." and opens the file after user choice
Warning text
Found a swap file by the name "~/.local/state/nvim/swap//...gitignore.swp"
owned by: ...
file name: ...
modified: no
user name: ...
process ID: ...
While opening file "./.gitignore"
dated: ...
(1) Another program may be editing the same file. If this is the case,
be careful not to end up with two different instances of the same
file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r ./.gitignore"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "...//...gitignore.swp"
to avoid this message.
Swap file "~/.local/state/nvim/swap//...%.gitignore.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:
Actual:
The vim warning is shown and waits for user interaction (good) and fzf-lua displays an additional error that needs to be skipped (annoying)
fzf-lua error
[Fzf-lua] fn_selected threw an error: vim/_editor.lua:0: nvim_exec2(): Vim(edit):E325: ATTENTION
stack traceback:
^I...nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/core.lua:170: in function <...nvim/site/pack/vendor/start/fzf-lua/
lua/fzf-lua/core.lua:169>
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I...m/site/pack/vendor/start/fzf-lua/lua/fzf-lua/actions.lua:136: in function 'vimcmd_file'
^I...m/site/pack/vendor/start/fzf-lua/lua/fzf-lua/actions.lua:162: in function 'action'
^I...m/site/pack/vendor/start/fzf-lua/lua/fzf-lua/actions.lua:72: in function 'act'
^I...nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/core.lua:94: in function 'fn_selected'
^I...nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/core.lua:168: in function <...nvim/site/pack/vendor/start/fzf-lua/
lua/fzf-lua/core.lua:167>
^I[C]: in function 'xpcall'
^I...nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/core.lua:167: in function <...nvim/site/pack/vendor/start/fzf-lua/
lua/fzf-lua/core.lua:161>
Press ENTER or type command to continue
The problem seems to be the xpcall at https://github.com/ibhagwan/fzf-lua/blob/36195a230246fc44e8144ee0b454fc022ac5326b/lua/fzf-lua/core.lua#L165, maybe we can filter out the error?
xpcall(function()
opts.fn_selected(selected, opts)
end, function(err)
if string.find(err, 'Vim(edit):E325', 1, true) then
return
end
utils.err("fn_selected threw an error: " .. debug.traceback(err, 1))
end)
Or there might be a cleaner way..?
Or there might be a cleaner way..?
I’ll think about it, not sure if there is a cleaner way.
Also, when selecting Abort, the error is actually Keyboard Interrupt
. For this use case, Quit has the same effect without the interrupt error though.
[Fzf-lua] fn_selected threw an error: vim/_editor.lua:0: Keyboard interrupt
stack traceback:
^I...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:174: in function <...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:169>
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I...vim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/actions.lua:136: in function 'vimcmd_file'
^I...vim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/actions.lua:162: in function 'action'
^I...vim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/actions.lua:72: in function 'act'
^I...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:94: in function 'fn_selected'
^I...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:168: in function <...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:167>
^I[C]: in function 'xpcall'
^I...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:167: in function <...e/nvim/site/pack/paqs/start/fzf-lua/lua/fzf-lua/core.lua:161>
Perhaps a better solution would be to check if a swap file exists and vim.schedule
the buffer edit command (outside of the fzf-lua coroutine), that might solve it without complex gymnastics and error filtering.
https://github.com/ibhagwan/fzf-lua/commit/82457207eff56f31a995917fed09df5dad1f2751
@lbonn, the other "more elegant" solutions turn out to be much more code and more room for error :-)
You purposed solution is probably best here.
Great, thank you :)