fix(install): don't print operation summary by default

Problem: People complain about noisy `install()`.

Solution: Gate operation summary behind `summary` install option
(default false, set to true for interactive `:TS*` commands).
This commit is contained in:
Christian Clason 2025-05-29 12:25:13 +02:00 committed by Christian Clason
parent ce903fde5d
commit ff770d718b
4 changed files with 43 additions and 13 deletions

View file

@ -125,16 +125,21 @@ install({languages} [, {opts}]) *nvim-treesitter.install()*
compiling. compiling.
• {max_jobs} (`integer?`) limit parallel tasks (useful in • {max_jobs} (`integer?`) limit parallel tasks (useful in
combination with {generate} on memory-limited systems). combination with {generate} on memory-limited systems).
• {summary} (`boolean?`, default `false`) print summary of
successful and total operations for multiple languages.
uninstall({languages}) *nvim-treesitter.uninstall()* uninstall({languages} [, {opts}]) *nvim-treesitter.uninstall()*
Remove the parser and queries for the specified language(s). Remove the parser and queries for the specified language(s).
Parameters: ~ Parameters: ~
• {languages} `(string[]|string)` (List of) languages or tiers (`stable`, • {languages} `(string[]|string)` (List of) languages or tiers (`stable`,
`unstable`) to update. `unstable`) to update.
• {opts} `(table?)` Optional parameters:
• {summary} (`boolean?`, default `false`) print summary of
successful and total operations for multiple languages.
update([{languages}]) *nvim-treesitter.update()* update([{languages}, {opts}]) *nvim-treesitter.update()*
Update the parsers and queries if older than the revision specified in the Update the parsers and queries if older than the revision specified in the
manifest. manifest.
@ -147,6 +152,11 @@ update([{languages}]) *nvim-treesitter.update()*
Parameters: ~ Parameters: ~
• {languages} `(string[]|string)?` (List of) languages or tiers to update • {languages} `(string[]|string)?` (List of) languages or tiers to update
(default: all installed). (default: all installed).
• {opts} `(table?)` Optional parameters:
• {max_jobs} (`integer?`) limit parallel tasks (useful in
combination with {generate} on memory-limited systems).
• {summary} (`boolean?`, default `false`) print summary of
successful and total operations for multiple languages.
indentexpr() *nvim-treesitter.indentexpr()* indentexpr() *nvim-treesitter.indentexpr()*
@ -165,6 +175,12 @@ get_installed([{type}]) *nvim-treesitter.get_installed()*
Return list of languages installed via `nvim-treesitter`. Return list of languages installed via `nvim-treesitter`.
Note: This only searches `nvim-treesitter`'s (configured or default)
installation directory; parsers and queries from other sources can be
placed anywhere on 'runtimepath' and are not included. To list all, e.g.,
parsers that are installed from any source, use >lua
vim.api.nvim_get_runtime_file('parser/*', true)
<
Parameters: ~ Parameters: ~
• {type} `('queries'|parsers'?)` If specified, only show languages with • {type} `('queries'|parsers'?)` If specified, only show languages with
installed queries or parsers, respectively. installed queries or parsers, respectively.

View file

