Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit 9ccbd1d

Browse files
committed
diagnostics: convert columns to bytes
1 parent 77e53bc commit 9ccbd1d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lua/null-ls/diagnostics.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ local handle_multiple_file_diagnostics = function(namespace, diagnostics)
115115
end
116116

117117
local handle_diagnostics = function(id, diagnostics, bufnr, multiple_files)
118+
for _, diagnostic in ipairs(diagnostics) do
119+
local bnr = bufnr
120+
if multiple_files then
121+
bnr = diagnostic.bufnr
122+
end
123+
local start_line = vim.api.nvim_buf_get_lines(bnr, diagnostic.lnum, diagnostic.lnum + 1, false)[1]
124+
diagnostic.col = vim.str_byteindex(start_line, diagnostic.col)
125+
-- automatic search for valid end coordinates for sources that don't provide them
126+
diagnostic.end_col, diagnostic.end_lnum = (setmetatable({
127+
end_col = diagnostic.end_col,
128+
end_lnum = diagnostic.end_lnum,
129+
}, {
130+
__call = function(self)
131+
local end_line = vim.api.nvim_buf_get_lines(bnr, self.end_lnum, self.end_lnum + 1, false)[1]
132+
local ok, end_col = pcall(vim.str_byteindex, end_line, self.end_col)
133+
if not ok then
134+
self.end_lnum = self.end_lnum + 1
135+
self.end_col = self.end_col - vim.api.nvim_strwidth(end_line) - 1
136+
return self()
137+
end
138+
return end_col, self.end_lnum
139+
end,
140+
}))()
141+
end
118142
local namespace = get_namespace(id)
119143
if multiple_files then
120144
handle_multiple_file_diagnostics(namespace, diagnostics)

0 commit comments

Comments
 (0)