diff options
| author | William Boman <william@redwill.se> | 2022-12-26 17:43:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-26 17:43:01 +0100 |
| commit | 21a2475da458e97be798bdc9261da24460da5c65 (patch) | |
| tree | 7138d6b8d3badd52b738d773449c9a388a1af540 /lua | |
| parent | feat(powershell): set $ErrorActionPreference = "Stop"; (#807) (diff) | |
| download | mason-21a2475da458e97be798bdc9261da24460da5c65.tar mason-21a2475da458e97be798bdc9261da24460da5c65.tar.gz mason-21a2475da458e97be798bdc9261da24460da5c65.tar.bz2 mason-21a2475da458e97be798bdc9261da24460da5c65.tar.lz mason-21a2475da458e97be798bdc9261da24460da5c65.tar.xz mason-21a2475da458e97be798bdc9261da24460da5c65.tar.zst mason-21a2475da458e97be798bdc9261da24460da5c65.zip | |
refactor: interact with libuv pipes in async context (#808)
Also now properly close pipes (shutdown -> close).
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason-core/async/uv.lua | 3 | ||||
| -rw-r--r-- | lua/mason-core/fetch.lua | 11 | ||||
| -rw-r--r-- | lua/mason-core/managers/powershell/init.lua | 13 | ||||
| -rw-r--r-- | lua/mason-registry/r-languageserver/init.lua | 12 | ||||
| -rw-r--r-- | lua/mason/health/init.lua | 9 |
5 files changed, 30 insertions, 18 deletions
diff --git a/lua/mason-core/async/uv.lua b/lua/mason-core/async/uv.lua index f3d25b04..9a998be5 100644 --- a/lua/mason-core/async/uv.lua +++ b/lua/mason-core/async/uv.lua @@ -11,6 +11,9 @@ local M = setmetatable({}, { return M ---@alias UvMethod +---| '"write"' +---| '"shutdown"' +---| '"close"' ---| '"fs_close"' ---| '"fs_open"' ---| '"fs_read"' diff --git a/lua/mason-core/fetch.lua b/lua/mason-core/fetch.lua index fbb755b8..a6db7c6b 100644 --- a/lua/mason-core/fetch.lua +++ b/lua/mason-core/fetch.lua @@ -1,3 +1,5 @@ +local a = require "mason-core.async" +local async_uv = require "mason-core.async.uv" local log = require "mason-core.log" local platform = require "mason-core.platform" local Result = require "mason-core.result" @@ -105,14 +107,15 @@ local function fetch(url, opts) opts.data and { "-d", "@-" } or vim.NIL, opts.out_file and { "-o", opts.out_file } or vim.NIL, url, - on_spawn = function(_, stdio) + on_spawn = a.scope(function(_, stdio) local stdin = stdio[1] if opts.data then log.trace("Writing stdin to curl", opts.data) - stdin:write(opts.data) + async_uv.write(stdin, opts.data) end - stdin:close() - end, + async_uv.shutdown(stdin) + async_uv.close(stdin) + end), } end diff --git a/lua/mason-core/managers/powershell/init.lua b/lua/mason-core/managers/powershell/init.lua index 786645db..4133df23 100644 --- a/lua/mason-core/managers/powershell/init.lua +++ b/lua/mason-core/managers/powershell/init.lua @@ -1,4 +1,5 @@ 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" @@ -23,12 +24,12 @@ function M.script(script, opts, custom_spawn) "-NoProfile", on_spawn = a.scope(function(_, stdio) local stdin = stdio[1] - 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() + 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.shutdown(stdin) + async_uv.close(stdin) end), env_raw = process.graft_env(opts.env or {}, { "PSMODULEPATH" }), }, opts)) diff --git a/lua/mason-registry/r-languageserver/init.lua b/lua/mason-registry/r-languageserver/init.lua index fd7d0292..80376aee 100644 --- a/lua/mason-registry/r-languageserver/init.lua +++ b/lua/mason-registry/r-languageserver/init.lua @@ -1,6 +1,7 @@ +local a = require "mason-core.async" +local async_uv = require "mason-core.async.uv" local Pkg = require "mason-core.package" local path = require "mason-core.path" -local github_client = require "mason-core.managers.github.client" local github = require "mason-core.managers.github" ---@param install_dir string @@ -66,11 +67,12 @@ return Pkg.new { source.with_receipt() ctx.spawn.R { "--no-save", - on_spawn = function(_, stdio) + on_spawn = a.scope(function(_, stdio) local stdin = stdio[1] - stdin:write(create_install_script(ctx.cwd:get(), source.release)) - stdin:close() - end, + async_uv.write(create_install_script(ctx.cwd:get(), source.release)) + async_uv.close(stdin) + async_uv.shutdown(stdin) + end), } ctx.fs:write_file("server.R", create_server_script(ctx.package:get_install_path())) diff --git a/lua/mason/health/init.lua b/lua/mason/health/init.lua index 0e33911d..0ff8a787 100644 --- a/lua/mason/health/init.lua +++ b/lua/mason/health/init.lua @@ -1,5 +1,6 @@ local health = vim.health or require "health" local a = require "mason-core.async" +local async_uv = require "mason-core.async.uv" local platform = require "mason-core.platform" local github_client = require "mason-core.managers.github.client" local _ = require "mason-core.functional" @@ -72,10 +73,12 @@ local function mk_healthcheck(callback) local healthcheck_result = spawn [opts.cmd]({ opts.args, - on_spawn = function(_, stdio) + on_spawn = a.scope(function(_, stdio) local stdin = stdio[1] - stdin:close() -- some processes (`sh` for example) will endlessly read from stdin, so we close it immediately - end, + -- some processes (`sh` for example) will endlessly read from stdin, so we close it immediately + async_uv.close(stdin) + async_uv.shutdown(stdin) + end), }) :map(parse_version) :map(function(version) |
