-
Notifications
You must be signed in to change notification settings - Fork 49
/
update.lua
119 lines (108 loc) · 2.48 KB
/
update.lua
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
local log = require("codeium.log")
local config = require("codeium.config")
local versions = require("codeium.versions")
local io = require("codeium.io")
local Job = require("plenary.job")
local M = {}
local cached = nil
function M.get_bin_info()
if cached then
return cached
end
local os_info = io.get_system_info()
local dir = config.options.bin_path .. "/" .. versions.extension
local bin_sufix
if os_info.os == "windows" then
bin_sufix = "windows_x64.exe"
elseif os_info.is_aarch or os_info.is_arm then
bin_sufix = os_info.os .. "_arm"
else
bin_sufix = os_info.os .. "_x64"
end
cached = {
dir = dir,
bin_sufix = bin_sufix,
bin = dir .. "/" .. "language_server_" .. bin_sufix,
download_url = "https://github.com/Exafunction/codeium/releases/download/language-server-v"
.. versions.extension
.. "/language_server_"
.. bin_sufix
.. ".gz",
}
return cached
end
function M.download(callback)
local info = M.get_bin_info()
if io.exists(info.bin) then
callback(nil)
return
end
local gz = info.bin .. ".gz"
vim.fn.mkdir(info.dir, "p")
local function chmod()
Job:new(config.job_args({
"chmod",
"+x",
info.bin,
}, {
on_exit = function(j, s)
if s ~= 0 then
log.error("failed to chmod Codeium server ", s, ": ", {
stdout = j:result(),
stderr = j:stderr_result(),
})
vim.notify("Failed to chmod Codeium server")
callback("chmod_failed")
return
end
vim.notify("Codeium server updated")
callback(nil)
end,
})):start()
end
local function unpack()
vim.notify("Unpacking Codeium server", vim.log.levels.INFO)
Job:new(config.job_args({
"gzip",
"-d",
gz,
}, {
on_exit = function(j, s)
if s ~= 0 then
log.error("failed to unpack Codeium server ", s, ": ", {
stdout = j:result(),
stderr = j:stderr_result(),
})
vim.notify("Failed to unpack Codeium server")
callback("unpack_failed")
return
end
chmod()
end,
})):start()
end
local function download()
vim.notify("Downloading Codeium Server", vim.log.levels.INFO)
Job:new(config.job_args({
"curl",
"-Lo",
gz,
info.download_url,
}, {
on_exit = function(j, s)
if s ~= 0 then
log.error("failed to download Codeium server ", s, ": ", {
stdout = j:result(),
stderr = j:stderr_result(),
})
vim.notify("Failed to download Codeium server")
callback("download_failed")
return
end
unpack()
end,
})):start()
end
download()
end
return M