diff options
author | Fredrik Ekre <ekrefredrik@gmail.com> | 2022-06-01 18:56:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-01 18:56:18 +0200 |
commit | 209824ce2c6d37332079e6e213d4b8e257d7d53b (patch) | |
tree | acefbff4b7cf17af4533e34df65e8790eb083ade /runtime/lua/vim/lsp/buf.lua | |
parent | 19e80738e03f352602ec573d3634d53cb6cd09f7 (diff) | |
download | rneovim-209824ce2c6d37332079e6e213d4b8e257d7d53b.tar.gz rneovim-209824ce2c6d37332079e6e213d4b8e257d7d53b.tar.bz2 rneovim-209824ce2c6d37332079e6e213d4b8e257d7d53b.zip |
fix(lsp): adjust offset encoding in lsp.buf.rename() (#18829)
Fix a bug in lsp.buf.rename() where the range returned by the server in
textDocument/prepareRename was interpreted as a byte range directly,
instead of taking the negotiated offset encoding into account. This
caused the placeholder value in vim.ui.input to be incorrect in some
cases, for example when non-ascii characters are used earlier on the
same line.
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index bcfaecdfcc..0b2e1c9b8d 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -408,13 +408,13 @@ function M.rename(new_name, options) local cword = vfn.expand('<cword>') ---@private - local function get_text_at_range(range) + local function get_text_at_range(range, offset_encoding) return vim.api.nvim_buf_get_text( bufnr, range.start.line, - range.start.character, + util._get_line_byte_from_position(bufnr, range.start, offset_encoding), range['end'].line, - range['end'].character, + util._get_line_byte_from_position(bufnr, range['end'], offset_encoding), {} )[1] end @@ -461,9 +461,9 @@ function M.rename(new_name, options) if result.placeholder then prompt_opts.default = result.placeholder elseif result.start then - prompt_opts.default = get_text_at_range(result) + prompt_opts.default = get_text_at_range(result, client.offset_encoding) elseif result.range then - prompt_opts.default = get_text_at_range(result.range) + prompt_opts.default = get_text_at_range(result.range, client.offset_encoding) else prompt_opts.default = cword end |