Skip to content

Commit

Permalink
feat: format_on_save functions can return a callback as the second value
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Sep 15, 2023
1 parent d3fe431 commit 1a568c6
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lua/conform/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,18 @@ M.setup = function(opts)
pattern = "*",
group = aug,
callback = function(args)
local format_args = opts.format_on_save
local format_args, callback = opts.format_on_save, nil
if type(format_args) == "function" then
format_args = format_args(args.buf)
format_args, callback = format_args(args.buf)
end
if format_args then
M.format(vim.tbl_deep_extend("force", format_args, {
buf = args.buf,
async = false,
}))
M.format(
vim.tbl_deep_extend("force", format_args, {
buf = args.buf,
async = false,
}),
callback
)
end
end,
})
Expand All @@ -109,9 +112,9 @@ M.setup = function(opts)
if vim.b[args.buf].conform_applying_formatting then
return
end
local format_args = opts.format_after_save
local format_args, callback = opts.format_after_save, nil
if type(format_args) == "function" then
format_args = format_args(args.buf)
format_args, callback = format_args(args.buf)
end
if format_args then
M.format(
Expand All @@ -127,6 +130,9 @@ M.setup = function(opts)
vim.b[args.buf].conform_applying_formatting = false
end)
end
if callback then
callback(err)
end
end
)
end
Expand Down

0 comments on commit 1a568c6

Please sign in to comment.