diff options
author | hrsh7th <629908+hrsh7th@users.noreply.github.com> | 2023-03-14 20:59:43 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 04:59:43 -0700 |
commit | 8dde7c907ca9ad365895bded2c2f59e08f65d3ed (patch) | |
tree | e69c38ade53bc9779640ae1f57a97a5873ed2096 /runtime/lua/vim/lsp/util.lua | |
parent | 06e3ff6671b45ffde8cbfa98ce2743fb9d46319d (diff) | |
download | rneovim-8dde7c907ca9ad365895bded2c2f59e08f65d3ed.tar.gz rneovim-8dde7c907ca9ad365895bded2c2f59e08f65d3ed.tar.bz2 rneovim-8dde7c907ca9ad365895bded2c2f59e08f65d3ed.zip |
fix(lsp): vim.lsp.util.apply_text_edits cursor validation #22636
Problem
Using wrong variable when checking the cursor position is valid or not in
vim.lsp.util.apply_text_edits.
Solution
Use the correct variable.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 342fad33c2..82c9e3bc87 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -436,7 +436,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding) -- Some LSP servers are depending on the VSCode behavior. -- The VSCode will re-locate the cursor position after applying TextEdit so we also do it. - local is_current_buf = api.nvim_get_current_buf() == bufnr + local is_current_buf = api.nvim_get_current_buf() == bufnr or bufnr == 0 local cursor = (function() if not is_current_buf then return { @@ -464,7 +464,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding) start_col = get_line_byte_from_position(bufnr, text_edit.range.start, offset_encoding), end_row = text_edit.range['end'].line, end_col = get_line_byte_from_position(bufnr, text_edit.range['end'], offset_encoding), - text = split(text_edit.newText, '\n', true), + text = split(text_edit.newText, '\n', { plain = true }), } local max = api.nvim_buf_line_count(bufnr) @@ -522,7 +522,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding) if is_cursor_fixed then local is_valid_cursor = true is_valid_cursor = is_valid_cursor and cursor.row < max - is_valid_cursor = is_valid_cursor and cursor.col <= #(get_line(bufnr, max - 1) or '') + is_valid_cursor = is_valid_cursor and cursor.col <= #(get_line(bufnr, cursor.row) or '') if is_valid_cursor then api.nvim_win_set_cursor(0, { cursor.row + 1, cursor.col }) end |