diff options
Diffstat (limited to 'lua/mason-core/managers/powershell/init.lua')
| -rw-r--r-- | lua/mason-core/managers/powershell/init.lua | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/lua/mason-core/managers/powershell/init.lua b/lua/mason-core/managers/powershell/init.lua index 35261ab9..8f796128 100644 --- a/lua/mason-core/managers/powershell/init.lua +++ b/lua/mason-core/managers/powershell/init.lua @@ -1,7 +1,7 @@ local a = require "mason-core.async" -local async_uv = require "mason-core.async.uv" local spawn = require "mason-core.spawn" local process = require "mason-core.process" +local _ = require "mason-core.functional" local M = {} @@ -11,31 +11,18 @@ local PWSHOPT = { error_action_preference = [[ $ErrorActionPreference = "Stop"; ]], } -local powershell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell" - ----@param script string ----@param opts SpawnArgs? ----@param custom_spawn JobSpawn? -function M.script(script, opts, custom_spawn) - opts = opts or {} - ---@type JobSpawn - local spawner = custom_spawn or spawn - return spawner[powershell](vim.tbl_extend("keep", { - "-NoProfile", - on_spawn = a.scope(function(_, stdio) - local stdin = stdio[1] - async_uv.write(stdin, PWSHOPT.error_action_preference) - async_uv.write(stdin, PWSHOPT.progress_preference) - async_uv.write(stdin, PWSHOPT.security_protocol) - async_uv.write(stdin, script) - async_uv.write(stdin, "\n") - async_uv.shutdown(stdin) - async_uv.close(stdin) - end), - env_raw = process.graft_env(opts.env or {}, { "PSMODULEPATH" }), - }, opts)) -end +local powershell = _.lazy(function() + if vim.in_fast_event() then + a.scheduler() + end + if vim.fn.executable "pwsh" == 1 then + return "pwsh" + else + return "powershell" + end +end) +---@async ---@param command string ---@param opts SpawnArgs? ---@param custom_spawn JobSpawn? @@ -43,8 +30,9 @@ function M.command(command, opts, custom_spawn) opts = opts or {} ---@type JobSpawn local spawner = custom_spawn or spawn - return spawner[powershell](vim.tbl_extend("keep", { + return spawner[powershell()](vim.tbl_extend("keep", { "-NoProfile", + "-NonInteractive", "-Command", PWSHOPT.error_action_preference .. PWSHOPT.progress_preference .. PWSHOPT.security_protocol .. command, env_raw = process.graft_env(opts.env or {}, { "PSMODULEPATH" }), |
