diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2020-10-25 19:27:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 14:27:11 -0400 |
commit | 7fef16e1d6c106af57039c0620d77db917b12078 (patch) | |
tree | 8247cbc9151bd31c6992704be694145a75bb43e8 /runtime/lua/vim/lsp/callbacks.lua | |
parent | c984a888b8249b9f0e92b2949f02b3816a5e6e3e (diff) | |
download | rneovim-7fef16e1d6c106af57039c0620d77db917b12078.tar.gz rneovim-7fef16e1d6c106af57039c0620d77db917b12078.tar.bz2 rneovim-7fef16e1d6c106af57039c0620d77db917b12078.zip |
lsp: Store diagnostics for unloaded buffers (#13102)
To avoid loading buffers https://github.com/neovim/neovim/pull/12440
changed the logic to not process diagnostics for unloaded buffers.
This is problematic for language servers where compile errors or build
errors are reported via diagnostics. These errors may prevent the
language server from providing all functions and it is difficult for
users to debug it without having access to the errors.
For example, with eclipse.jdt.ls there may be a problem with gradle (the
build tool for java), it results in a diagnostics like this:
org.gradle.toolingapi/build.gradle|1 col 1| Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.8.1-bin.zip'.
This would be invisible to users unless the user happens to open the
right file. In this case the user would actually never see the error,
because the language server isn't attached to the build configuration
files.
This changes the behaviour to at least store the diagnostics. The other
operations which are more expensive are still skipped.
Diffstat (limited to 'runtime/lua/vim/lsp/callbacks.lua')
-rw-r--r-- | runtime/lua/vim/lsp/callbacks.lua | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua index 4e7a8333a0..3270d1d2a9 100644 --- a/runtime/lua/vim/lsp/callbacks.lua +++ b/runtime/lua/vim/lsp/callbacks.lua @@ -82,18 +82,6 @@ M['textDocument/publishDiagnostics'] = function(_, _, result) return end - -- Unloaded buffers should not handle diagnostics. - -- When the buffer is loaded, we'll call on_attach, which sends textDocument/didOpen. - -- This should trigger another publish of the diagnostics. - -- - -- In particular, this stops a ton of spam when first starting a server for current - -- unloaded buffers. - if not api.nvim_buf_is_loaded(bufnr) then - return - end - - util.buf_clear_diagnostics(bufnr) - -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#diagnostic -- The diagnostic's severity. Can be omitted. If omitted it is up to the -- client to interpret diagnostics as error, warning, info or hint. @@ -104,7 +92,23 @@ M['textDocument/publishDiagnostics'] = function(_, _, result) end end + util.buf_clear_diagnostics(bufnr) + + -- Always save the diagnostics, even if the buf is not loaded. + -- Language servers may report compile or build errors via diagnostics + -- Users should be able to find these, even if they're in files which + -- are not loaded. util.buf_diagnostics_save_positions(bufnr, result.diagnostics) + + -- Unloaded buffers should not handle diagnostics. + -- When the buffer is loaded, we'll call on_attach, which sends textDocument/didOpen. + -- This should trigger another publish of the diagnostics. + -- + -- In particular, this stops a ton of spam when first starting a server for current + -- unloaded buffers. + if not api.nvim_buf_is_loaded(bufnr) then + return + end util.buf_diagnostics_underline(bufnr, result.diagnostics) util.buf_diagnostics_virtual_text(bufnr, result.diagnostics) util.buf_diagnostics_signs(bufnr, result.diagnostics) |