diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 3677a414cf..cc9e4e3690 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -378,6 +378,7 @@ function M.apply_text_edits(text_edits, bufnr, position_encoding, change_annotat -- of the buffer. if max <= start_row then api.nvim_buf_set_lines(bufnr, max, max, false, text) + has_eol_text_edit = true else local last_line_len = #(get_line(bufnr, math.min(end_row, max - 1)) or '') -- Some LSP servers may return +1 range of the buffer content but nvim_buf_set_text can't diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 2e68f2cbfe..93ecc71b04 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2248,6 +2248,20 @@ describe('LSP', function() }, buf_lines(1)) end) + it('applies newline-terminated text edits at the end of the document', function() + apply_text_edits({ + { 5, 0, 5, 0, 'foobar\n' }, + }) + eq({ + 'First line of text', + 'Second line of text', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', + 'foobar', + }, buf_lines(1)) + end) + it('it restores marks', function() eq(true, api.nvim_buf_set_mark(1, 'a', 2, 1, {})) apply_text_edits({