diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2023-12-06 22:20:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 22:20:29 -0800 |
commit | 659838ff4244ef6af095395ce68aaaf99fa8e696 (patch) | |
tree | b92754f2de1a225187769ed2c30e01a3ea703b3c /lua/conform/runner.lua | |
parent | 8d0421a11b2944c6c059e0936a95182972921c30 (diff) |
refactor!: formatter config functions take self as first argument (#233)
This is a breaking API change, but there is a shim in place that will keep existing functions working, just with a warning notification. Most people should not encounter this at all. For anyone overriding a formatter config value with a function that takes `(ctx)` as the parameter, it will need to be updated to take `(self, ctx)`.
Diffstat (limited to 'lua/conform/runner.lua')
-rw-r--r-- | lua/conform/runner.lua | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index 9571588..8137ad1 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -8,25 +8,26 @@ local M = {} ---@class (exact) conform.RunOpts ---@field exclusive boolean If true, ensure only a single formatter is running per buffer +---@param formatter_name string ---@param ctx conform.Context ---@param config conform.JobFormatterConfig ---@return string|string[] -M.build_cmd = function(ctx, config) +M.build_cmd = function(formatter_name, ctx, config) local command = config.command if type(command) == "function" then - command = command(ctx) + command = util.compat_call_with_self(formatter_name, config, command, ctx) end ---@type string|string[] local args = {} if ctx.range and config.range_args then - ---@cast ctx conform.RangeContext - args = config.range_args(ctx) + args = util.compat_call_with_self(formatter_name, config, config.range_args, ctx) elseif config.args then - if type(config.args) == "function" then - args = config.args(ctx) + local computed_args = config.args + if type(computed_args) == "function" then + args = util.compat_call_with_self(formatter_name, config, computed_args, ctx) else ---@diagnostic disable-next-line: cast-local-type - args = config.args + args = computed_args end end @@ -262,14 +263,14 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c return end ---@cast config conform.JobFormatterConfig - local cmd = M.build_cmd(ctx, config) + local cmd = M.build_cmd(formatter.name, ctx, config) local cwd = nil if config.cwd then - cwd = config.cwd(ctx) + cwd = util.compat_call_with_self(formatter.name, config, config.cwd, ctx) end local env = config.env if type(env) == "function" then - env = env(ctx) + env = util.compat_call_with_self(formatter.name, config, env, ctx) end local buffer_text |