diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-02-19 19:05:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 22:05:49 -0500 |
commit | b2fcfc65b7181cfb519ce1f827cb62f1120de5a0 (patch) | |
tree | 40676433b960adc771892cc3b48ee92a55dc6216 /runtime/lua/vim/lsp.lua | |
parent | 4d5dbea4f402c76de4419977f7f89d3dec572510 (diff) | |
download | rneovim-b2fcfc65b7181cfb519ce1f827cb62f1120de5a0.tar.gz rneovim-b2fcfc65b7181cfb519ce1f827cb62f1120de5a0.tar.bz2 rneovim-b2fcfc65b7181cfb519ce1f827cb62f1120de5a0.zip |
lsp: client stop cleanups (#13877)
* lsp: client stop cleanups
* Add diagnostic clearing to client.stop() method used by nvim-lspconfig
* Clear diagnostic cache to prevent stale diagnostics on client restart
* lsp: Add test for vim.lsp.diagnostic.reset
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index a6f118abde..0c8d0bdc95 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -548,19 +548,13 @@ function lsp.start_client(config) function dispatch.on_exit(code, signal) active_clients[client_id] = nil uninitialized_clients[client_id] = nil - local active_buffers = {} - for bufnr, client_ids in pairs(all_buffer_active_clients) do - if client_ids[client_id] then - table.insert(active_buffers, bufnr) - end + + lsp.diagnostic.reset(client_id, all_buffer_active_clients) + all_client_active_buffers[client_id] = nil + for _, client_ids in pairs(all_buffer_active_clients) do client_ids[client_id] = nil end - -- Buffer level cleanup - vim.schedule(function() - for _, bufnr in ipairs(active_buffers) do - lsp.diagnostic.clear(bufnr) - end - end) + if config.on_exit then pcall(config.on_exit, code, signal, client_id) end @@ -751,6 +745,13 @@ function lsp.start_client(config) --- --@param force (bool, optional) function client.stop(force) + + lsp.diagnostic.reset(client_id, all_buffer_active_clients) + all_client_active_buffers[client_id] = nil + for _, client_ids in pairs(all_buffer_active_clients) do + client_ids[client_id] = nil + end + local handle = rpc.handle if handle:is_closing() then return @@ -1016,23 +1017,12 @@ end function lsp.stop_client(client_id, force) local ids = type(client_id) == 'table' and client_id or {client_id} for _, id in ipairs(ids) do - local resolved_client_id if type(id) == 'table' and id.stop ~= nil then id.stop(force) - resolved_client_id = id.id elseif active_clients[id] then active_clients[id].stop(force) - resolved_client_id = id elseif uninitialized_clients[id] then uninitialized_clients[id].stop(true) - resolved_client_id = id - end - if resolved_client_id then - local client_buffers = lsp.get_buffers_by_client_id(resolved_client_id) - for idx = 1, #client_buffers do - lsp.diagnostic.clear(client_buffers[idx], resolved_client_id) - end - all_client_active_buffers[resolved_client_id] = nil end end end |