aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-10-08 13:10:24 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-10-08 16:58:44 -0700
commita94f686986631d5b97bd75b3877813c39de55c47 (patch)
treea0c975e5799bb2b9c05ace69b7dbe8025a431837 /lua/conform/formatters
parente75819642c36810a55a7235b6b5e16a5ce896ed3 (diff)
feat: errors do not stop formatting early
Diffstat (limited to 'lua/conform/formatters')
-rw-r--r--lua/conform/formatters/injected.lua27
1 files changed, 13 insertions, 14 deletions
diff --git a/lua/conform/formatters/injected.lua b/lua/conform/formatters/injected.lua
index b9d3acd..8140550 100644
--- a/lua/conform/formatters/injected.lua
+++ b/lua/conform/formatters/injected.lua
@@ -84,6 +84,7 @@ return {
end,
format = function(self, ctx, lines, callback)
local conform = require("conform")
+ local errors = require("conform.errors")
local log = require("conform.log")
local util = require("conform.util")
local text = table.concat(lines, "\n")
@@ -124,19 +125,17 @@ return {
local function apply_format_results()
if format_error then
- if self.options.ignore_errors then
- -- Find all of the conform errors in the replacements table and remove them
- local i = 1
- while i <= #replacements do
- if replacements[i].code then
- table.remove(replacements, i)
- else
- i = i + 1
- end
+ -- Find all of the conform errors in the replacements table and remove them
+ local i = 1
+ while i <= #replacements do
+ if replacements[i].code then
+ table.remove(replacements, i)
+ else
+ i = i + 1
end
- else
- callback(format_error)
- return
+ end
+ if self.options.ignore_errors then
+ format_error = nil
end
end
@@ -150,13 +149,13 @@ return {
table.insert(formatted_lines, start_lnum, new_lines[i])
end
end
- callback(nil, formatted_lines)
+ callback(format_error, formatted_lines)
end
local num_format = 0
local formatter_cb = function(err, idx, start_lnum, end_lnum, new_lines)
if err then
- format_error = err
+ format_error = errors.coalesce(format_error, err)
replacements[idx] = err
else
replacements[idx] = { start_lnum, end_lnum, new_lines }