diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2023-09-15 08:35:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 08:35:28 -0700 |
commit | fbb18a5b92e2f11aaaef379d74d4a1132a138cb3 (patch) | |
tree | 8a9193f0be376d9317f447790f23a5a0f1554a7c /lua/conform/runner.lua | |
parent | 3f855f3675a22cb52a6754f3ab073d13528ce0ca (diff) |
feat: allow running commands in a shell (#49)
Diffstat (limited to 'lua/conform/runner.lua')
-rw-r--r-- | lua/conform/runner.lua | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index ff8fbef..fff638b 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -48,12 +48,13 @@ end ---@param ctx conform.Context ---@param config conform.FormatterConfig +---@return string|string[] M.build_cmd = function(ctx, config) local command = config.command if type(command) == "function" then command = command(ctx) end - local cmd = { command } + ---@type string|string[] local args = {} if ctx.range and config.range_args then ---@cast ctx conform.RangeContext @@ -67,16 +68,22 @@ M.build_cmd = function(ctx, config) end end - ---@diagnostic disable-next-line: param-type-mismatch - for _, v in ipairs(args) do - if v == "$FILENAME" then - v = ctx.filename - elseif v == "$DIRNAME" then - v = ctx.dirname + if type(args) == "string" then + local interpolated = args:gsub("$FILENAME", ctx.filename):gsub("$DIRNAME", ctx.dirname) + return command .. " " .. interpolated + else + local cmd = { command } + ---@diagnostic disable-next-line: param-type-mismatch + for _, v in ipairs(args) do + if v == "$FILENAME" then + v = ctx.filename + elseif v == "$DIRNAME" then + v = ctx.dirname + end + table.insert(cmd, v) end - table.insert(cmd, v) + return cmd end - return cmd end ---@param range? conform.Range |