replace vim.loop.spawn with vim.fn.jobstart -- taken from xlucn on

github
This commit is contained in:
2023-04-29 11:04:14 -04:00
parent e08bfe10d0
commit 36db96d397

View File

@ -2,56 +2,36 @@ local logger = require("dep.log").global
local proc = {} local proc = {}
function proc.exec(process, args, cwd, env, cb) function proc.exec(process, args, cwd, env, cb)
local handle, pid, buffer = nil, nil, {} local buffer = {}
local stdout = vim.loop.new_pipe()
local stderr = vim.loop.new_pipe()
handle, pid = vim.loop.spawn( local function cb_output(_, data, _)
process, table.insert(buffer, table.concat(data))
{ args = args, cwd = cwd, env = env, stdio = { nil, stdout, stderr } }, end
vim.schedule_wrap(function(code) local function cb_exit(job_id, exit_code, _)
handle:close() local output = table.concat(buffer)
logger:log(
local output = table.concat(buffer) process,
string.format(
if output:sub(-1) == "\n" then 'Job %s ["%s"] finished with exitcode %s\n%s',
output = output:sub(1, -2) job_id,
end table.concat(args, '", "'),
exit_code,
logger:log( output)
process, )
string.format( cb(exit_code ~= 0, output)
'executed `%s` (code=%s, pid=%s) with args: "%s"\n%s', end
process, table.insert(args, 1, process)
code, vim.fn.jobstart(args, {
pid, cwd = cwd,
table.concat(args, '", "'), env = env,
output stdin = nil,
) on_exit = cb_exit,
) on_stdout = cb_output,
on_stderr = cb_output,
cb(code ~= 0, output) })
end)
)
vim.loop.read_start(stdout, function(_, data)
if data then
buffer[#buffer + 1] = data
else
stdout:close()
end
end)
vim.loop.read_start(stderr, function(_, data)
if data then
buffer[#buffer + 1] = data
else
stderr:close()
end
end)
end end
local git_env = { "GIT_TERMINAL_PROMPT=0" } local git_env = { GIT_TERMINAL_PROMPT = 0 }
function proc.git_rev_parse(dir, arg, cb) function proc.git_rev_parse(dir, arg, cb)
local args = { "rev-parse", "--short", arg } local args = { "rev-parse", "--short", arg }