From 03a37f1b53d83af7aee10fc3ffee9f3a05d09e2e Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Tue, 29 Aug 2023 16:19:34 -0700 Subject: feat: add support for environment variables (#8) --- lua/conform/init.lua | 1 + lua/conform/runner.lua | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'lua/conform') 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|fun(ctx: conform.Context): table ---@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", -- cgit v1.2.3-70-g09d2