Skip to content

Commit bf94626

Browse files
authored
feat: add pre and post formatter autocmds (#623)
* Pre and post formatter hooks * Ensure post hook is called Also changes the event formatter data to only contain the name of the formatter * Standardise autocommand names
1 parent 3c14c39 commit bf94626

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lua/conform/runner.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ local last_run_errored = {}
298298
---@param callback fun(err?: conform.Error, output?: string[])
299299
---@return integer? job_id
300300
local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, callback)
301+
local autocmd_data = {
302+
formatter = {
303+
name = formatter.name,
304+
},
305+
}
306+
vim.api.nvim_exec_autocmds("User", {
307+
pattern = "ConformFormatPre",
308+
data = autocmd_data,
309+
})
301310
log.info("Run %s on %s", formatter.name, vim.api.nvim_buf_get_name(bufnr))
302311
log.trace("Input lines: %s", input_lines)
303312
callback = util.wrap_callback(callback, function(err)
@@ -309,6 +318,11 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
309318
else
310319
last_run_errored[formatter.name] = false
311320
end
321+
autocmd_data["err"] = err
322+
vim.api.nvim_exec_autocmds("User", {
323+
pattern = "ConformFormatPost",
324+
data = autocmd_data,
325+
})
312326
end)
313327
if config.format then
314328
local err_string_cb = function(err, ...)

0 commit comments

Comments
 (0)