diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2024-03-15 08:56:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-15 08:56:03 -0700 |
commit | b05962622d3eebeefe6b1a90deb9eb86947e0349 (patch) | |
tree | 1da4f07fcc096c0071e08f3e5dd90e7b2c6394b4 /lua | |
parent | a605ce4b2db397c84ae6fa8bcfc85f00b985bc73 (diff) |
feat: add formatter config option to change name of temporary file (#332)
Diffstat (limited to 'lua')
-rw-r--r-- | lua/conform/init.lua | 1 | ||||
-rw-r--r-- | lua/conform/runner.lua | 7 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lua/conform/init.lua b/lua/conform/init.lua index e1f3544..2412445 100644 --- a/lua/conform/init.lua +++ b/lua/conform/init.lua @@ -14,6 +14,7 @@ local M = {} ---@field cwd? fun(self: conform.JobFormatterConfig, ctx: conform.Context): nil|string ---@field require_cwd? boolean When cwd is not found, don't run the formatter (default false) ---@field stdin? boolean Send buffer contents to stdin (default true) +---@field tmpfile_format? string When stdin=false, use this format for temporary files (default ".conform.$RANDOM.$FILENAME") ---@field condition? fun(self: conform.JobFormatterConfig, ctx: conform.Context): boolean ---@field exit_codes? integer[] Exit codes that indicate success (default {0}) ---@field env? table<string, any>|fun(self: conform.JobFormatterConfig, ctx: conform.Context): table<string, any> diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index 2810948..ff58570 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -442,8 +442,13 @@ M.build_context = function(bufnr, config, range) end if not config.stdin then + local template = config.tmpfile_format + if not template then + template = ".conform.$RANDOM.$FILENAME" + end local basename = vim.fs.basename(filename) - local tmpname = string.format(".conform.%d.%s", math.random(1000000, 9999999), basename) + local tmpname = + template:gsub("$FILENAME", basename):gsub("$RANDOM", tostring(math.random(1000000, 9999999))) local parent = vim.fs.dirname(filename) filename = fs.join(parent, tmpname) end |