diff options
author | Steven Arcangeli <stevearc@stevearc.com> | 2023-09-13 11:42:54 -0700 |
---|---|---|
committer | Steven Arcangeli <stevearc@stevearc.com> | 2023-09-13 11:43:38 -0700 |
commit | e18cdaf529b94465592d0c2afe1b62bc26155070 (patch) | |
tree | 34550a1335ca2f2adcbe21af4a14eccf42c0c11f | |
parent | 212e5a8574e65f0c79d0267f5170c4247309e33b (diff) |
fix: extra trailing newline for LSP formatters that replace entire file
-rw-r--r-- | lua/conform/lsp_format.lua | 4 |
1 files changed, 4 insertions, 0 deletions
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) |