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

Commit

Permalink
Fix going out of bounds in a buffer
Browse files Browse the repository at this point in the history
`strict_indexing` was set to `true` in the `nvim_buf_get_lines` call, so when `row` got to the end of the buffer it would cause an error.

Setting `strict_indexing` to `false` caused `line` to be `nil` sometimes, so I added some logic to handle that.
  • Loading branch information
Iron-E authored Jul 4, 2020
1 parent bdef92a commit fa12d56
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lua/diagnostic/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,22 @@ function M.locations_to_items(locations)
for _, temp in ipairs(rows) do
local pos = temp.start
local row = pos.line
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
local col
if pos.character > #line then
col = #line
else
col = vim.str_byteindex(line, pos.character)
local line = api.nvim_buf_get_lines(0, row, row+1, false)[1]
if line then
local col
if pos.character > #line then
col = #line
else
col = vim.str_byteindex(line, pos.character)
end

table.insert(items, {
bufnr = bufnr,
lnum = row + 1,
col = col + 1;
text = line
})
end
table.insert(items, {
bufnr = bufnr,
lnum = row + 1,
col = col + 1;
text = line
})
end
return items
end
Expand Down

0 comments on commit fa12d56

Please sign in to comment.