fix(lsp): check buffer is loaded and valid #30330

Problem: buffer mabye not valid when callback handler invoke.

Soliton: check buffer is valid and loaded in handler.
This commit is contained in:
glepnir 2024-09-11 23:11:09 +08:00 committed by GitHub
parent a30afeeb85
commit f9bf64d746
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,17 +43,16 @@ function M.on_inlayhint(err, result, ctx, _)
return return
end end
local bufnr = assert(ctx.bufnr) local bufnr = assert(ctx.bufnr)
if util.buf_versions[bufnr] ~= ctx.version then if
util.buf_versions[bufnr] ~= ctx.version
or not result
or not api.nvim_buf_is_loaded(bufnr)
or not bufstates[bufnr].enabled
then
return return
end end
local client_id = ctx.client_id local client_id = ctx.client_id
if not result then
return
end
local bufstate = bufstates[bufnr] local bufstate = bufstates[bufnr]
if not bufstate.enabled then
return
end
if not (bufstate.client_hints and bufstate.version) then if not (bufstate.client_hints and bufstate.version) then
bufstate.client_hints = vim.defaulttable() bufstate.client_hints = vim.defaulttable()
bufstate.version = ctx.version bufstate.version = ctx.version