From d42f7ee9dcbbece1c65d901fb9825fbe97eeedce Mon Sep 17 00:00:00 2001 From: Aaron Tinio Date: Thu, 11 Jun 2026 07:25:13 +0800 Subject: fix(lsp): trailing blank line when edit inserts past end of buffer #40133 Problem: A text edit positioned entirely past the last buffer line, with newText ending in a newline, leaves a stray blank line: the past-the-end path appends the trailing empty fragment produced by vim.split() and does not set has_eol_text_edit, so the end-of-buffer cleanup is skipped. Formatting servers emit such edits whenever formatting moves text to the end of a document. Regression from ec94014cd1 (#20137), which split the past-the-end fast path off the clamp path that sets the flag. Solution: Set has_eol_text_edit in the past-the-end path, like the adjacent path that clamps end_row. --- runtime/lua/vim/lsp/util.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/lua/vim/lsp/util.lua') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 0b5e978323..b702afb6d9 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -223,6 +223,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)) -- Some LSP servers may return +1 range of the buffer content but nvim_buf_set_text can't -- cgit