mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 19:00:02 -04:00
Add progress info to iter_cmd
This commit is contained in:
parent
0a51d492a5
commit
18fca90457
1 changed files with 36 additions and 4 deletions
|
|
@ -12,6 +12,24 @@ local lockfile = {}
|
||||||
|
|
||||||
M.compilers = { vim.fn.getenv('CC'), "cc", "gcc", "clang" }
|
M.compilers = { vim.fn.getenv('CC'), "cc", "gcc", "clang" }
|
||||||
|
|
||||||
|
local started_commands = 0
|
||||||
|
local finished_commands = 0
|
||||||
|
local failed_commands = 0
|
||||||
|
|
||||||
|
local function reset_progress_counter()
|
||||||
|
if started_commands ~= finished_commands then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
started_commands = 0
|
||||||
|
finished_commands = 0
|
||||||
|
failed_commands = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_job_status()
|
||||||
|
return "["..finished_commands.."/"..started_commands
|
||||||
|
..(failed_commands > 0 and ", failed: "..failed_commands or "").."]"
|
||||||
|
end
|
||||||
|
|
||||||
local function get_revision(lang)
|
local function get_revision(lang)
|
||||||
if #lockfile == 0 then
|
if #lockfile == 0 then
|
||||||
lockfile = vim.fn.json_decode(vim.fn.readfile(utils.join_paths(utils.get_package_path(), 'lockfile.json')))
|
lockfile = vim.fn.json_decode(vim.fn.readfile(utils.join_paths(utils.get_package_path(), 'lockfile.json')))
|
||||||
|
|
@ -42,16 +60,24 @@ local function select_rm_file_cmd(file, info_msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.iter_cmd(cmd_list, i, lang, success_message)
|
function M.iter_cmd(cmd_list, i, lang, success_message)
|
||||||
if i == #cmd_list + 1 then return print(success_message) end
|
if i == 1 then
|
||||||
|
started_commands = started_commands + 1
|
||||||
|
end
|
||||||
|
if i == #cmd_list + 1 then
|
||||||
|
finished_commands = finished_commands + 1
|
||||||
|
return print(get_job_status().." "..success_message)
|
||||||
|
end
|
||||||
|
|
||||||
local attr = cmd_list[i]
|
local attr = cmd_list[i]
|
||||||
if attr.info then print(attr.info) end
|
if attr.info then print(get_job_status().." "..attr.info) end
|
||||||
|
|
||||||
local handle
|
local handle
|
||||||
|
|
||||||
handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code)
|
handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code)
|
||||||
handle:close()
|
handle:close()
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
|
failed_commands = failed_commands + 1
|
||||||
|
finished_commands = finished_commands + 1
|
||||||
return api.nvim_err_writeln(attr.err or ("Failed to execute the following command:\n"..vim.inspect(attr)))
|
return api.nvim_err_writeln(attr.err or ("Failed to execute the following command:\n"..vim.inspect(attr)))
|
||||||
end
|
end
|
||||||
M.iter_cmd(cmd_list, i + 1, lang, success_message)
|
M.iter_cmd(cmd_list, i + 1, lang, success_message)
|
||||||
|
|
@ -288,7 +314,6 @@ end
|
||||||
|
|
||||||
local function install(with_sync, ask_reinstall)
|
local function install(with_sync, ask_reinstall)
|
||||||
return function (...)
|
return function (...)
|
||||||
|
|
||||||
if fn.executable('git') == 0 then
|
if fn.executable('git') == 0 then
|
||||||
return api.nvim_err_writeln('Git is required on your system to run this command')
|
return api.nvim_err_writeln('Git is required on your system to run this command')
|
||||||
end
|
end
|
||||||
|
|
@ -309,6 +334,10 @@ local function install(with_sync, ask_reinstall)
|
||||||
ask = ask_reinstall
|
ask = ask_reinstall
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #languages > 1 then
|
||||||
|
reset_progress_counter()
|
||||||
|
end
|
||||||
|
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
install_lang(lang, ask, cache_folder, install_folder, with_sync)
|
install_lang(lang, ask, cache_folder, install_folder, with_sync)
|
||||||
end
|
end
|
||||||
|
|
@ -316,6 +345,7 @@ local function install(with_sync, ask_reinstall)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.update(lang)
|
function M.update(lang)
|
||||||
|
reset_progress_counter()
|
||||||
if lang then
|
if lang then
|
||||||
install(false, 'force')(lang)
|
install(false, 'force')(lang)
|
||||||
else
|
else
|
||||||
|
|
@ -333,6 +363,7 @@ function M.uninstall(lang)
|
||||||
end
|
end
|
||||||
|
|
||||||
if lang == 'all' then
|
if lang == 'all' then
|
||||||
|
reset_progress_counter()
|
||||||
local installed = info.installed_parsers()
|
local installed = info.installed_parsers()
|
||||||
for _, lang in pairs(installed) do
|
for _, lang in pairs(installed) do
|
||||||
M.uninstall(lang)
|
M.uninstall(lang)
|
||||||
|
|
@ -371,7 +402,8 @@ function M.write_lockfile(verbose)
|
||||||
if verbose then
|
if verbose then
|
||||||
print(vim.inspect(lockfile))
|
print(vim.inspect(lockfile))
|
||||||
end
|
end
|
||||||
vim.fn.writefile(vim.fn.split(vim.fn.json_encode(lockfile), '\n'), utils.get_package_path().."/lockfile.json")
|
vim.fn.writefile(vim.fn.split(vim.fn.json_encode(lockfile), '\n'),
|
||||||
|
utils.join_paths(utils.get_package_path(), "lockfile.json"))
|
||||||
end
|
end
|
||||||
|
|
||||||
M.ensure_installed = install(false, false)
|
M.ensure_installed = install(false, false)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue