Skip to content

Commit

Permalink
fix: catch and fix more cases of bad-behaving LSP formatters (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Oct 9, 2023
1 parent 2defad6 commit 9bd1690
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lua/conform/lsp_format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 9bd1690

Please sign in to comment.