aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/diagnostic.lua
diff options
context:
space:
mode:
authorChris AtLee <chris.atlee@shopify.com>2023-08-31 04:00:24 -0400
committerGitHub <noreply@github.com>2023-08-31 10:00:24 +0200
commitc235959fd909d75248c066a781475e207606c5aa (patch)
tree340f439aa9c6cc533cc33e14439acc473662c35e /runtime/lua/vim/lsp/diagnostic.lua
parentee56daebb6468075e743db0d605cb3f2a1699419 (diff)
downloadrneovim-c235959fd909d75248c066a781475e207606c5aa.tar.gz
rneovim-c235959fd909d75248c066a781475e207606c5aa.tar.bz2
rneovim-c235959fd909d75248c066a781475e207606c5aa.zip
fix(lsp): only disable inlay hints / diagnostics if no other clients are connected (#24535)
This fixes the issue where the LspNotify handlers for inlay_hint / diagnostics would end up refreshing all attached clients. The handler would call util._refresh, which called vim.lsp.buf_request, which calls the method on all attached clients. Now util._refresh takes an optional client_id parameter, which is used to specify a specific client to update. This commit also fixes util._refresh's handling of the `only_visible` flag. Previously if `only_visible` was false, two requests would be made to the server: one for the visible region, and one for the entire file. Co-authored-by: Stanislav Asunkin <1353637+stasjok@users.noreply.github.com> Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Diffstat (limited to 'runtime/lua/vim/lsp/diagnostic.lua')
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua26
1 files changed, 22 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index a0568bc09c..2a77992c4d 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -408,6 +408,16 @@ local function disable(bufnr)
clear(bufnr)
end
+--- Refresh diagnostics, only if we have attached clients that support it
+---@param bufnr (integer) buffer number
+---@param opts? table Additional options to pass to util._refresh
+---@private
+local function _refresh(bufnr, opts)
+ opts = opts or {}
+ opts['bufnr'] = bufnr
+ util._refresh(ms.textDocument_diagnostic, opts)
+end
+
--- Enable pull diagnostics for a buffer
---@param bufnr (integer) Buffer handle, or 0 for current
---@private
@@ -429,7 +439,7 @@ function M._enable(bufnr)
return
end
if bufstates[bufnr] and bufstates[bufnr].enabled then
- util._refresh(ms.textDocument_diagnostic, { bufnr = bufnr, only_visible = true })
+ _refresh(bufnr, { only_visible = true, client_id = opts.data.client_id })
end
end,
group = augroup,
@@ -438,7 +448,7 @@ function M._enable(bufnr)
api.nvim_buf_attach(bufnr, false, {
on_reload = function()
if bufstates[bufnr] and bufstates[bufnr].enabled then
- util._refresh(ms.textDocument_diagnostic, { bufnr = bufnr })
+ _refresh(bufnr)
end
end,
on_detach = function()
@@ -448,8 +458,16 @@ function M._enable(bufnr)
api.nvim_create_autocmd('LspDetach', {
buffer = bufnr,
- callback = function()
- disable(bufnr)
+ callback = function(args)
+ local clients = vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_diagnostic })
+
+ if
+ not vim.iter(clients):any(function(c)
+ return c.id ~= args.data.client_id
+ end)
+ then
+ disable(bufnr)
+ end
end,
group = augroup,
})