aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-12-26 17:38:44 +0100
committerGitHub <noreply@github.com>2022-12-26 17:38:44 +0100
commite3d469e7712b81b752cb63813fc7c79e18df279d (patch)
tree354e52b175a5c138f99817bee8aba43f86302943 /lua
parentrefactor(installer): write debug log file after installation finishes (#806) (diff)
downloadmason-e3d469e7712b81b752cb63813fc7c79e18df279d.tar
mason-e3d469e7712b81b752cb63813fc7c79e18df279d.tar.gz
mason-e3d469e7712b81b752cb63813fc7c79e18df279d.tar.bz2
mason-e3d469e7712b81b752cb63813fc7c79e18df279d.tar.lz
mason-e3d469e7712b81b752cb63813fc7c79e18df279d.tar.xz
mason-e3d469e7712b81b752cb63813fc7c79e18df279d.tar.zst
mason-e3d469e7712b81b752cb63813fc7c79e18df279d.zip
feat(powershell): set $ErrorActionPreference = "Stop"; (#807)
Also write to stdin pipe asynchronously.
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-core/managers/powershell/init.lua26
1 files changed, 15 insertions, 11 deletions
diff --git a/lua/mason-core/managers/powershell/init.lua b/lua/mason-core/managers/powershell/init.lua
index 161ee4b2..786645db 100644
--- a/lua/mason-core/managers/powershell/init.lua
+++ b/lua/mason-core/managers/powershell/init.lua
@@ -1,3 +1,4 @@
+local a = require "mason-core.async"
local spawn = require "mason-core.spawn"
local process = require "mason-core.process"
@@ -6,12 +7,13 @@ local M = {}
local PWSHOPT = {
progress_preference = [[ $ProgressPreference = 'SilentlyContinue'; ]], -- https://stackoverflow.com/a/63301751
security_protocol = [[ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ]],
+ error_action_preference = [[ $ErrorActionPreference = "Stop"; ]],
}
local powershell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell"
---@param script string
----@param opts JobSpawnOpts?
+---@param opts SpawnArgs?
---@param custom_spawn JobSpawn?
function M.script(script, opts, custom_spawn)
opts = opts or {}
@@ -19,19 +21,21 @@ function M.script(script, opts, custom_spawn)
local spawner = custom_spawn or spawn
return spawner[powershell](vim.tbl_extend("keep", {
"-NoProfile",
- on_spawn = function(_, stdio)
+ on_spawn = a.scope(function(_, stdio)
local stdin = stdio[1]
- stdin:write(PWSHOPT.progress_preference)
- stdin:write(PWSHOPT.security_protocol)
- stdin:write(script)
- stdin:close()
- end,
+ local write = a.promisify(vim.loop.write)
+ write(stdin, PWSHOPT.error_action_preference)
+ write(stdin, PWSHOPT.progress_preference)
+ write(stdin, PWSHOPT.security_protocol)
+ write(stdin, script)
+ stdin:shutdown()
+ end),
env_raw = process.graft_env(opts.env or {}, { "PSMODULEPATH" }),
- }, opts) --[[@as JobSpawnOpts]])
+ }, opts))
end
---@param command string
----@param opts JobSpawnOpts?
+---@param opts SpawnArgs?
---@param custom_spawn JobSpawn?
function M.command(command, opts, custom_spawn)
opts = opts or {}
@@ -40,9 +44,9 @@ function M.command(command, opts, custom_spawn)
return spawner[powershell](vim.tbl_extend("keep", {
"-NoProfile",
"-Command",
- PWSHOPT.progress_preference .. PWSHOPT.security_protocol .. command,
+ PWSHOPT.error_action_preference .. PWSHOPT.progress_preference .. PWSHOPT.security_protocol .. command,
env_raw = process.graft_env(opts.env or {}, { "PSMODULEPATH" }),
- }, opts) --[[@as JobSpawnOpts]])
+ }, opts))
end
return M