summaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/conform/runner.lua14
1 files changed, 8 insertions, 6 deletions
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua
index b3a1e61..1fbb33c 100644
--- a/lua/conform/runner.lua
+++ b/lua/conform/runner.lua
@@ -33,17 +33,19 @@ M.build_cmd = function(formatter_name, ctx, config)
end
end
- local cwd
- if config.cwd then
- cwd = config.cwd(config, ctx)
+ local function compute_relative_filepath()
+ local cwd
+ if config.cwd then
+ cwd = config.cwd(config, ctx)
+ end
+ return fs.relative_path(cwd or vim.fn.getcwd(), ctx.filename)
end
- local relative_filename = fs.relative_path(cwd or vim.fn.getcwd(), ctx.filename)
if type(args) == "string" then
local interpolated = args
:gsub("$FILENAME", ctx.filename)
:gsub("$DIRNAME", ctx.dirname)
- :gsub("$RELATIVE_FILEPATH", relative_filename)
+ :gsub("$RELATIVE_FILEPATH", compute_relative_filepath)
return command .. " " .. interpolated
else
local cmd = { command }
@@ -54,7 +56,7 @@ M.build_cmd = function(formatter_name, ctx, config)
elseif v == "$DIRNAME" then
v = ctx.dirname
elseif v == "$RELATIVE_FILEPATH" then
- v = relative_filename
+ v = compute_relative_filepath()
end
table.insert(cmd, v)
end