From 096f8418c5b7f2ea75b996b5cf4a6534fb99fcb6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 2 Dec 2021 07:02:30 -0800 Subject: [PATCH] fix(diagnostic): clamp diagnostics on negative line numbers (#16497) Closes https://github.com/neovim/neovim/issues/16492 Despite having logic for setting the maximum diagnostic line number to at minimum 0, previously the conditional statement only checked if lnum and end_lnum were greater than the line count. Fix: also check if lnum and end_lnum are less than 0. (cherry picked from commit 2799463ba260296d17e9ce3708a91526e01e454b) Co-authored-by: Michael Lingelbach --- runtime/lua/vim/diagnostic.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 71bf96baee..a903f25b58 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -386,7 +386,7 @@ local function get_diagnostics(bufnr, opts, clamp) if not opts.lnum or d.lnum == opts.lnum then if clamp and vim.api.nvim_buf_is_loaded(b) then local line_count = buf_line_count[b] - 1 - if (d.lnum > line_count or d.end_lnum > line_count) then + if (d.lnum > line_count or d.end_lnum > line_count or d.lnum < 0 or d.end_lnum < 0) then d = vim.deepcopy(d) d.lnum = math.max(math.min(d.lnum, line_count), 0) d.end_lnum = math.max(math.min(d.end_lnum, line_count), 0)