SmiteshP / nvim-navic

Simple winbar/statusline plugin that shows your current code context
Apache License 2.0
1.35k stars 49 forks source link

Invalid buffer ID when navigating with Lspsaga #124

Closed MariaSolOs closed 12 months ago

MariaSolOs commented 12 months ago

Hello! I just installed this plugin but I'm getting the following errors when navigating through diagnostics with Lspsaga (this happens after using Lspsaga diagnostic_jump_prev/next):

Screenshot 2023-07-04 at 2 43 16 PM

Any help is appreciated 🙏🏻

SmiteshP commented 12 months ago

Why is the error message appearing in floating window? Is lspsaga creating it?

MariaSolOs commented 12 months ago

No, the error is coming from Noice.

Anyway, I found the issue after debugging for a while. Turns out that Lspsaga creates a buffer for displaying diagnostics that has a filetype of 'markdown'. That wakes up the Markdown language server, and my attach callback then attaches that server to that unnamed markdown buffer that's displaying the diagnostics. When navigating through the diagnostic windows, those buffers are closed and then navic freaks out because there's a client that's not attached to the current buffer...

Modifying my attach callback to have the following check fixes the issue, although I'm unsure if it's the right fix.

if buf_client.server_capabilities.documentSymbolProvider and vim.api.nvim_buf_get_name(bufnr) ~= '' then
  require('nvim-navic').attach(buf_client, bufnr)
end
SmiteshP commented 12 months ago

Oh ok! I see what is happening. nvim-navic is trying to poll the lsp server, but since the buffer is closed before the lsp server has a chance to respond, it is causing the error. The modification to the attach function isn't the right fix. Can you try out the request_loop_fix branch and tell me if the error is fixed for you?

MariaSolOs commented 12 months ago

@SmiteshP It fixed it!

SmiteshP commented 12 months ago

Awesome 🚀