diff options
| author | William Boman <william@redwill.se> | 2023-03-05 02:55:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-05 02:55:51 +0100 |
| commit | c79ba10813ab6977e13f1c7321b3c2c3ae792afa (patch) | |
| tree | dde3af5137596d60e5e9796e57771f2ff387c44d /lua | |
| parent | refactor(expr): better handling of nil values (#1056) (diff) | |
| download | mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.tar mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.tar.gz mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.tar.bz2 mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.tar.lz mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.tar.xz mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.tar.zst mason-c79ba10813ab6977e13f1c7321b3c2c3ae792afa.zip | |
refactor(powershell): remove .script and fix fast API error (#1057)
Calling vim.fn.executable in the module scope has potential to error
if the module is required outside of the main loop.
Diffstat (limited to '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" }), |
