diff options
author | Steven Arcangeli <stevearc@stevearc.com> | 2024-05-13 11:14:50 -0600 |
---|---|---|
committer | Steven Arcangeli <stevearc@stevearc.com> | 2024-05-13 11:14:53 -0600 |
commit | 40faaa8fdd0b7f98f58070943306fd93abb5caad (patch) | |
tree | 4a471ff19b78bf89b2bfbdc2714f5b871864af84 /lua/conform | |
parent | 95f2cf0181a45c29f804a2c557bcce39406d4901 (diff) |
fix: lazily compute relative filepath
Diffstat (limited to 'lua/conform')
-rw-r--r-- | lua/conform/runner.lua | 14 |
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 |