feat(setup)!: remove ensure_install field

Instead, call `require('nvim-treesitter').install( { ... } )` manually.

This gives users full control over how they want to install parsers
(sync, from grammar, limited concurrency) and obviates the need for
calling `setup` for most users.
This commit is contained in:
Christian Clason 2025-04-27 13:02:32 +02:00
parent 73adbe597e
commit 522e0c6991
7 changed files with 37 additions and 46 deletions

View file

@ -3,13 +3,11 @@ local M = {}
M.tiers = { 'stable', 'unstable', 'unmaintained', 'unsupported' }
---@class TSConfig
---@field ensure_install string[]
---@field ignore_install string[]
---@field install_dir string
---@type TSConfig
local config = {
ensure_install = {},
ignore_install = {},
install_dir = vim.fs.joinpath(vim.fn.stdpath('data'), 'site'),
}
@ -20,21 +18,10 @@ function M.setup(user_data)
if user_data then
if user_data.install_dir then
user_data.install_dir = vim.fs.normalize(user_data.install_dir)
--TODO(clason): leave to user!
vim.opt.runtimepath:append(user_data.install_dir)
end
config = vim.tbl_deep_extend('force', config, user_data)
end
if #config.ensure_install > 0 then
local to_install = M.norm_languages(
config.ensure_install,
{ ignored = true, installed = true, unsupported = true }
)
if #to_install > 0 then
require('nvim-treesitter.install').install(to_install, { force = true })
end
end
end
-- Returns the install path for parsers, parser info, and queries.

View file

@ -4,6 +4,18 @@ function M.setup(...)
require('nvim-treesitter.config').setup(...)
end
function M.install(...)
require('nvim-treesitter.install').install(...)
end
function M.uninstall(...)
require('nvim-treesitter.install').uninstall(...)
end
function M.update(...)
require('nvim-treesitter.install').update(...)
end
function M.indentexpr()
return require('nvim-treesitter.indent').get_indent(vim.v.lnum)
end