aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/core/async
diff options
context:
space:
mode:
Diffstat (limited to 'lua/nvim-lsp-installer/core/async')
-rw-r--r--lua/nvim-lsp-installer/core/async/init.lua4
-rw-r--r--lua/nvim-lsp-installer/core/async/spawn.lua63
-rw-r--r--lua/nvim-lsp-installer/core/async/uv.lua55
3 files changed, 57 insertions, 65 deletions
diff --git a/lua/nvim-lsp-installer/core/async/init.lua b/lua/nvim-lsp-installer/core/async/init.lua
index 6ecb5a61..0c278373 100644
--- a/lua/nvim-lsp-installer/core/async/init.lua
+++ b/lua/nvim-lsp-installer/core/async/init.lua
@@ -91,8 +91,8 @@ local function new_execution_context(suspend_fn, callback, ...)
end
end
-exports.run = function(suspend_fn, callback)
- return new_execution_context(suspend_fn, callback)
+exports.run = function(suspend_fn, callback, ...)
+ return new_execution_context(suspend_fn, callback, ...)
end
exports.scope = function(suspend_fn)
diff --git a/lua/nvim-lsp-installer/core/async/spawn.lua b/lua/nvim-lsp-installer/core/async/spawn.lua
deleted file mode 100644
index 5fc7eee7..00000000
--- a/lua/nvim-lsp-installer/core/async/spawn.lua
+++ /dev/null
@@ -1,63 +0,0 @@
-local a = require "nvim-lsp-installer.core.async"
-local Result = require "nvim-lsp-installer.core.result"
-local process = require "nvim-lsp-installer.process"
-local platform = require "nvim-lsp-installer.platform"
-
-local async_spawn = a.promisify(process.spawn)
-
----@type Record<string, fun(opts: JobSpawnOpts): Result>
-local spawn = {
- aliases = {
- npm = platform.is_win and "npm.cmd" or "npm",
- },
-}
-
-local function Failure(err, cmd)
- return Result.failure(setmetatable(err, {
- __tostring = function()
- return ("spawn: %s failed with exit code %d"):format(cmd, err.exit_code)
- end,
- }))
-end
-
-setmetatable(spawn, {
- __index = function(self, k)
- return function(args)
- local cmd_args = {}
- for i, arg in ipairs(args) do
- cmd_args[i] = arg
- end
- ---@type JobSpawnOpts
- local spawn_args = {
- stdio_sink = args.stdio_sink,
- cwd = args.cwd,
- env = args.env,
- args = cmd_args,
- }
-
- local stdio
- if not spawn_args.stdio_sink then
- stdio = process.in_memory_sink()
- spawn_args.stdio_sink = stdio.sink
- end
-
- local cmd = self.aliases[k] or k
- local _, exit_code = async_spawn(cmd, spawn_args)
-
- if exit_code == 0 then
- return Result.success {
- stdout = stdio and table.concat(stdio.buffers.stdout, "") or nil,
- stderr = stdio and table.concat(stdio.buffers.stderr, "") or nil,
- }
- else
- return Failure({
- exit_code = exit_code,
- stdout = stdio and table.concat(stdio.buffers.stdout, "") or nil,
- stderr = stdio and table.concat(stdio.buffers.stderr, "") or nil,
- }, cmd)
- end
- end
- end,
-})
-
-return spawn
diff --git a/lua/nvim-lsp-installer/core/async/uv.lua b/lua/nvim-lsp-installer/core/async/uv.lua
new file mode 100644
index 00000000..a2249be9
--- /dev/null
+++ b/lua/nvim-lsp-installer/core/async/uv.lua
@@ -0,0 +1,55 @@
+local a = require "nvim-lsp-installer.core.async"
+
+---@type Record<UvMethod, async fun(...)>
+local M = setmetatable({}, {
+ __index = function(_, method)
+ ---@async
+ return function(...)
+ local err, result = a.promisify(vim.loop[method])(...)
+ if err then
+ error(err, 2)
+ end
+ return result
+ end
+ end,
+})
+
+return M
+
+---@alias UvMethod
+---| '"fs_close"'
+---| '"fs_open"'
+---| '"fs_read"'
+---| '"fs_unlink"'
+---| '"fs_write"'
+---| '"fs_mkdir"'
+---| '"fs_mkdtemp"'
+---| '"fs_mkstemp"'
+---| '"fs_rmdir"'
+---| '"fs_scandir"'
+---| '"fs_stat"'
+---| '"fs_fstat"'
+---| '"fs_lstat"'
+---| '"fs_rename"'
+---| '"fs_fsync"'
+---| '"fs_fdatasync"'
+---| '"fs_ftruncate"'
+---| '"fs_sendfile"'
+---| '"fs_access"'
+---| '"fs_chmod"'
+---| '"fs_fchmod"'
+---| '"fs_utime"'
+---| '"fs_futime"'
+---| '"fs_lutime"'
+---| '"fs_link"'
+---| '"fs_symlink"'
+---| '"fs_readlink"'
+---| '"fs_realpath"'
+---| '"fs_chown"'
+---| '"fs_fchown"'
+---| '"fs_lchown"'
+---| '"fs_copyfile"'
+---| '"fs_opendir"'
+---| '"fs_readdir"'
+---| '"fs_closedir"'
+---| '"fs_statfs"'