diff options
author | Steven Arcangeli <stevearc@stevearc.com> | 2024-06-10 17:42:58 -0500 |
---|---|---|
committer | Steven Arcangeli <stevearc@stevearc.com> | 2024-06-10 17:42:58 -0500 |
commit | a28a4255e5c5631ee9c58537592fca05447f0503 (patch) | |
tree | 468942221e73b255eb14f60dc5d34aaa0739816f | |
parent | cf562dd160c27a7fc5342dfce7e1227746dd3aaa (diff) |
feat: formatter override can use (#453)
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | lua/conform/types.lua | 1 | ||||
-rw-r--r-- | lua/conform/util.lua | 2 |
3 files changed, 7 insertions, 1 deletions
@@ -515,9 +515,12 @@ require("conform").setup({ }, -- Set to false to disable merging the config with the base definition inherit = true, - -- When inherit = true, add these additional arguments to the command. + -- When inherit = true, add these additional arguments to the beginning of the command. -- This can also be a function, like args prepend_args = { "--use-tabs" }, + -- When inherit = true, add these additional arguments to the end of the command. + -- This can also be a function, like args + append_args = { "--trailing-comma" }, }, -- These can also be a function that returns the formatter other_formatter = function(bufnr) diff --git a/lua/conform/types.lua b/lua/conform/types.lua index bd98426..f68c2de 100644 --- a/lua/conform/types.lua +++ b/lua/conform/types.lua @@ -35,6 +35,7 @@ ---@field inherit? boolean ---@field command? string|fun(self: conform.FormatterConfig, ctx: conform.Context): string ---@field prepend_args? string|string[]|fun(self: conform.FormatterConfig, ctx: conform.Context): string|string[] +---@field append_args? string|string[]|fun(self: conform.FormatterConfig, ctx: conform.Context): string|string[] ---@field format? fun(self: conform.LuaFormatterConfig, ctx: conform.Context, lines: string[], callback: fun(err: nil|string, new_lines: nil|string[])) Mutually exclusive with command ---@field options? table diff --git a/lua/conform/util.lua b/lua/conform/util.lua index 1222af2..4f9b01b 100644 --- a/lua/conform/util.lua +++ b/lua/conform/util.lua @@ -170,6 +170,8 @@ M.merge_formatter_configs = function(config, override) local ret = vim.tbl_deep_extend("force", config, override) if override.prepend_args then M.add_formatter_args(ret, override.prepend_args, { append = false }) + elseif override.append_args then + M.add_formatter_args(ret, override.append_args, { append = true }) end return ret end |