aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--doc/conform.txt4
-rw-r--r--lua/conform/init.lua1
-rw-r--r--lua/conform/runner.lua8
-rw-r--r--tests/options_doc.lua4
5 files changed, 21 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9bc8c24..8622df0 100644
--- a/README.md
+++ b/README.md
@@ -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()