aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/process.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-10-05 17:29:47 +0200
committerGitHub <noreply@github.com>2021-10-05 17:29:47 +0200
commit31431474a5b0d6f27de815c9a31249165cb54fbc (patch)
tree3d1be0b24d426b0374ea195b5e9c1ae71ac4c64a /lua/nvim-lsp-installer/process.lua
parentbetter error messaging (diff)
downloadmason-31431474a5b0d6f27de815c9a31249165cb54fbc.tar
mason-31431474a5b0d6f27de815c9a31249165cb54fbc.tar.gz
mason-31431474a5b0d6f27de815c9a31249165cb54fbc.tar.bz2
mason-31431474a5b0d6f27de815c9a31249165cb54fbc.tar.lz
mason-31431474a5b0d6f27de815c9a31249165cb54fbc.tar.xz
mason-31431474a5b0d6f27de815c9a31249165cb54fbc.tar.zst
mason-31431474a5b0d6f27de815c9a31249165cb54fbc.zip
attempt curl if wget is not available (#129)
Diffstat (limited to 'lua/nvim-lsp-installer/process.lua')
-rw-r--r--lua/nvim-lsp-installer/process.lua36
1 files changed, 35 insertions, 1 deletions
diff --git a/lua/nvim-lsp-installer/process.lua b/lua/nvim-lsp-installer/process.lua
index dca7b328..e7ede690 100644
--- a/lua/nvim-lsp-installer/process.lua
+++ b/lua/nvim-lsp-installer/process.lua
@@ -120,7 +120,7 @@ function M.spawn(cmd, opts, callback)
if handle == nil then
log.fmt_error("Failed to spawn process. cmd=%s, err=%s", cmd, pid_or_err)
if type(pid_or_err) == "string" and pid_or_err:find "ENOENT" == 1 then
- opts.stdio_sink.stderr(("Could not find required executable %q in path.\n"):format(cmd))
+ opts.stdio_sink.stderr(("Could not find executable %q in path.\n"):format(cmd))
else
opts.stdio_sink.stderr(("Failed to spawn process cmd=%s err=%s\n"):format(cmd, pid_or_err))
end
@@ -215,4 +215,38 @@ function M.debounced(debounced_fn)
end
end
+function M.lazy_spawn(cmd, opts)
+ return function(callback)
+ return M.spawn(cmd, opts, callback)
+ end
+end
+
+function M.attempt(opts)
+ local jobs, on_finish, on_iterate = opts.jobs, opts.on_finish, opts.on_iterate
+ if #jobs == 0 then
+ error "process.attempt(...) need at least one job."
+ end
+ local function spawn(idx)
+ jobs[idx](function(success)
+ if success then
+ -- this job succeeded. exit early
+ on_finish(true)
+ elseif jobs[idx + 1] then
+ -- iterate
+ if on_iterate then
+ on_iterate()
+ end
+ log.debug "Previous job failed, attempting next."
+ spawn(idx + 1)
+ else
+ -- we exhausted all jobs without success
+ log.debug "All jobs failed."
+ on_finish(false)
+ end
+ end)
+ end
+
+ spawn(1)
+end
+
return M