diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-09-05 10:27:52 -0700 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2021-09-26 10:25:17 -0700 |
commit | cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0 (patch) | |
tree | 980dbf25f4342e9cf4b616f6c242df3355963ec8 /runtime/lua/vim/lsp/diagnostic.lua | |
parent | f8e0011534a3f94cfd341fd9bfce1bcf9b1b7b73 (diff) | |
download | rneovim-cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0.tar.gz rneovim-cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0.tar.bz2 rneovim-cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0.zip |
feat(lsp)!: change handler signature #15504
Diffstat (limited to 'runtime/lua/vim/lsp/diagnostic.lua')
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index c83e29aa64..01a75d4094 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -1008,15 +1008,16 @@ end --- - Update diagnostics in InsertMode or wait until InsertLeave --- - severity_sort: (default=false) --- - Sort diagnostics (and thus signs and virtual text) -function M.on_publish_diagnostics(_, _, params, client_id, _, config) - local uri = params.uri +function M.on_publish_diagnostics(_, result, ctx, config) + local client_id = ctx.client_id + local uri = result.uri local bufnr = vim.uri_to_bufnr(uri) if not bufnr then return end - local diagnostics = params.diagnostics + local diagnostics = result.diagnostics if config and if_nil(config.severity_sort, false) then table.sort(diagnostics, function(a, b) return a.severity > b.severity end) @@ -1164,8 +1165,41 @@ function M.display(diagnostics, bufnr, client_id, config) save_extmarks(bufnr, client_id) end --- }}} --- Diagnostic User Functions {{{ +--- Redraw diagnostics for the given buffer and client +--- +--- This calls the "textDocument/publishDiagnostics" handler manually using +--- the cached diagnostics already received from the server. This can be useful +--- for redrawing diagnostics after making changes in diagnostics +--- configuration. |lsp-handler-configuration| +--- +---@param bufnr (optional, number): Buffer handle, defaults to current +---@param client_id (optional, number): Redraw diagnostics for the given +--- client. The default is to redraw diagnostics for all attached +--- clients. +function M.redraw(bufnr, client_id) + bufnr = get_bufnr(bufnr) + if not client_id then + return vim.lsp.for_each_buffer_client(bufnr, function(client) + M.redraw(bufnr, client.id) + end) + end + + -- We need to invoke the publishDiagnostics handler directly instead of just + -- calling M.display so that we can preserve any custom configuration options + -- the user may have set with vim.lsp.with. + vim.lsp.handlers["textDocument/publishDiagnostics"]( + nil, + { + uri = vim.uri_from_bufnr(bufnr), + diagnostics = M.get(bufnr, client_id), + }, + { + method = "textDocument/publishDiagnostics", + client_id = client_id, + bufnr = bufnr, + } + ) + end --- Open a floating window with the diagnostics from {line_nr} --- |