From f9bf64d74641f33961fe1d6c1592b65d2744298f Mon Sep 17 00:00:00 2001 From: glepnir Date: Wed, 11 Sep 2024 23:11:09 +0800 Subject: 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. --- runtime/lua/vim/lsp/inlay_hint.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua index 4483b083de..61059180fe 100644 --- a/runtime/lua/vim/lsp/inlay_hint.lua +++ b/runtime/lua/vim/lsp/inlay_hint.lua @@ -43,17 +43,16 @@ function M.on_inlayhint(err, result, ctx, _) return end 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 end local client_id = ctx.client_id - if not result then - return - end local bufstate = bufstates[bufnr] - if not bufstate.enabled then - return - end if not (bufstate.client_hints and bufstate.version) then bufstate.client_hints = vim.defaulttable() bufstate.version = ctx.version -- cgit