diff options
| author | Riley Bruins <ribru17@hotmail.com> | 2025-07-10 11:12:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-10 11:12:18 -0700 |
| commit | 7bd4dfd209e9877c9878ce63e59a84492f00251b (patch) | |
| tree | 6f3844e605408d47f21055685fc1b4f4448c0d25 /runtime/lua/vim | |
| parent | 4745270bf124a960ccdffdddbb6c27b7bf36ba82 (diff) | |
| download | rneovim-7bd4dfd209e9877c9878ce63e59a84492f00251b.tar.gz rneovim-7bd4dfd209e9877c9878ce63e59a84492f00251b.tar.bz2 rneovim-7bd4dfd209e9877c9878ce63e59a84492f00251b.zip | |
refactor(lsp): simplify multiline semantic token logic #34698
This commit makes it so that only one call to `vim.str_byteindex` is
needed, at the end of the `end_line`, `end_col` calculations.
Diffstat (limited to 'runtime/lua/vim')
| -rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 3a760c1156..8b34cf9d71 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -152,17 +152,19 @@ local function tokens_to_ranges(data, bufnr, client, request) local buf_line = lines[line + 1] or '' local end_line = line ---@type integer local start_col = vim.str_byteindex(buf_line, encoding, start_char, false) - local end_col = vim.str_byteindex(buf_line, encoding, end_char, false) - end_char = end_char - vim.str_utfindex(buf_line, encoding) - eol_offset + ---@type integer LuaLS bug, type must be marked explicitly here + local new_end_char = end_char - vim.str_utfindex(buf_line, encoding) - eol_offset -- While end_char goes past the given line, extend the token range to the next line - while end_char > 0 do + while new_end_char > 0 do + end_char = new_end_char end_line = end_line + 1 buf_line = lines[end_line + 1] or '' - end_col = vim.str_byteindex(buf_line, encoding, end_char, false) - end_char = end_char - vim.str_utfindex(buf_line, encoding) - eol_offset + new_end_char = new_end_char - vim.str_utfindex(buf_line, encoding) - eol_offset end + local end_col = vim.str_byteindex(buf_line, encoding, end_char, false) + ranges[#ranges + 1] = { line = line, end_line = end_line, |