diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | doc/conform.txt | 4 | ||||
-rw-r--r-- | lua/conform/init.lua | 1 | ||||
-rw-r--r-- | lua/conform/runner.lua | 8 | ||||
-rw-r--r-- | tests/options_doc.lua | 4 |
5 files changed, 21 insertions, 0 deletions
@@ -250,6 +250,10 @@ require("conform").setup({ end, -- Exit codes that indicate success (default {0}) exit_codes = { 0, 1 }, + -- Environment variables. This can also be a function that returns a table. + env = { + VAR = "value", + }, }, -- These can also be a function that returns the formatter other_formatter = function() diff --git a/doc/conform.txt b/doc/conform.txt index 9542f63..854cfab 100644 --- a/doc/conform.txt +++ b/doc/conform.txt @@ -62,6 +62,10 @@ OPTIONS *conform-option end, -- Exit codes that indicate success (default {0}) exit_codes = { 0, 1 }, + -- Environment variables. This can also be a function that returns a table. + env = { + VAR = "value", + }, }, -- These can also be a function that returns the formatter other_formatter = function() diff --git a/lua/conform/init.lua b/lua/conform/init.lua index b2c3d31..d1a6849 100644 --- a/lua/conform/init.lua +++ b/lua/conform/init.lua @@ -16,6 +16,7 @@ local M = {} ---@field stdin? boolean Send buffer contents to stdin (default true) ---@field condition? fun(ctx: conform.Context): boolean ---@field exit_codes? integer[] Exit codes that indicate success (default {0}) +---@field env? table<string, any>|fun(ctx: conform.Context): table<string, any> ---@class (exact) conform.FileFormatterConfig : conform.FormatterConfig ---@field meta conform.FormatterMeta diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index 843dae1..2471ec2 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -104,6 +104,10 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, callbac if config.cwd then cwd = config.cwd(ctx) end + local env = config.env + if type(env) == "function" then + env = env(ctx) + end log.info("Run %s on %s", formatter.name, vim.api.nvim_buf_get_name(bufnr)) if not config.stdin then log.debug("Creating temp file %s", ctx.filename) @@ -121,11 +125,15 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, callbac if cwd then log.debug("Run CWD: %s", cwd) end + if env then + log.debug("Run ENV: %s", env) + end local stdout local stderr local exit_codes = config.exit_codes or { 0 } local jid = vim.fn.jobstart(cmd, { cwd = cwd, + env = env, stdout_buffered = true, stderr_buffered = true, stdin = config.stdin and "pipe" or "null", diff --git a/tests/options_doc.lua b/tests/options_doc.lua index f559d89..bdbf5df 100644 --- a/tests/options_doc.lua +++ b/tests/options_doc.lua @@ -48,6 +48,10 @@ require("conform").setup({ end, -- Exit codes that indicate success (default {0}) exit_codes = { 0, 1 }, + -- Environment variables. This can also be a function that returns a table. + env = { + VAR = "value", + }, }, -- These can also be a function that returns the formatter other_formatter = function() |