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

Commit cd80a41

Browse files
authored
Merge pull request #38 from Iron-E/patch-1
Fix going out of bounds in a buffer
2 parents bdef92a + fa12d56 commit cd80a41

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

lua/diagnostic/util.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,22 @@ function M.locations_to_items(locations)
146146
for _, temp in ipairs(rows) do
147147
local pos = temp.start
148148
local row = pos.line
149-
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
150-
local col
151-
if pos.character > #line then
152-
col = #line
153-
else
154-
col = vim.str_byteindex(line, pos.character)
149+
local line = api.nvim_buf_get_lines(0, row, row+1, false)[1]
150+
if line then
151+
local col
152+
if pos.character > #line then
153+
col = #line
154+
else
155+
col = vim.str_byteindex(line, pos.character)
156+
end
157+
158+
table.insert(items, {
159+
bufnr = bufnr,
160+
lnum = row + 1,
161+
col = col + 1;
162+
text = line
163+
})
155164
end
156-
table.insert(items, {
157-
bufnr = bufnr,
158-
lnum = row + 1,
159-
col = col + 1;
160-
text = line
161-
})
162165
end
163166
return items
164167
end

0 commit comments

Comments
 (0)