mirror of
https://github.com/neovim/neovim.git
synced 2026-09-08 23:18:59 +00:00
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
This commit is contained in:
committed by
GitHub
parent
65ef6fdaee
commit
ce5e230af8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user