From 915553fe1d6d4721970b038f82cd6a550468b945 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Wed, 9 Aug 2023 19:31:08 -0500 Subject: [PATCH 1/3] feat(#44): support env var specification --- lua/guard/filetype.lua | 14 ++++++++++++++ lua/guard/spawn.lua | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/guard/filetype.lua b/lua/guard/filetype.lua index c9a68e83..c9c476f5 100644 --- a/lua/guard/filetype.lua +++ b/lua/guard/filetype.lua @@ -42,6 +42,20 @@ local function box() return self end + function tbl:env(...) + local tool = self[current][#self[current]] + if type(tool) == 'string' then + tool = current == 'format' and require('guard.tools.formatter')[tool] + or require('guard.tools.linter.' .. tool) + end + tool.env = {} + local env = vim.tbl_extend('force', vim.uv.os_environ(), ... or {}) + for k, v in pairs(env) do + table.insert(tool.env, ('%s=%s'):format(k, tostring(v))) + end + return self + end + function tbl:key_alias(key) local _t = { ['lint'] = function() diff --git a/lua/guard/spawn.lua b/lua/guard/spawn.lua index b4fdfad2..2b8d0926 100644 --- a/lua/guard/spawn.lua +++ b/lua/guard/spawn.lua @@ -37,7 +37,7 @@ local function spawn(opt) stdio = { stdin, stdout, stderr }, args = opt.args, cwd = opt.cwd, - env = opt.env_flat or nil, + env = opt.env, }, function(exit_code, signal) if timeout then timeout:stop() From c0ebc6c66d16d3679d7170704e84dcc74000ff64 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 10 Aug 2023 18:02:35 -0500 Subject: [PATCH 2/3] fix(env): validate env parameter spec --- lua/guard/filetype.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/guard/filetype.lua b/lua/guard/filetype.lua index c9c476f5..db5decb3 100644 --- a/lua/guard/filetype.lua +++ b/lua/guard/filetype.lua @@ -42,14 +42,20 @@ local function box() return self end - function tbl:env(...) + function tbl:env(env) + vim.validate({ + env = { env, 'table' } + }) + if vim.tbl_count(env) == 0 then + return self + end local tool = self[current][#self[current]] if type(tool) == 'string' then tool = current == 'format' and require('guard.tools.formatter')[tool] or require('guard.tools.linter.' .. tool) end tool.env = {} - local env = vim.tbl_extend('force', vim.uv.os_environ(), ... or {}) + env = vim.tbl_extend('force', vim.uv.os_environ(), env or {}) for k, v in pairs(env) do table.insert(tool.env, ('%s=%s'):format(k, tostring(v))) end From 2ce1aa195fa62257abaca718e1b6913f8c59cf1c Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrett-ruth@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:53:57 -0500 Subject: [PATCH 3/3] Update lua/guard/filetype.lua Co-authored-by: Raphael --- lua/guard/filetype.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/guard/filetype.lua b/lua/guard/filetype.lua index db5decb3..508d43dc 100644 --- a/lua/guard/filetype.lua +++ b/lua/guard/filetype.lua @@ -57,7 +57,7 @@ local function box() tool.env = {} env = vim.tbl_extend('force', vim.uv.os_environ(), env or {}) for k, v in pairs(env) do - table.insert(tool.env, ('%s=%s'):format(k, tostring(v))) + tool.env[#tool.env + 1 ] = ('%s=%s'):format(k, tostring(v)) end return self end