nvim-treesitter/scripts/install-parsers.lua

43 lines
968 B
Lua
Raw Normal View History

#!/usr/bin/env -S nvim -l
local generate = false
local update = false
local max_jobs = nil ---@type 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
2025-04-27 16:08:59 +02:00
parsers[#parsers + 1] = _G.arg[i] ---@type string
end
end
vim.opt.runtimepath:append('.')
-- needed on CI
vim.fn.mkdir(vim.fn.stdpath('cache'), 'p')
2025-05-16 13:05:43 +01:00
local task = nil
if update then
--- @type async.Task
2025-05-16 14:27:59 +02:00
task = require('nvim-treesitter.install').update('all')
2025-05-16 13:05:43 +01:00
else
--- @type async.Task
2025-05-16 14:27:59 +02:00
task = require('nvim-treesitter.install').install(
2025-05-16 13:05:43 +01:00
#parsers > 0 and parsers or 'all',
{ force = true, generate = generate, max_jobs = max_jobs }
)
end
local ok, err_or_ok = task:pwait(6000000)
2025-05-16 13:58:34 +02:00
if not ok then
2025-05-16 13:05:43 +01:00
print('ERROR: ', err_or_ok)
vim.cmd.cq()
elseif not err_or_ok then
vim.cmd.cq()
end