fix(diagnostic): handle diagnostics placed past the end of line (#16095)

This commit is contained in:
Gregory Anders
2021-10-19 16:27:49 -06:00
committed by GitHub
parent 208d259e83
commit a2994c82e3
2 changed files with 20 additions and 1 deletions

View File

@@ -1146,8 +1146,12 @@ function M.open_float(bufnr, opts)
return d.lnum == lnum
end, diagnostics)
elseif scope == "cursor" then
-- LSP servers can send diagnostics with `end_col` past the length of the line
local line_length = #vim.api.nvim_buf_get_lines(bufnr, lnum, lnum + 1, true)[1]
diagnostics = vim.tbl_filter(function(d)
return d.lnum == lnum and d.col <= col and (d.end_col >= col or d.end_lnum > lnum)
return d.lnum == lnum
and math.min(d.col, line_length - 1) <= col
and (d.end_col >= col or d.end_lnum > lnum)
end, diagnostics)
end