1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
local platform = require "nvim-lsp-installer.platform"
local Data = require "nvim-lsp-installer.data"
local M = {}
function M.pipe(installers)
if #installers == 0 then
error "No installers to pipe."
end
return function(server, callback, context)
local function execute(idx)
local ok, err = pcall(installers[idx], server, function(success)
if not success then
-- oh no, error. exit early
callback(success)
elseif installers[idx + 1] then
-- iterate
execute(idx + 1)
else
-- we done
callback(success)
end
end, context)
if not ok then
context.stdio_sink.stderr(tostring(err) .. "\n")
callback(false)
end
end
execute(1)
end
end
-- much fp, very wow
function M.compose(installers)
return M.pipe(Data.list_reverse(installers))
end
function M.always_succeed(installer)
return function(server, callback, context)
installer(server, function()
callback(true)
end, context)
end
end
local function get_by_platform(platform_table)
if platform.is_mac then
return platform_table.mac or platform_table.unix
elseif platform.is_linux then
return platform_table.linux or platform_table.unix
elseif platform.is_unix then
return platform_table.unix
elseif platform.is_win then
return platform_table.win
else
return nil
end
end
-- non-exhaustive
function M.on(platform_table)
return function(server, callback, context)
local installer = get_by_platform(platform_table)
if installer then
installer(server, callback, context)
else
callback(true)
end
end
end
-- exhaustive
function M.when(platform_table)
return function(server, callback, context)
local installer = get_by_platform(platform_table)
if installer then
installer(server, callback, context)
else
context.stdio_sink.stderr(
("Current operating system is not yet supported for server %q.\n"):format(server.name)
)
callback(false)
end
end
end
return M
|