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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
local path = require "nvim-lsp-installer.path"
local process = require "nvim-lsp-installer.process"
local installers = require "nvim-lsp-installer.installers"
local shell = require "nvim-lsp-installer.installers.shell"
local M = {}
function M.download_file(url, out_file)
return installers.when {
unix = function(server, callback, context)
process.spawn("wget", {
args = { "-nv", "-O", out_file, url },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end,
win = shell.powershell(("iwr -Uri %q -OutFile %q"):format(url, out_file)),
}
end
function M.unzip(file, dest)
return installers.pipe {
installers.when {
unix = function(server, callback, context)
process.spawn("unzip", {
args = { "-d", dest, file },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end,
win = shell.powershell(("Expand-Archive -Path %q -DestinationPath %q"):format(file, dest)),
},
installers.always_succeed(M.delete_file, file),
}
end
function M.unzip_remote(url, dest)
return installers.pipe {
M.download_file(url, "archive.zip"),
M.unzip("archive.zip", dest or "."),
}
end
function M.untar(file)
return installers.pipe {
function(server, callback, context)
process.spawn("tar", {
args = { "-xvf", file },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end,
installers.always_succeed(M.delete_file(file)),
}
end
function M.untargz_remote(url)
return installers.pipe {
M.download_file(url, "archive.tar.gz"),
M.gunzip "archive.tar.gz",
M.untar "archive.tar",
}
end
function M.gunzip(file)
return function(server, callback, context)
process.spawn("gzip", {
args = { "-d", file },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end
end
function M.gunzip_remote(url, out_file)
local archive = ("%s.gz"):format(out_file or "archive")
return installers.pipe {
M.download_file(url, archive),
M.gunzip(archive),
installers.always_succeed(M.delete_file(archive)),
}
end
function M.delete_file(file)
return installers.when {
unix = function(server, callback, context)
process.spawn("rm", {
args = { "-f", file },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end,
win = shell.powershell(("rm %q"):format(file)),
}
end
function M.git_clone(repo_url)
return function(server, callback, context)
process.spawn("git", {
args = { "clone", "--depth", "1", repo_url, "." },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end
end
function M.gradlew(opts)
return function(server, callback, context)
process.spawn(path.concat { server.root_dir, "gradlew" }, {
args = opts.args,
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end
end
function M.ensure_executables(executables)
return vim.schedule_wrap(function(_, callback, context)
for i = 1, #executables do
local executable = executables[i]
if vim.fn.executable(executable) ~= 1 then
context.stdio_sink.stderr(("Missing required %q executable."):format(executable))
callback(false)
return
end
end
callback(true)
end)
end
function M.chmod(flags, files)
return installers.on {
unix = function(server, callback, context)
process.spawn("chmod", {
args = vim.list_extend({ flags }, files),
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
end,
}
end
return M
|