fix(lsp): check whether buffer is valid when scheduled #35461

This commit is contained in:
Yi Ming
2025-08-25 09:59:56 +08:00
committed by GitHub
parent bccec33f5a
commit 42f244bf18

View File

@@ -265,7 +265,7 @@ end
---@param client_id integer
function State:on_attach(client_id)
self.client_state = {}
self.client_state[client_id] = {}
self:refresh(vim.lsp.get_client_by_id(client_id))
end
@@ -344,7 +344,9 @@ function M.foldexpr(lnum)
if not vim.lsp._capability.is_enabled('folding_range', { bufnr = bufnr }) then
-- `foldexpr` lead to a textlock, so any further operations need to be scheduled.
vim.schedule(function()
vim.lsp._capability.enable('folding_range', true, { bufnr = bufnr })
if api.nvim_buf_is_valid(bufnr) then
vim.lsp._capability.enable('folding_range', true, { bufnr = bufnr })
end
end)
end