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

Commit

Permalink
Merge pull request #51 from el-iot/master
Browse files Browse the repository at this point in the history
Ensure that diagnostic character-positions are > 0 (index-out-of-bounds error)
  • Loading branch information
haorenW1025 authored Jul 25, 2020
2 parents 5e1ce55 + 29ce932 commit 0367068
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 0367068

Please sign in to comment.