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

Commit

Permalink
Ensure that diagnostic character-positions are > 0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
el-iot committed Jul 24, 2020
1 parent 5e1ce55 commit 29ce932
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function M.publish_diagnostics(bufnr)
if #vim.lsp.buf_get_clients() == 0 then return end
local diagnostics = vim.lsp.util.diagnostics_by_buf[bufnr]
if diagnostics == nil then return end
util.align_diagnostic_indices(diagnostics)
vim.fn.setloclist(0, {}, 'r')
if vim.api.nvim_get_var('diagnostic_enable_underline') == 1 then
vim.lsp.util.buf_diagnostics_underline(bufnr, diagnostics)
Expand Down
7 changes: 7 additions & 0 deletions lua/diagnostic/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,11 @@ function M.buf_diagnostics_signs(bufnr, diagnostics)
end
end

function M.align_diagnostic_indices(diagnostics)
for idx, diagnostic in ipairs(diagnostics) do
if diagnostic.range.start.character < 0 then diagnostic.range.start.character = 0 end
if diagnostic.range['end'].character < 0 then diagnostic.range['end'].character = 0 end
end
end

return M

0 comments on commit 29ce932

Please sign in to comment.