Skip to content

Commit 890ecbd

Browse files
committed
update get_hash function
1 parent 2efcbca commit 890ecbd

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lua/zig-lamp/module/pkg.lua

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@ local function get_hash(_url)
3030
if vim.fn.executable("zig") == 0 then
3131
return nil
3232
end
33-
--- @diagnostic disable-next-line: missing-fields
34-
local _tmp = job:new({ command = "zig", args = { "fetch", _url } })
35-
_tmp:after_failure(vim.schedule_wrap(function(_, code, signal)
36-
-- stylua: ignore
37-
util.Error(string.format("failed fetch: %s, code is %d, signal is %d", _url, code, signal))
38-
end))
39-
util.Info("fetching: " .. _url)
40-
local _result, _ = _tmp:sync(vim.g.zig_lamp_zig_fetch_timeout)
41-
if not _result then
33+
util.Info("start get package hash")
34+
local _handle = vim.system({ "zig", "fetch", _url }, { text = true })
35+
local result = _handle:wait()
36+
if result.code ~= 0 then
37+
util.Error(
38+
string.format(
39+
"failed fetch: %s, code is %d, signal is %d",
40+
_url,
41+
result.code,
42+
result.signal
43+
)
44+
)
4245
return nil
4346
end
44-
return _result[1]
47+
if result.stdout then
48+
return vim.trim(result.stdout)
49+
end
50+
return nil
4551
end
4652

4753
local function render_help_text(buffer)

0 commit comments

Comments
 (0)