mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
feat(install): allow ignore list when installing parsers (#1098)
This commit is contained in:
parent
09045354c0
commit
7984975a2f
5 changed files with 53 additions and 7 deletions
|
|
@ -101,6 +101,7 @@ All modules are disabled by default and need to be activated explicitly in your
|
|||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
||||
ignore_install = { "javascript" }, -- List of parsers to ignore installing
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
disable = { "c", "rust" }, -- list of language that will be disabled
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ To enable supported features, put this in your `init.vim` file:
|
|||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
||||
ignore_install = { "javascript" }, -- List of parsers to ignore installing
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
disable = { "c", "rust" }, -- list of language that will be disabled
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ local M = {}
|
|||
local config = {
|
||||
modules = {},
|
||||
ensure_installed = {},
|
||||
ignore_install = {},
|
||||
update_strategy = 'lockfile',
|
||||
}
|
||||
-- List of modules that need to be setup on initialization.
|
||||
|
|
@ -271,6 +272,7 @@ end
|
|||
-- @param user_data module overrides
|
||||
function M.setup(user_data)
|
||||
config.modules = vim.tbl_deep_extend('force', config.modules, user_data)
|
||||
config.ignore_install = user_data.ignore_install or {}
|
||||
|
||||
local ensure_installed = user_data.ensure_installed or {}
|
||||
if #ensure_installed > 0 then
|
||||
|
|
@ -412,4 +414,8 @@ function M.get_update_strategy()
|
|||
return config.update_strategy
|
||||
end
|
||||
|
||||
function M.get_ignored_parser_installs()
|
||||
return config.ignore_install or {}
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -267,7 +267,13 @@ local function install_lang(lang, ask_reinstall, cache_folder, install_folder, w
|
|||
run_install(cache_folder, install_folder, lang, install_info, with_sync, generate_from_grammar)
|
||||
end
|
||||
|
||||
local function install(with_sync, ask_reinstall, generate_from_grammar)
|
||||
local function install(options)
|
||||
options = options or {}
|
||||
local with_sync = options.with_sync
|
||||
local ask_reinstall = options.ask_reinstall
|
||||
local generate_from_grammar = options.generate_from_grammar
|
||||
local exclude_configured_parsers = options.exclude_configured_parsers
|
||||
|
||||
return function (...)
|
||||
if fn.executable('git') == 0 then
|
||||
return api.nvim_err_writeln('Git is required on your system to run this command')
|
||||
|
|
@ -292,6 +298,10 @@ local function install(with_sync, ask_reinstall, generate_from_grammar)
|
|||
ask = ask_reinstall
|
||||
end
|
||||
|
||||
if exclude_configured_parsers then
|
||||
languages = utils.difference(languages, configs.get_ignored_parser_installs())
|
||||
end
|
||||
|
||||
if #languages > 1 then
|
||||
reset_progress_counter()
|
||||
end
|
||||
|
|
@ -306,7 +316,7 @@ function M.update(lang)
|
|||
M.lockfile = {}
|
||||
reset_progress_counter()
|
||||
if lang and lang ~= 'all' then
|
||||
install(false, 'force')(lang)
|
||||
install({ ask_reinstall = 'force' })(lang)
|
||||
else
|
||||
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
||||
and outdated_parsers()
|
||||
|
|
@ -315,7 +325,10 @@ function M.update(lang)
|
|||
print('All parsers are up-to-date!')
|
||||
end
|
||||
for _, lang in pairs(parsers_to_update) do
|
||||
install(false, 'force')(lang)
|
||||
install({
|
||||
ask_reinstall = 'force',
|
||||
exclude_configured_parsers = true
|
||||
})(lang)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -382,25 +395,25 @@ function M.write_lockfile(verbose, skip_langs)
|
|||
utils.join_path(utils.get_package_path(), "lockfile.json"))
|
||||
end
|
||||
|
||||
M.ensure_installed = install(false, false)
|
||||
M.ensure_installed = install({ exclude_configured_parsers = true })
|
||||
|
||||
M.commands = {
|
||||
TSInstall = {
|
||||
run = install(false, true),
|
||||
run = install({ ask_reinstall = true }),
|
||||
args = {
|
||||
"-nargs=+",
|
||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||
},
|
||||
},
|
||||
TSInstallFromGrammar = {
|
||||
run = install(false, true, true),
|
||||
run = install({ ask_reinstall = true, generate_from_grammar = true }),
|
||||
args = {
|
||||
"-nargs=+",
|
||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||
},
|
||||
},
|
||||
TSInstallSync = {
|
||||
run = install(true, true),
|
||||
run = install({ with_sync = true, ask_reinstall = true }),
|
||||
args = {
|
||||
"-nargs=+",
|
||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||
|
|
|
|||
|
|
@ -141,4 +141,29 @@ function M.index_of(tbl, obj)
|
|||
end
|
||||
end
|
||||
|
||||
-- Filters a list based on the given predicate
|
||||
-- @param tbl The list to filter
|
||||
-- @param predicate The predicate to filter with
|
||||
function M.filter(tbl, predicate)
|
||||
local result = {}
|
||||
|
||||
for i, v in ipairs(tbl) do
|
||||
if predicate(v, i) then
|
||||
table.insert(result, v)
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
-- Returns a list of all values from the first list
|
||||
-- that are not present in the second list.
|
||||
-- @params tbl1 The first table
|
||||
-- @params tbl2 The second table
|
||||
function M.difference(tbl1, tbl2)
|
||||
return M.filter(tbl1, function(v)
|
||||
return not vim.tbl_contains(tbl2, v)
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue