diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-03-30 14:37:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 14:37:55 -0700 |
commit | db47cf81537f929812cd7aa3bc2b852a31cb48ae (patch) | |
tree | 50935706fc9e15d219309b3d140025c691d43e0a /runtime/lua/vim/lsp/util.lua | |
parent | 240cec9192802db4f166c092428087180e4d3214 (diff) | |
parent | 0cadab14123a492f6a02f9580315596d604f9a9d (diff) | |
download | rneovim-db47cf81537f929812cd7aa3bc2b852a31cb48ae.tar.gz rneovim-db47cf81537f929812cd7aa3bc2b852a31cb48ae.tar.bz2 rneovim-db47cf81537f929812cd7aa3bc2b852a31cb48ae.zip |
Merge pull request #14233 from mjlbach/disable_utf16_conversion
lsp: use utf-8 when utf-16 not requested
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 412be68396..ec1131ae1f 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -357,8 +357,11 @@ end --- Returns the range table for the difference between old and new lines --@param old_lines table list of lines --@param new_lines table list of lines +--@param start_line_idx int line to begin search for first difference +--@param end_line_idx int line to begin search for last difference +--@param offset_encoding string encoding requested by language server --@returns table start_line_idx and start_col_idx of range -function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx) +function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx, offset_encoding) local start_line, start_char = first_difference(old_lines, new_lines, start_line_idx) local end_line, end_char = last_difference(vim.list_slice(old_lines, start_line, #old_lines), vim.list_slice(new_lines, start_line, #new_lines), start_char, end_line_idx) @@ -373,13 +376,19 @@ function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx) adj_end_char = #old_lines[#old_lines + end_line + 1] + end_char + 1 end - local _, utf16_start_char = vim.str_utfindex(old_lines[start_line], start_char - 1) - local _, utf16_end_char = vim.str_utfindex(old_lines[#old_lines + end_line + 1], adj_end_char) + local _ + if offset_encoding == "utf-16" then + _, start_char = vim.str_utfindex(old_lines[start_line], start_char - 1) + _, end_char = vim.str_utfindex(old_lines[#old_lines + end_line + 1], adj_end_char) + else + start_char = start_char - 1 + end_char = adj_end_char + end local result = { range = { - start = { line = start_line - 1, character = utf16_start_char}, - ["end"] = { line = adj_end_line, character = utf16_end_char} + start = { line = start_line - 1, character = start_char}, + ["end"] = { line = adj_end_line, character = end_char} }, text = text, rangeLength = length + 1, |