diff options
author | Andre Toerien <49614525+AThePeanut4@users.noreply.github.com> | 2024-05-23 12:03:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-23 12:03:47 +0200 |
commit | 5ac8db10f0428c976dfc9a4935a74d0fe160995c (patch) | |
tree | aa50ff431cfccc926a74553f01456c87dfd3af49 | |
parent | bdf15dbe6909b39e5d3cf22ae844ebd37862a1a8 (diff) | |
download | rneovim-5ac8db10f0428c976dfc9a4935a74d0fe160995c.tar.gz rneovim-5ac8db10f0428c976dfc9a4935a74d0fe160995c.tar.bz2 rneovim-5ac8db10f0428c976dfc9a4935a74d0fe160995c.zip |
fix(lsp): trigger LspDetach on buffer delete (#28795)
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
-rw-r--r-- | runtime/lua/vim/lsp.lua | 9 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index ad1794e98d..700c10abc8 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -576,10 +576,19 @@ local function buf_attach(bufnr) 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 diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 3bbb5c0971..8358a1b9ec 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -475,6 +475,12 @@ describe('LSP', function() local server = _create_server() local bufnr = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(bufnr) + local detach_called = false + vim.api.nvim_create_autocmd("LspDetach", { + callback = function() + detach_called = true + end + }) local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server.cmd }) assert(client_id, "lsp.start must return client_id") local client = vim.lsp.get_client_by_id(client_id) @@ -486,11 +492,13 @@ describe('LSP', function() client_id = client_id, num_attached_before = num_attached_before, num_attached_after = num_attached_after, + detach_called = detach_called, } ]]) eq(true, result ~= nil, 'exec_lua must return result') eq(1, result.num_attached_before) eq(0, result.num_attached_after) + eq(true, result.detach_called) end) it('client should return settings via workspace/configuration handler', function() |