nvimtools / none-ls.nvim

null-ls.nvim reloaded / Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
The Unlicense
2.44k stars 73 forks source link

fix: diagnostic range in multi-byte lines #36

Closed davidmh closed 9 months ago

davidmh commented 9 months ago

When we parse the report produced by a source, we usually read and forward the column index, but in Lua, the index of a substring depends on the number of bytes in the string, not the number of printable characters.

For example, the line:

• Any rule whose heading is ~~struck through~~ is deprecated.

Produces the report:

text:1:47:"is deprecated" may be passive voice

But if we use that 47 to create the diagnostic, Lua will count 47 bytes, which will give us:

"~~ is deprecated"

Instead of

"is deprecated"

That's why we end up with the odd range described in #19.

Luckily, the Neovim team has a function to find the index we need through the function vim.str_byteindex.

davidmh commented 9 months ago

@mochaaP thank you for the review. Could you merge the PR? I don't have write access.