From b1e0f89f4c85a0767a76ff3e0db4c888b6ac3002 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 25 Nov 2021 06:55:18 +0100 Subject: fix(windows): unset PSMODULEPATH before invoking powershell scripts (#278) --- lua/nvim-lsp-installer/installers/context.lua | 1 + lua/nvim-lsp-installer/installers/shell.lua | 4 +++- lua/nvim-lsp-installer/process.lua | 10 +++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua index 97f200d5..bdb993a5 100644 --- a/lua/nvim-lsp-installer/installers/context.lua +++ b/lua/nvim-lsp-installer/installers/context.lua @@ -44,6 +44,7 @@ local function fetch(url, callback) process.lazy_spawn("powershell.exe", { args = { "-NoProfile", "-Command", table.concat(ps_script, ";") }, stdio_sink = stdio.sink, + env = process.graft_env({}, { "PSMODULEPATH" }), }) ) end diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua index 33d603a9..34cfc524 100644 --- a/lua/nvim-lsp-installer/installers/shell.lua +++ b/lua/nvim-lsp-installer/installers/shell.lua @@ -11,7 +11,9 @@ local function shell(opts) args = opts.args, cwd = context.install_dir, stdio_sink = context.stdio_sink, - env = process.graft_env(opts.env or {}), + env = process.graft_env(opts.env or {}, { + "PSMODULEPATH", -- https://github.com/williamboman/nvim-lsp-installer/issues/271 + }), }, callback) if stdio then diff --git a/lua/nvim-lsp-installer/process.lua b/lua/nvim-lsp-installer/process.lua index 7fe3625c..9316fd38 100644 --- a/lua/nvim-lsp-installer/process.lua +++ b/lua/nvim-lsp-installer/process.lua @@ -47,15 +47,19 @@ end ---Merges the provided env param with the user's full environent. Provided env has precedence. ---@param env table -function M.graft_env(env) +---@param excluded_var_names string[]|nil +function M.graft_env(env, excluded_var_names) + local excluded_var_names_set = excluded_var_names and Data.set_of(excluded_var_names) or {} local merged_env = {} for key, val in pairs(initial_environ) do - if env[key] == nil then + if not excluded_var_names_set[key] and env[key] == nil then merged_env[#merged_env + 1] = key .. "=" .. val end end for key, val in pairs(env) do - merged_env[#merged_env + 1] = key .. "=" .. val + if not excluded_var_names_set[key] then + merged_env[#merged_env + 1] = key .. "=" .. val + end end return merged_env end -- cgit v1.3