feat(install): allow pass callback to update()

Problem: cannot run `:TSUpdate synchronously`

Solution: pass callback used after exiting jobs
(like in `install-parsers`).
This commit is contained in:
przepompownia 2025-03-05 20:03:30 +01:00 committed by Christian Clason
parent 02a1a0537c
commit 6fe0032640
4 changed files with 56 additions and 43 deletions

View file

@ -1,11 +1,14 @@
#!/usr/bin/env -S nvim -l
local generate = false
local update = false
local max_jobs = nil ---@as integer
local parsers = {}
for i = 1, #_G.arg do
if _G.arg[i] == '--generate' then
generate = true
elseif _G.arg[i] == '--update' then
update = true
elseif _G.arg[i]:find('^%-%-max%-jobs') then
max_jobs = _G.arg[i]:match('=(%d+)')
else
@ -19,13 +22,19 @@ vim.opt.runtimepath:append('.')
vim.fn.mkdir(vim.fn.stdpath('cache'), 'p')
local ok = nil
require('nvim-treesitter.install').install(
#parsers > 0 and parsers or 'all',
{ force = true, generate = generate, max_jobs = max_jobs },
function(success)
if update then
require('nvim-treesitter.install').update('all', {}, function(success)
ok = success
end
)
end)
else
require('nvim-treesitter.install').install(
#parsers > 0 and parsers or 'all',
{ force = true, generate = generate, max_jobs = max_jobs },
function(success)
ok = success
end
)
end
vim.wait(6000000, function()
return ok ~= nil