aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/core/async/init.lua30
-rw-r--r--lua/nvim-lsp-installer/core/installer/context.lua15
-rw-r--r--lua/nvim-lsp-installer/core/installer/init.lua4
-rw-r--r--lua/nvim-lsp-installer/core/managers/powershell/init.lua2
4 files changed, 37 insertions, 14 deletions
diff --git a/lua/nvim-lsp-installer/core/async/init.lua b/lua/nvim-lsp-installer/core/async/init.lua
index 8537b909..27a4c7cb 100644
--- a/lua/nvim-lsp-installer/core/async/init.lua
+++ b/lua/nvim-lsp-installer/core/async/init.lua
@@ -147,6 +147,9 @@ local function oneshot_channel()
local saved_callback
return {
+ is_closed = function()
+ return has_sent
+ end,
send = function(...)
assert(not has_sent, "Oneshot channel can only send once.")
has_sent = true
@@ -174,32 +177,31 @@ exports.wait_all = function(suspend_fns)
do
local results = {}
- local threads = {}
+ local thread_cancellations = {}
local count = #suspend_fns
local completed = 0
- local function callback(i)
- return function(success, result)
+ for i, suspend_fn in ipairs(suspend_fns) do
+ thread_cancellations[i] = exports.run(suspend_fn, function(success, result)
+ completed = completed + 1
if not success then
- for _, cancel_thread in ipairs(threads) do
- cancel_thread()
+ if not channel.is_closed() then
+ for _, cancel_thread in ipairs(thread_cancellations) do
+ cancel_thread()
+ end
+ channel.send(false, result)
+ results = nil
+ thread_cancellations = {}
end
- channel.send(false, result)
- results = nil
- threads = nil
else
results[i] = result
- completed = completed + 1
if completed >= count then
channel.send(true, results)
results = nil
- threads = nil
+ thread_cancellations = {}
end
end
- end
- end
- for i, suspend_fn in ipairs(suspend_fns) do
- threads[i] = exports.run(suspend_fn, callback(i))
+ end)
end
end
diff --git a/lua/nvim-lsp-installer/core/installer/context.lua b/lua/nvim-lsp-installer/core/installer/context.lua
index 5705fa41..f97f334f 100644
--- a/lua/nvim-lsp-installer/core/installer/context.lua
+++ b/lua/nvim-lsp-installer/core/installer/context.lua
@@ -4,6 +4,8 @@ local fs = require "nvim-lsp-installer.core.fs"
local path = require "nvim-lsp-installer.path"
local platform = require "nvim-lsp-installer.platform"
local receipt = require "nvim-lsp-installer.core.receipt"
+local installer = require "nvim-lsp-installer.core.installer"
+local a = require "nvim-lsp-installer.core.async"
---@class ContextualSpawn
---@field cwd CwdManager
@@ -139,4 +141,17 @@ function InstallContext:promote_cwd()
self.cwd:set(self.destination_dir)
end
+---Runs the provided async functions concurrently and returns their result, once all are resolved.
+---This is really just a wrapper around a.wait_all() that makes sure to patch the coroutine context before creating the
+---new async execution contexts.
+---@async
+---@param suspend_fns async fun(ctx: InstallContext)[]
+function InstallContext:run_concurrently(suspend_fns)
+ return a.wait_all(vim.tbl_map(function(suspend_fn)
+ return function()
+ return installer.run_installer(self, suspend_fn)
+ end
+ end, suspend_fns))
+end
+
return InstallContext
diff --git a/lua/nvim-lsp-installer/core/installer/init.lua b/lua/nvim-lsp-installer/core/installer/init.lua
index dc9143a2..888415f2 100644
--- a/lua/nvim-lsp-installer/core/installer/init.lua
+++ b/lua/nvim-lsp-installer/core/installer/init.lua
@@ -34,6 +34,7 @@ end
function M.run_installer(context, installer)
local thread = coroutine.create(installer)
local step
+ local ret_val
step = function(...)
local ok, result = coroutine.resume(thread, ...)
if not ok then
@@ -43,9 +44,12 @@ function M.run_installer(context, installer)
elseif coroutine.status(thread) == "suspended" then
-- yield to parent coroutine
step(coroutine.yield(result))
+ else
+ ret_val = result
end
end
step(context)
+ return ret_val
end
---@async
diff --git a/lua/nvim-lsp-installer/core/managers/powershell/init.lua b/lua/nvim-lsp-installer/core/managers/powershell/init.lua
index a246e24c..94046b05 100644
--- a/lua/nvim-lsp-installer/core/managers/powershell/init.lua
+++ b/lua/nvim-lsp-installer/core/managers/powershell/init.lua
@@ -11,6 +11,7 @@ local PWSHOPT = {
---@param script string
---@param opts JobSpawnOpts
---@param custom_spawn JobSpawn
+---@return Result
function M.script(script, opts, custom_spawn)
opts = opts or {}
---@type JobSpawn
@@ -31,6 +32,7 @@ end
---@param command string
---@param opts JobSpawnOpts
---@param custom_spawn JobSpawn
+---@return Result
function M.command(command, opts, custom_spawn)
opts = opts or {}
---@type JobSpawn