aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-06-19 09:28:44 -0700
committerGitHub <noreply@github.com>2024-06-19 09:28:44 -0700
commite5e81262af88ec13b456d68ffb5a6ffafe497dab (patch)
treef35ac3727556fe7246b59975d5c94e3c406bf964
parentfe5d1279a4378582898e2e281fe5778d81c30017 (diff)
downloadrneovim-e5e81262af88ec13b456d68ffb5a6ffafe497dab.tar.gz
rneovim-e5e81262af88ec13b456d68ffb5a6ffafe497dab.tar.bz2
rneovim-e5e81262af88ec13b456d68ffb5a6ffafe497dab.zip
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
-rw-r--r--runtime/lua/vim/diagnostic.lua8
1 files changed, 7 insertions, 1 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index c8e34258f5..3be22556ab 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -1359,6 +1359,10 @@ M.handlers.signs = {
bufnr = get_bufnr(bufnr)
opts = opts or {}
+ if not api.nvim_buf_is_loaded(bufnr) then
+ return
+ end
+
if opts.signs and opts.signs.severity then
diagnostics = filter_by_severity(opts.signs.severity, diagnostics)
end
@@ -1441,8 +1445,10 @@ M.handlers.signs = {
local numhl = opts.signs.numhl or {}
local linehl = opts.signs.linehl or {}
+ local line_count = api.nvim_buf_line_count(bufnr)
+
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, {
sign_text = text[diagnostic.severity] or text[M.severity[diagnostic.severity]] or 'U',
sign_hl_group = sign_highlight_map[diagnostic.severity],