linrongbin16 / fzfx.nvim

A Neovim fuzzy finder that updates on every keystroke.
https://linrongbin16.github.io/fzfx.nvim/
MIT License
110 stars 4 forks source link

Bug: attempt to read non-existing file #734

Closed savchenko closed 3 days ago

savchenko commented 4 days ago

Steps to reproduce

  1. Create a new buffer: :edit foo.bar, do not save it
  2. Execute <cmd>FzfxBuffers<cr>
  3. Observe the following:
Error executing luv callback:
...al/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/fileio.lua:208: failed to complete open(r) file "new.py": "ENOENT: no such file or directory: new.py"                                          
stack traceback:                                                                                                                                                                                
        [C]: in function 'error'                                                                                                                                                                
        ...al/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/fileio.lua:208: in function <...al/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/fileio.lua:206>

Additional information

:ls output:

:ls 
  1  h   "some/path/__init__.py"        line 26                                                                                                                                                 
  6  a   "another/path/file.py"         line 169                                                                                                                                                
  7 %a + "new.py"                       line 58                                                                                                                                                 
 10 #h   "../null/__init__.py"          line 20
linrongbin16 commented 3 days ago

Thanks for report.

The two possible fixes are:

  1. Ignore the unsaved new.py (or foo.bar) buffer in FzfxBuffers providers. i.e. it never shows up in left side of fzf. But somehow I feel like it's not compatible with Neovim's behavior, because it's indeed a buffer, just not been saved to file system.
  2. Since the buffer is not been saved to file system, so previewer cannot find a corresponding file and read the text contents. So for invalid filename or failed to opened files, simply treat them as empty text contents.

In PR #735 , I choose the 2nd solution, which looks good to me. And also this behavior is compatible with fzf's builtin preview window when working with bat.

linrongbin16 commented 3 days ago

hi @savchenko , #735 is merged into main branch, pull and try!

savchenko commented 1 day ago

@linrongbin16, confirmed working in https://github.com/linrongbin16/fzfx.nvim/commit/fed10de1242ff0e8c671eb9cca93c6283428fe12. Thanks!