From ee3a58d42e7fce666eef570db6f2944c29303d98 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sun, 14 Nov 2021 12:55:16 +0100 Subject: fix(lsp): ensure buffers are re-attached on rename (#16266) If a LSP server sent a workspace edit containing a rename the buffers file name changed without the server receiving a close notification for the old buffer and without the client properly re-attaching on the new file. This affected `Move` code-actions in nvim-jdtls, but also `vim.lsp.buf.rename` on a class level. --- runtime/lua/vim/lsp.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp.lua') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 7fa70af779..0fc0a7a7aa 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -472,7 +472,11 @@ local function text_document_did_open_handler(bufnr, client) -- Next chance we get, we should re-do the diagnostics vim.schedule(function() - vim.lsp.diagnostic.redraw(bufnr, client.id) + -- Protect against a race where the buffer disappears + -- between `did_open_handler` and the scheduled function firing. + if vim.api.nvim_buf_is_valid(bufnr) then + vim.lsp.diagnostic.redraw(bufnr, client.id) + end end) end -- cgit