mirror of
https://github.com/neovim/neovim
synced 2025-07-16 17:21:49 +00:00
fix(codelens): add buffer and line checks before displaying codelens (#23887)
Co-authored-by: Rohit Sukumaran <rohit.sukumaran@kredx.com>
This commit is contained in:
@ -136,6 +136,10 @@ end
|
|||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param client_id integer
|
---@param client_id integer
|
||||||
function M.display(lenses, bufnr, client_id)
|
function M.display(lenses, bufnr, client_id)
|
||||||
|
if not api.nvim_buf_is_loaded(bufnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local ns = namespaces[client_id]
|
local ns = namespaces[client_id]
|
||||||
if not lenses or not next(lenses) then
|
if not lenses or not next(lenses) then
|
||||||
api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
|
api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
|
||||||
@ -181,6 +185,10 @@ end
|
|||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param client_id integer
|
---@param client_id integer
|
||||||
function M.save(lenses, bufnr, client_id)
|
function M.save(lenses, bufnr, client_id)
|
||||||
|
if not api.nvim_buf_is_loaded(bufnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local lenses_by_client = lens_cache_by_buf[bufnr]
|
local lenses_by_client = lens_cache_by_buf[bufnr]
|
||||||
if not lenses_by_client then
|
if not lenses_by_client then
|
||||||
lenses_by_client = {}
|
lenses_by_client = {}
|
||||||
@ -221,19 +229,24 @@ local function resolve_lenses(lenses, bufnr, client_id, callback)
|
|||||||
countdown()
|
countdown()
|
||||||
else
|
else
|
||||||
client.request('codeLens/resolve', lens, function(_, result)
|
client.request('codeLens/resolve', lens, function(_, result)
|
||||||
if result and result.command then
|
if api.nvim_buf_is_loaded(bufnr) and result and result.command then
|
||||||
lens.command = result.command
|
lens.command = result.command
|
||||||
-- Eager display to have some sort of incremental feedback
|
-- Eager display to have some sort of incremental feedback
|
||||||
-- Once all lenses got resolved there will be a full redraw for all lenses
|
-- Once all lenses got resolved there will be a full redraw for all lenses
|
||||||
-- So that multiple lens per line are properly displayed
|
-- So that multiple lens per line are properly displayed
|
||||||
api.nvim_buf_set_extmark(
|
|
||||||
bufnr,
|
local num_lines = api.nvim_buf_line_count(bufnr)
|
||||||
ns,
|
if lens.range.start.line <= num_lines then
|
||||||
lens.range.start.line,
|
api.nvim_buf_set_extmark(
|
||||||
0,
|
bufnr,
|
||||||
{ virt_text = { { lens.command.title, 'LspCodeLens' } }, hl_mode = 'combine' }
|
ns,
|
||||||
)
|
lens.range.start.line,
|
||||||
|
0,
|
||||||
|
{ virt_text = { { lens.command.title, 'LspCodeLens' } }, hl_mode = 'combine' }
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
countdown()
|
countdown()
|
||||||
end, bufnr)
|
end, bufnr)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user