From 40faaa8fdd0b7f98f58070943306fd93abb5caad Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Mon, 13 May 2024 11:14:50 -0600 Subject: fix: lazily compute relative filepath --- lua/conform/runner.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lua') 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 -- cgit v1.2.3-70-g09d2