aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2024-03-01 14:00:59 -0800
committerSteven Arcangeli <stevearc@stevearc.com>2024-03-01 14:01:08 -0800
commit8d91cf1fb5c53860f137439e2b4cb27cbe9f6a22 (patch)
treec2246dda1ae4776ce17ae43710af825c658d45e2 /lua
parent2a769b950526acf62a71de89b876d14862988ee5 (diff)
cleanup: remove backwards compatability shim
Diffstat (limited to 'lua')
-rw-r--r--lua/conform/init.lua10
-rw-r--r--lua/conform/runner.lua11
-rw-r--r--lua/conform/util.lua46
3 files changed, 13 insertions, 54 deletions
diff --git a/lua/conform/init.lua b/lua/conform/init.lua
index db0e939..02d8f7a 100644
--- a/lua/conform/init.lua
+++ b/lua/conform/init.lua
@@ -657,21 +657,21 @@ M.get_formatter_info = function(formatter, bufnr)
local command = config.command
if type(command) == "function" then
- command = util.compat_call_with_self(formatter, config, command, ctx)
+ ---@cast config conform.JobFormatterConfig
+ command = command(config, ctx)
end
if vim.fn.executable(command) == 0 then
available = false
available_msg = "Command not found"
- elseif
- config.condition and not util.compat_call_with_self(formatter, config, config.condition, ctx)
- then
+ elseif config.condition and not config.condition(config, ctx) then
available = false
available_msg = "Condition failed"
end
local cwd = nil
if config.cwd then
- cwd = util.compat_call_with_self(formatter, config, config.cwd, ctx)
+ ---@cast config conform.JobFormatterConfig
+ cwd = config.cwd(config, ctx)
if available and not cwd and config.require_cwd then
available = false
available_msg = "Root directory not found"
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua
index 725e824..2810948 100644
--- a/lua/conform/runner.lua
+++ b/lua/conform/runner.lua
@@ -16,16 +16,17 @@ local M = {}
M.build_cmd = function(formatter_name, ctx, config)
local command = config.command
if type(command) == "function" then
- command = util.compat_call_with_self(formatter_name, config, command, ctx)
+ command = command(config, ctx)
end
---@type string|string[]
local args = {}
if ctx.range and config.range_args then
- args = util.compat_call_with_self(formatter_name, config, config.range_args, ctx)
+ ---@cast ctx conform.RangeContext
+ args = config.range_args(config, ctx)
elseif config.args then
local computed_args = config.args
if type(computed_args) == "function" then
- args = util.compat_call_with_self(formatter_name, config, computed_args, ctx)
+ args = computed_args(config, ctx)
else
---@diagnostic disable-next-line: cast-local-type
args = computed_args
@@ -279,11 +280,11 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
local cmd = M.build_cmd(formatter.name, ctx, config)
local cwd = nil
if config.cwd then
- cwd = util.compat_call_with_self(formatter.name, config, config.cwd, ctx)
+ cwd = config.cwd(config, ctx)
end
local env = config.env
if type(env) == "function" then
- env = util.compat_call_with_self(formatter.name, config, env, ctx)
+ env = env(config, ctx)
end
local buffer_text
diff --git a/lua/conform/util.lua b/lua/conform/util.lua
index 0ff54de..e967918 100644
--- a/lua/conform/util.lua
+++ b/lua/conform/util.lua
@@ -115,10 +115,10 @@ M.extend_args = function(args, extra_args, opts)
opts = opts or {}
return function(self, ctx)
if type(args) == "function" then
- args = M.compat_call_with_self("unknown", self, args, ctx)
+ args = args(self, ctx)
end
if type(extra_args) == "function" then
- extra_args = M.compat_call_with_self("unknown", self, extra_args, ctx)
+ extra_args = extra_args(self, ctx)
end
if type(args) == "string" then
if type(extra_args) ~= "string" then
@@ -183,46 +183,4 @@ M.buf_get_changedtick = function(bufnr)
end
end
----Returns true if the function takes no args or has self as the first arg
----@param name string
----@param fn function(...: any): T
----@return boolean
-local function has_self_arg(name, fn)
- local first_arg_name = nil
- debug.sethook(function()
- local info = debug.getinfo(3)
- if info.name ~= "pcall" then
- return
- end
- first_arg_name = debug.getlocal(2, 1)
- error()
- end, "c")
- pcall(fn)
- debug.sethook()
-
- return first_arg_name == "self" or first_arg_name == nil
-end
-
----@generic T
----@param formatter_name string
----@param self any
----@param fn fun(...: any): T
----@param ... any
----@return T
-M.compat_call_with_self = function(formatter_name, self, fn, ...)
- local has_self = has_self_arg(formatter_name, fn)
- if has_self then
- return fn(self, ...)
- else
- vim.notify_once(
- string.format(
- "[conform] formatter %s should take 'self' as the first argument for args, range_args, cwd, condition, and env functions (see :help conform-self-args)\nCompatibility will be dropped on 2024-03-01",
- formatter_name
- ),
- vim.log.levels.WARN
- )
- return fn(...)
- end
-end
-
return M