diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2024-05-23 15:17:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-23 15:17:03 +0200 |
commit | 2908f71dc9e9591f97e0f9d70dbc8d8b18f9e475 (patch) | |
tree | 6b740bc2469baadec0c5aee5410593c6b3ca12c6 /runtime/lua/vim/lsp.lua | |
parent | 5ac8db10f0428c976dfc9a4935a74d0fe160995c (diff) | |
download | rneovim-2908f71dc9e9591f97e0f9d70dbc8d8b18f9e475.tar.gz rneovim-2908f71dc9e9591f97e0f9d70dbc8d8b18f9e475.tar.bz2 rneovim-2908f71dc9e9591f97e0f9d70dbc8d8b18f9e475.zip |
refactor(lsp): reuse buf_detach_client logic in on_detach (#28939)
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 68 |
1 files changed, 29 insertions, 39 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 700c10abc8..1592fd3151 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -501,6 +501,30 @@ local function text_document_did_save_handler(bufnr) end end +---@param bufnr integer resolved buffer +---@param client vim.lsp.Client +local function buf_detach_client(bufnr, client) + api.nvim_exec_autocmds('LspDetach', { + buffer = bufnr, + modeline = false, + data = { client_id = client.id }, + }) + + changetracking.reset_buf(client, bufnr) + + if client.supports_method(ms.textDocument_didClose) then + local uri = vim.uri_from_bufnr(bufnr) + local params = { textDocument = { uri = uri } } + client.notify(ms.textDocument_didClose, params) + end + + client.attached_buffers[bufnr] = nil + util.buf_versions[bufnr] = nil + + local namespace = lsp.diagnostic.get_namespace(client.id) + vim.diagnostic.reset(namespace, bufnr) +end + --- @type table<integer,true> local attached_buffers = {} @@ -574,26 +598,10 @@ local function buf_attach(bufnr) end, on_detach = function() - local params = { textDocument = { uri = uri } } - for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do - api.nvim_exec_autocmds('LspDetach', { - buffer = bufnr, - modeline = false, - data = { client_id = client.id }, - }) - - changetracking.reset_buf(client, bufnr) - if client.supports_method(ms.textDocument_didClose) then - client.notify(ms.textDocument_didClose, params) - end - - local namespace = lsp.diagnostic.get_namespace(client.id) - vim.diagnostic.reset(namespace, bufnr) - end - for _, client in ipairs(all_clients) do - client.attached_buffers[bufnr] = nil + local clients = lsp.get_clients({ bufnr = bufnr, _uninitialized = true }) + for _, client in ipairs(clients) do + buf_detach_client(bufnr, client) end - util.buf_versions[bufnr] = nil attached_buffers[bufnr] = nil end, @@ -668,27 +676,9 @@ function lsp.buf_detach_client(bufnr, client_id) ) ) return + else + buf_detach_client(bufnr, client) end - - api.nvim_exec_autocmds('LspDetach', { - buffer = bufnr, - modeline = false, - data = { client_id = client_id }, - }) - - changetracking.reset_buf(client, bufnr) - - if client.supports_method(ms.textDocument_didClose) then - local uri = vim.uri_from_bufnr(bufnr) - local params = { textDocument = { uri = uri } } - client.notify(ms.textDocument_didClose, params) - end - - client.attached_buffers[bufnr] = nil - util.buf_versions[bufnr] = nil - - local namespace = lsp.diagnostic.get_namespace(client_id) - vim.diagnostic.reset(namespace, bufnr) end --- Checks if a buffer is attached for a particular client. |