mirror of
https://github.com/neovim/neovim
synced 2025-07-21 05:42:46 +00:00
fix(diagnostics): don't apply extmarks to invalid lines #29321
Problem:
If there are errors in the last line of a buffer, something like `Gdk` or
`G2k3J` will produce an error (at least with `lua_ls`):
Error executing vim.schedule lua callback:
.../neovim/share/nvim/runtime/lua/vim/diagnostic.lua:1446: Invalid 'line': out of range
Solution:
Only set extmarks if the target buffer line still exists
(cherry picked from commit e5e81262af
)
This commit is contained in:
committed by
Christian Clason
parent
5955ef0ba8
commit
21157459fe
@ -1239,6 +1239,10 @@ M.handlers.signs = {
|
|||||||
bufnr = get_bufnr(bufnr)
|
bufnr = get_bufnr(bufnr)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
|
if not api.nvim_buf_is_loaded(bufnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if opts.signs and opts.signs.severity then
|
if opts.signs and opts.signs.severity then
|
||||||
diagnostics = filter_by_severity(opts.signs.severity, diagnostics)
|
diagnostics = filter_by_severity(opts.signs.severity, diagnostics)
|
||||||
end
|
end
|
||||||
@ -1323,8 +1327,10 @@ M.handlers.signs = {
|
|||||||
local numhl = opts.signs.numhl or {}
|
local numhl = opts.signs.numhl or {}
|
||||||
local linehl = opts.signs.linehl or {}
|
local linehl = opts.signs.linehl or {}
|
||||||
|
|
||||||
|
local line_count = api.nvim_buf_line_count(bufnr)
|
||||||
|
|
||||||
for _, diagnostic in ipairs(diagnostics) do
|
for _, diagnostic in ipairs(diagnostics) do
|
||||||
if api.nvim_buf_is_loaded(diagnostic.bufnr) then
|
if diagnostic.lnum <= line_count then
|
||||||
api.nvim_buf_set_extmark(bufnr, ns.user_data.sign_ns, diagnostic.lnum, 0, {
|
api.nvim_buf_set_extmark(bufnr, ns.user_data.sign_ns, diagnostic.lnum, 0, {
|
||||||
sign_text = text[diagnostic.severity] or text[M.severity[diagnostic.severity]] or 'U',
|
sign_text = text[diagnostic.severity] or text[M.severity[diagnostic.severity]] or 'U',
|
||||||
sign_hl_group = sign_highlight_map[diagnostic.severity],
|
sign_hl_group = sign_highlight_map[diagnostic.severity],
|
||||||
|
Reference in New Issue
Block a user