From 9bd169029ac7fac5d0b3899a47556549d113a4c2 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Mon, 9 Oct 2023 09:04:31 -0700 Subject: fix: catch and fix more cases of bad-behaving LSP formatters (#119) --- lua/conform/lsp_format.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lua/conform/lsp_format.lua') diff --git a/lua/conform/lsp_format.lua b/lua/conform/lsp_format.lua index 089bde2..283b3ae 100644 --- a/lua/conform/lsp_format.lua +++ b/lua/conform/lsp_format.lua @@ -9,7 +9,7 @@ local function apply_text_edits(text_edits, bufnr, offset_encoding) #text_edits == 1 and text_edits[1].range.start.line == 0 and text_edits[1].range.start.character == 0 - and text_edits[1].range["end"].line == vim.api.nvim_buf_line_count(bufnr) + 1 + and text_edits[1].range["end"].line >= vim.api.nvim_buf_line_count(bufnr) and text_edits[1].range["end"].character == 0 then local original_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) @@ -18,6 +18,7 @@ local function apply_text_edits(text_edits, bufnr, offset_encoding) if #new_lines > 1 and new_lines[#new_lines] == "" then table.remove(new_lines) end + log.debug("Converting full-file LSP format to piecewise format") 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