nvim-lua / lsp-status.nvim

Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
MIT License
625 stars 41 forks source link

Diagnostic callback #10

Closed Shatur closed 4 years ago

Shatur commented 4 years ago

Thank for the awesome plugin!

I have a question. There is diagnostics() function that allows to get information about errors, warnings, hints, etc. Is there a way to get a callback when the diagnostics changes? For example, in lightline.vim I need to have a callback to display custom section by calling call lightline#update().

wbthomason commented 4 years ago

Since lsp-status doesn't fetch new diagnostics itself (it just collects them using the built-in API), there's not a callback built in for this purpose. However, the native LSP client should trigger LspDiagnosticsChanged (see :help LspDiagnosticsChanged) when it receives new diagnostics; you can make an autocommand for this event to call your custom update code.

Feel free to reopen if that's not quite what you're after!

Shatur commented 4 years ago

Thank you a lot! autocmd User LspDiagnosticsChanged call lightline#update() is just what I need.

smartding commented 3 years ago

Thank you a lot! autocmd User LspDiagnosticsChanged call lightline#update() is just what I need.

@Shatur95, it seems LspDiagnosticsChanged event is not fired when the number of diagnostic information goes to 0 from non-zero. Is this true in your case?

Shatur commented 3 years ago

Sorry, do not Neovim as IDE right now, only as a text editor.

smartding commented 3 years ago

Since lsp-status doesn't fetch new diagnostics itself (it just collects them using the built-in API), there's not a callback built in for this purpose. However, the native LSP client should trigger LspDiagnosticsChanged (see :help LspDiagnosticsChanged) when it receives new diagnostics; you can make an autocommand for this event to call your custom update code.

Feel free to reopen if that's not quite what you're after!

@wbthomason I added the following autocmd to my vimrc for testing purpose:

autocmd User LspDiagnosticsChanged :echom "diagnostic changed"

it seems LspDiagnosticsChanged is not triggered when number of diagnostics goes to zero. So my status line shows a non-zero number of diagnostics when it's actually zero. How do I fix this?

wbthomason commented 3 years ago

@smartding: Unfortunately, that sounds like an issue to report to core Neovim - lsp-status does not generate the LspDiagnosticsChanged event, so I can't directly debug this issue.

smartding commented 3 years ago

@smartding: Unfortunately, that sounds like an issue to report to core Neovim - lsp-status does not generate the LspDiagnosticsChanged event, so I can't directly debug this issue.

ok, thanks, I'll ask the neovim guys

lucax88x commented 3 years ago

@smartding I did it for you, having the same issue.

smartding commented 3 years ago

@smartding I did it for you, having the same issue.

oh, thanks. they have a really long issue template, never had the time to fill it out:)

smartding commented 3 years ago

LspDiagnosticsChanged is finally working now that https://github.com/neovim/neovim/pull/13483 is merged