From ce5e230af8d371ba78d04057d7d840bd4c31fd22 Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi Date: Mon, 7 Sep 2026 18:21:11 +0200 Subject: [PATCH] fix(lsp): show_document() reports a failed buffer load #41731 Problem: vim.lsp.util.show_document() can fail to load the target buffer, most visibly with E325 when another process owns the file's swapfile and the user declines to open it. The Vim error escapes show_document() and surfaces inside whichever LSP handler called it, instead of being reported as a failure to show the document. Solution: Load the buffer up front with vim.fn.bufload(), before any of that state is touched, and report the error instead of raising. AI-assisted --- runtime/lua/vim/lsp/util.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 0da99e70bf..7a8e8d6812 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -876,6 +876,13 @@ function M.show_document(location, position_encoding, opts) end local bufnr = vim.uri_to_bufnr(uri) + -- Return early if the buffer fails to load, to avoid partial setup. + local loaded, err = pcall(vim.fn.bufload, bufnr) + if not loaded then + vim.notify(tostring(err), vim.log.levels.ERROR) + return false + end + opts = opts or {} local focus = vim.nonnil(opts.focus, true) if focus then