mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 03:10:04 -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
|
lua <<EOF
|
||||||
require'nvim-treesitter.configs'.setup {
|
require'nvim-treesitter.configs'.setup {
|
||||||
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
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 = {
|
highlight = {
|
||||||
enable = true, -- false will disable the whole extension
|
enable = true, -- false will disable the whole extension
|
||||||
disable = { "c", "rust" }, -- list of language that will be disabled
|
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
|
lua <<EOF
|
||||||
require'nvim-treesitter.configs'.setup {
|
require'nvim-treesitter.configs'.setup {
|
||||||
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
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 = {
|
highlight = {
|
||||||
enable = true, -- false will disable the whole extension
|
enable = true, -- false will disable the whole extension
|
||||||
disable = { "c", "rust" }, -- list of language that will be disabled
|
disable = { "c", "rust" }, -- list of language that will be disabled
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ local M = {}
|
||||||
local config = {
|
local config = {
|
||||||
modules = {},
|
modules = {},
|
||||||
ensure_installed = {},
|
ensure_installed = {},
|
||||||
|
ignore_install = {},
|
||||||
update_strategy = 'lockfile',
|
update_strategy = 'lockfile',
|
||||||
}
|
}
|
||||||
-- List of modules that need to be setup on initialization.
|
-- List of modules that need to be setup on initialization.
|
||||||
|
|
@ -271,6 +272,7 @@ end
|
||||||
-- @param user_data module overrides
|
-- @param user_data module overrides
|
||||||
function M.setup(user_data)
|
function M.setup(user_data)
|
||||||
config.modules = vim.tbl_deep_extend('force', config.modules, 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 {}
|
local ensure_installed = user_data.ensure_installed or {}
|
||||||
if #ensure_installed > 0 then
|
if #ensure_installed > 0 then
|
||||||
|
|
@ -412,4 +414,8 @@ function M.get_update_strategy()
|
||||||
return config.update_strategy
|
return config.update_strategy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_ignored_parser_installs()
|
||||||
|
return config.ignore_install or {}
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
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)
|
run_install(cache_folder, install_folder, lang, install_info, with_sync, generate_from_grammar)
|
||||||
end
|
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 (...)
|
return function (...)
|
||||||
if fn.executable('git') == 0 then
|
if fn.executable('git') == 0 then
|
||||||
return api.nvim_err_writeln('Git is required on your system to run this command')
|
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
|
ask = ask_reinstall
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if exclude_configured_parsers then
|
||||||
|
languages = utils.difference(languages, configs.get_ignored_parser_installs())
|
||||||
|
end
|
||||||
|
|
||||||
if #languages > 1 then
|
if #languages > 1 then
|
||||||
reset_progress_counter()
|
reset_progress_counter()
|
||||||
end
|
end
|
||||||
|
|
@ -306,7 +316,7 @@ function M.update(lang)
|
||||||
M.lockfile = {}
|
M.lockfile = {}
|
||||||
reset_progress_counter()
|
reset_progress_counter()
|
||||||
if lang and lang ~= 'all' then
|
if lang and lang ~= 'all' then
|
||||||
install(false, 'force')(lang)
|
install({ ask_reinstall = 'force' })(lang)
|
||||||
else
|
else
|
||||||
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
||||||
and outdated_parsers()
|
and outdated_parsers()
|
||||||
|
|
@ -315,7 +325,10 @@ function M.update(lang)
|
||||||
print('All parsers are up-to-date!')
|
print('All parsers are up-to-date!')
|
||||||
end
|
end
|
||||||
for _, lang in pairs(parsers_to_update) do
|
for _, lang in pairs(parsers_to_update) do
|
||||||
install(false, 'force')(lang)
|
install({
|
||||||
|
ask_reinstall = 'force',
|
||||||
|
exclude_configured_parsers = true
|
||||||
|
})(lang)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -382,25 +395,25 @@ function M.write_lockfile(verbose, skip_langs)
|
||||||
utils.join_path(utils.get_package_path(), "lockfile.json"))
|
utils.join_path(utils.get_package_path(), "lockfile.json"))
|
||||||
end
|
end
|
||||||
|
|
||||||
M.ensure_installed = install(false, false)
|
M.ensure_installed = install({ exclude_configured_parsers = true })
|
||||||
|
|
||||||
M.commands = {
|
M.commands = {
|
||||||
TSInstall = {
|
TSInstall = {
|
||||||
run = install(false, true),
|
run = install({ ask_reinstall = true }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TSInstallFromGrammar = {
|
TSInstallFromGrammar = {
|
||||||
run = install(false, true, true),
|
run = install({ ask_reinstall = true, generate_from_grammar = true }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TSInstallSync = {
|
TSInstallSync = {
|
||||||
run = install(true, true),
|
run = install({ with_sync = true, ask_reinstall = true }),
|
||||||
args = {
|
args = {
|
||||||
"-nargs=+",
|
"-nargs=+",
|
||||||
"-complete=custom,nvim_treesitter#installable_parsers",
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
|
|
|
||||||
|
|
@ -141,4 +141,29 @@ function M.index_of(tbl, obj)
|
||||||
end
|
end
|
||||||
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
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue