From e18cdaf529b94465592d0c2afe1b62bc26155070 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Wed, 13 Sep 2023 11:42:54 -0700 Subject: fix: extra trailing newline for LSP formatters that replace entire file --- lua/conform/lsp_format.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lua/conform/lsp_format.lua') diff --git a/lua/conform/lsp_format.lua b/lua/conform/lsp_format.lua index 66be47d..1400f3b 100644 --- a/lua/conform/lsp_format.lua +++ b/lua/conform/lsp_format.lua @@ -13,6 +13,10 @@ local function apply_text_edits(text_edits, bufnr, offset_encoding) then local original_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) local new_lines = vim.split(text_edits[1].newText, "\n", { plain = true }) + -- If it had a trailing newline, remove it to make the lines match the expected vim format + if #new_lines > 1 and new_lines[#new_lines] == "" then + table.remove(new_lines) + end require("conform.runner").apply_format(bufnr, original_lines, new_lines, nil, false) else vim.lsp.util.apply_text_edits(text_edits, bufnr, offset_encoding) -- cgit v1.2.3-70-g09d2