@ -437,6 +437,7 @@ end
---@field force? boolean ---@field force? boolean
---@field generate? boolean ---@field generate? boolean
---@field max_jobs? integer ---@field max_jobs? integer
---@field summary? boolean
--- Install a parser --- Install a parser
---@async ---@async
@ -467,7 +468,9 @@ local function install(languages, options)
join(options and options.max_jobs or MAX_JOBS, task_funs) join(options and options.max_jobs or MAX_JOBS, task_funs)
if #task_funs > 1 then if #task_funs > 1 then
a.schedule() a.schedule()
log.info('Installed %d/%d languages', done, #task_funs) if options and options.summary then
log.info('Installed %d/%d languages', done, #task_funs)
end
end end
return done == #task_funs return done == #task_funs
end end
@ -481,7 +484,8 @@ M.install = a.async(function(languages, options)
end) end)
---@param languages? string[]|string ---@param languages? string[]|string
M.update = a.async(function(languages) ---@param options? InstallOptions
M.update = a.async(function(languages, options)
reload_parsers() reload_parsers()
if not languages or #languages == 0 then if not languages or #languages == 0 then
languages = 'all' languages = 'all'
@ -489,10 +493,16 @@ M.update = a.async(function(languages)
languages = config.norm_languages(languages, { missing = true, unsupported = true }) languages = config.norm_languages(languages, { missing = true, unsupported = true })
languages = vim.tbl_filter(needs_update, languages) ---@type string[] languages = vim.tbl_filter(needs_update, languages) ---@type string[]
local summary = options and options.summary
if #languages > 0 then if #languages > 0 then
return install(languages, { force = true }) return install(
languages,
{ force = true, summary = summary, max_jobs = options and options.max_jobs }
)
else else
log.info('All parsers are up-to-date') if summary then
log.info('All parsers are up-to-date')
end
return true return true
end end
end) end)
@ -531,7 +541,8 @@ local function uninstall_lang(logger, lang, parser, queries)
end end
---@param languages string[]|string ---@param languages string[]|string
M.uninstall = a.async(function(languages) ---@param options? InstallOptions
M.uninstall = a.async(function(languages, options)
vim.api.nvim_exec_autocmds('User', { pattern = 'TSUpdate' }) vim.api.nvim_exec_autocmds('User', { pattern = 'TSUpdate' })
languages = config.norm_languages(languages or 'all', { missing = true, dependencies = true }) languages = config.norm_languages(languages or 'all', { missing = true, dependencies = true })
@ -560,7 +571,9 @@ M.uninstall = a.async(function(languages)
join(MAX_JOBS, task_funs) join(MAX_JOBS, task_funs)
if #task_funs > 1 then if #task_funs > 1 then
a.schedule() a.schedule()
log.info('Uninstalled %d/%d languages', done, #task_funs) if options and options.summary then
log.info('Uninstalled %d/%d languages', done, #task_funs)
end
end end
end) end)

View file

@ -27,7 +27,7 @@ end
-- create user commands -- create user commands
api.nvim_create_user_command('TSInstall', function(args) api.nvim_create_user_command('TSInstall', function(args)
require('nvim-treesitter.install').install(args.fargs, { force = args.bang }) require('nvim-treesitter.install').install(args.fargs, { force = args.bang, summary = true })
end, { end, {
nargs = '+', nargs = '+',
bang = true, bang = true,
@ -39,6 +39,7 @@ end, {
api.nvim_create_user_command('TSInstallFromGrammar', function(args) api.nvim_create_user_command('TSInstallFromGrammar', function(args)
require('nvim-treesitter.install').install(args.fargs, { require('nvim-treesitter.install').install(args.fargs, {
generate = true, generate = true,
summary = true,
force = args.bang, force = args.bang,
}) })
end, { end, {
@ -50,7 +51,7 @@ end, {
}) })
api.nvim_create_user_command('TSUpdate', function(args) api.nvim_create_user_command('TSUpdate', function(args)
require('nvim-treesitter.install').update(args.fargs) require('nvim-treesitter.install').update(args.fargs, { summary = true })
end, { end, {
nargs = '*', nargs = '*',
bar = true, bar = true,
@ -59,7 +60,7 @@ end, {
}) })
api.nvim_create_user_command('TSUninstall', function(args) api.nvim_create_user_command('TSUninstall', function(args)
require('nvim-treesitter.install').uninstall(args.fargs) require('nvim-treesitter.install').uninstall(args.fargs, { summary = true })
end, { end, {
nargs = '+', nargs = '+',
bar = true, bar = true,

View file

@ -19,10 +19,10 @@ end
vim.opt.runtimepath:append('.') vim.opt.runtimepath:append('.')
---@type async.Task ---@type async.Task
local task = update and require('nvim-treesitter').update('all') local task = update and require('nvim-treesitter').update('all', { summary = true })
or require('nvim-treesitter').install( or require('nvim-treesitter').install(
#parsers > 0 and parsers or 'all', #parsers > 0 and parsers or 'all',
{ force = true, generate = generate, max_jobs = max_jobs } { force = true, summary = true, generate = generate, max_jobs = max_jobs }
) )
local ok, err_or_ok = task:pwait(1800000) -- wait max. 30 minutes local ok, err_or_ok = task:pwait(1800000) -- wait max. 30 minutes