From c374f264305f0cae77b13eba99db027aa7a6cb07 Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 13 Feb 2025 18:24:38 +0800 Subject: fix(lsp): clear word when expand multi-lines word (#32393) Problem: When expanding a completion item that contains a multi-line word, the word is not deleted correctly. Solution: If the word contains a line break, delete the text from Context.cursor to the current cursor position. --- runtime/lua/vim/lsp/completion.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua index 09d38bbce3..f287304508 100644 --- a/runtime/lua/vim/lsp/completion.lua +++ b/runtime/lua/vim/lsp/completion.lua @@ -493,6 +493,7 @@ local function trigger(bufnr, clients) end end local start_col = (server_start_boundary or word_boundary) + 1 + Context.cursor = { cursor_row, start_col } vim.fn.complete(start_col, matches) end) @@ -572,8 +573,14 @@ local function on_complete_done() end -- Remove the already inserted word. - local start_char = cursor_col - #completed_item.word - api.nvim_buf_set_text(bufnr, cursor_row, start_char, cursor_row, cursor_col, { '' }) + api.nvim_buf_set_text( + bufnr, + Context.cursor[1] - 1, + Context.cursor[2] - 1, + cursor_row, + cursor_col, + { '' } + ) end local function apply_snippet_and_command() -- cgit