diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua index 7605d8fd44..1b49d946e9 100644 --- a/runtime/lua/vim/lsp/client.lua +++ b/runtime/lua/vim/lsp/client.lua @@ -1099,6 +1099,9 @@ function Client:on_attach(bufnr) -- on_attach and LspAttach callbacks the ability to schedule wrap the -- opt-out (deleting the semanticTokensProvider from capabilities) vim.schedule(function() + if not vim.api.nvim_buf_is_valid(bufnr) then + return + end for _, Capability in pairs(lsp._capability.all) do if self:supports_method(Capability.method)