nvimdev / lspsaga.nvim

improve neovim lsp experience
MIT License
3.47k stars 288 forks source link

Error when buffer is closed #1280

Closed sudopseudocode closed 1 year ago

sudopseudocode commented 1 year ago

Describe the bug

When using nvim-tree's ability to delete a file, it's logic appears to force close the buffer of that corresponding file (if open). When this file is the current buffer open with lspsaga enabled, I can consistently see an error which traces back to lspsaga's lightbulb.lua file.

Here is the error trace:

...testfile.lua was properly removed.                                
Error executing vim.schedule lua callback: ...r/neovim/0.9.1/share/nvim/runtime/lua/vim/diagnostic.lua:55: Invalid buffer id: 10                 
stack traceback:                                                                                                                                 
        [C]: in function 'nvim_create_autocmd'                                                                                                   
        ...r/neovim/0.9.1/share/nvim/runtime/lua/vim/diagnostic.lua:55: in function '__index'                                                    
        ...r/neovim/0.9.1/share/nvim/runtime/lua/vim/diagnostic.lua:434: in function 'get'                                                       
        ...ovim/0.9.1/share/nvim/runtime/lua/vim/lsp/diagnostic.lua:294: in function 'get_line_diagnostics'                                      
        ...er/opt/lspsaga.nvim/lua/lspsaga/codeaction/lightbulb.lua:59: in function 'render'                                                     
        ...er/opt/lspsaga.nvim/lua/lspsaga/codeaction/lightbulb.lua:83: in function <...er/opt/lspsaga.nvim/lua/lspsaga/codeaction/lightbulb.lua:
82> 

To be clear, this bug comes up when using in conjunction with nvim-tree, however, I believe this specific case illustrates the need for a fix in the corresponding lines in lightbulb.lua. On line 82, it looks like it calls vim.schedule with render(buf). This render function (or the logic in the vim.schedule call) probably needs some logic to check whether the buffer is still valid.

Steps to reproduce

Use nvim-tree plugin & lspsaga

  1. Create a new file & type some sample code
  2. Open nvim-tree and press "d" to delete the file currently open
  3. Witness error traced back to lspsaga's lightbulb.lua file

Expected behavior

There should be no error. Lspsaga logic should exit gracefully.

Neovim version (nvim -v)

NVIM v0.9.1

lspsaga commit

3519a20 diagnostic show fix #1279

Terminal name/version

zsh 5.9

sudopseudocode commented 1 year ago

Wow, fast work. Thank you!