diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2023-10-15 16:18:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-15 16:18:08 -0700 |
commit | 7027ebbd772e2d3593f7dd566dea06d2d20622ee (patch) | |
tree | b78bbe24dda9cd7e1272bce6c699b5e576d76a66 /lua/conform/util.lua | |
parent | 9b5fbddfca5080c6961dabafb3f0a6ef7e2fc18a (diff) |
feat!: merge configs in conform.formatters with defaults (#140)
This breaking change should make it significantly easier to modify formatters. While I expect 99% of configs to be backwards-compatible, this can still potentially cause problems. If you:
* define a formatter in the `formatters` option
* that has the same name as a built-in formatter
* and omits a property from the original formatter (e.g. leaves out `range_args` or `cwd`)
Then you may encounter breaking behavior from this commit, because now your config definition will be merged with the built-in definition, and so will inherit those omitted properties. This config merging behavior can be opted-out of by adding `inherit = false` to your formatter config.
Diffstat (limited to 'lua/conform/util.lua')
-rw-r--r-- | lua/conform/util.lua | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lua/conform/util.lua b/lua/conform/util.lua index 8a0073a..bbb711a 100644 --- a/lua/conform/util.lua +++ b/lua/conform/util.lua @@ -156,6 +156,17 @@ M.add_formatter_args = function(formatter, extra_args, opts) end end +---@param config conform.FormatterConfig +---@param override conform.FormatterConfigOverride +---@return conform.FormatterConfig +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 }) + end + return ret +end + ---@param bufnr integer ---@return integer M.buf_get_changedtick = function(bufnr) |