aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2020-09-26 22:56:46 +0200
committerKiyan Yazdani <yazdani.kiyan@protonmail.com>2020-09-27 13:09:12 +0200
commit18fca90457ba46ed99d05c2218736c63c0fb41cd (patch)
treea2ba6e6796ad2c124136832340ffe5e06c963620
parentAdd lockfile and make lockfile default install revision (diff)
downloadnvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.tar
nvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.tar.gz
nvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.tar.bz2
nvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.tar.lz
nvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.tar.xz
nvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.tar.zst
nvim-treesitter-18fca90457ba46ed99d05c2218736c63c0fb41cd.zip
Add progress info to iter_cmd
-rw-r--r--lua/nvim-treesitter/install.lua40
1 files changed, 36 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index b810df349..61612f458 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -12,6 +12,24 @@ local lockfile = {}
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)
if #lockfile == 0 then
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
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]
- if attr.info then print(attr.info) end
+ if attr.info then print(get_job_status().." "..attr.info) end
local handle
handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code)
handle:close()
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)))
end
M.iter_cmd(cmd_list, i + 1, lang, success_message)
@@ -288,7 +314,6 @@ end
local function install(with_sync, ask_reinstall)
return function (...)
-
if fn.executable('git') == 0 then
return api.nvim_err_writeln('Git is required on your system to run this command')
end
@@ -309,6 +334,10 @@ local function install(with_sync, ask_reinstall)
ask = ask_reinstall
end
+ if #languages > 1 then
+ reset_progress_counter()
+ end
+
for _, lang in ipairs(languages) do
install_lang(lang, ask, cache_folder, install_folder, with_sync)
end
@@ -316,6 +345,7 @@ local function install(with_sync, ask_reinstall)
end
function M.update(lang)
+ reset_progress_counter()
if lang then
install(false, 'force')(lang)
else
@@ -333,6 +363,7 @@ function M.uninstall(lang)
end
if lang == 'all' then
+ reset_progress_counter()
local installed = info.installed_parsers()
for _, lang in pairs(installed) do
M.uninstall(lang)
@@ -371,7 +402,8 @@ function M.write_lockfile(verbose)
if verbose then
print(vim.inspect(lockfile))
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
M.ensure_installed = install(false, false)