aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/lsp_format.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-10-09 09:04:31 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-10-09 09:04:42 -0700
commit9bd169029ac7fac5d0b3899a47556549d113a4c2 (patch)
tree38eb1574e5ded331851100314addca5eae8992a1 /lua/conform/lsp_format.lua
parent2defad68f16ad51f9a2d250f29e67af888435801 (diff)
fix: catch and fix more cases of bad-behaving LSP formatters (#119)
Diffstat (limited to 'lua/conform/lsp_format.lua')
-rw-r--r--lua/conform/lsp_format.lua3
1 files changed, 2 insertions, 1 deletions
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)