aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers/init.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-10-06 15:17:43 +0200
committerGitHub <noreply@github.com>2021-10-06 15:17:43 +0200
commitd09ada1a3ed7fb35fefc20eb5daa4b767fc73906 (patch)
tree2152516dba481350642db27df018c1f60a3171f1 /lua/nvim-lsp-installer/installers/init.lua
parentwindows: add -UseBasicParsing for iwr calls (diff)
downloadmason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.gz
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.bz2
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.lz
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.xz
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.zst
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.zip
windows: attempt all common archiver programs (#136)
Diffstat (limited to 'lua/nvim-lsp-installer/installers/init.lua')
-rw-r--r--lua/nvim-lsp-installer/installers/init.lua44
1 files changed, 42 insertions, 2 deletions
diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua
index 0dd48972..83b46a1b 100644
--- a/lua/nvim-lsp-installer/installers/init.lua
+++ b/lua/nvim-lsp-installer/installers/init.lua
@@ -1,4 +1,5 @@
local platform = require "nvim-lsp-installer.platform"
+local log = require "nvim-lsp-installer.log"
local Data = require "nvim-lsp-installer.data"
local M = {}
@@ -32,6 +33,37 @@ function M.pipe(installers)
end
end
+function M.first_successful(installers)
+ if #installers == 0 then
+ error "No installers to pipe."
+ end
+
+ return function(server, callback, context)
+ local function execute(idx)
+ log.fmt_trace("Executing installer idx=%d", idx)
+ local ok, err = pcall(installers[idx], server, function(success)
+ log.fmt_trace("Installer idx=%d on exit with success=%s", idx, success)
+ if not success and installers[idx + 1] then
+ -- iterate
+ execute(idx + 1)
+ else
+ callback(success)
+ end
+ end, context)
+ if not ok then
+ context.stdio_sink.stderr(tostring(err) .. "\n")
+ if installers[idx + 1] then
+ execute(idx + 1)
+ else
+ callback(false)
+ end
+ end
+ end
+
+ execute(1)
+ end
+end
+
-- much fp, very wow
function M.compose(installers)
return M.pipe(Data.list_reverse(installers))
@@ -64,7 +96,11 @@ function M.on(platform_table)
return function(server, callback, context)
local installer = get_by_platform(platform_table)
if installer then
- installer(server, callback, context)
+ if type(installer) == "function" then
+ installer(server, callback, context)
+ else
+ M.pipe(installer)(server, callback, context)
+ end
else
callback(true)
end
@@ -76,7 +112,11 @@ function M.when(platform_table)
return function(server, callback, context)
local installer = get_by_platform(platform_table)
if installer then
- installer(server, callback, context)
+ if type(installer) == "function" then
+ installer(server, callback, context)
+ else
+ M.pipe(installer)(server, callback, context)
+ end
else
context.stdio_sink.stderr(
("Current operating system is not yet supported for server %q.\n"):format(server.name)