Skip to content

Commit d595330

Browse files
authored
fix: correctly calculate unicode line length (#253)
* fix: correctly calculate unicode line length * use correct utf version in 0.11
1 parent a66b5b9 commit d595330

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lua/null-ls/helpers/diagnostics.lua

+10-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ local make_diagnostic = function(entries, defaults, attr_adapters, params, offse
6767
-- In order to match the correct range in lines with multi-byte characters,
6868
-- we need to convert the column number to a byte index.
6969
-- See: https://github.com/nvimtools/none-ls.nvim/issues/19#issuecomment-1820127436
70+
-- and https://github.com/nvimtools/none-ls.nvim/issues/226
7071
if entries["col"] ~= nil and content_line ~= nil then
7172
local col = tonumber(entries["col"]) or math.huge
72-
col = math.min(col, string.len(content_line))
73-
local byte_index_col = vim.str_byteindex(content_line, col)
73+
col = math.min(col, vim.fn.strwidth(content_line))
74+
75+
local byte_index_col
76+
if u.has_version("0.11") then
77+
byte_index_col = vim.str_byteindex(content_line, "utf-32", col)
78+
else
79+
byte_index_col = vim.str_byteindex(content_line, col)
80+
end
81+
7482
entries["col"] = tostring(byte_index_col)
7583
end
7684

0 commit comments

Comments
 (0)