Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 29ce932

Browse files
committed
Ensure that diagnostic character-positions are > 0
Some language clients will set the diagnostic.range.start.character = -1 for particular sorts of issues, which causes an "index-out-of-bounds" error when setting virtual text. This fix makes sure all characters start / end positions are are (at least) 0.
1 parent 5e1ce55 commit 29ce932

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lua/diagnostic.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function M.publish_diagnostics(bufnr)
7474
if #vim.lsp.buf_get_clients() == 0 then return end
7575
local diagnostics = vim.lsp.util.diagnostics_by_buf[bufnr]
7676
if diagnostics == nil then return end
77+
util.align_diagnostic_indices(diagnostics)
7778
vim.fn.setloclist(0, {}, 'r')
7879
if vim.api.nvim_get_var('diagnostic_enable_underline') == 1 then
7980
vim.lsp.util.buf_diagnostics_underline(bufnr, diagnostics)

lua/diagnostic/util.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,11 @@ function M.buf_diagnostics_signs(bufnr, diagnostics)
179179
end
180180
end
181181

182+
function M.align_diagnostic_indices(diagnostics)
183+
for idx, diagnostic in ipairs(diagnostics) do
184+
if diagnostic.range.start.character < 0 then diagnostic.range.start.character = 0 end
185+
if diagnostic.range['end'].character < 0 then diagnostic.range['end'].character = 0 end
186+
end
187+
end
188+
182189
return M

0 commit comments

Comments
 (0)