diff options
| author | Steven Sojka <steelsojka@users.noreply.github.com> | 2021-03-24 09:12:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-24 09:12:03 -0500 |
| commit | 7984975a2fa8e4c526359edf471a493307c0529c (patch) | |
| tree | 46bb699428271a031b1bca60a5a942c86505049a | |
| parent | Add generator functions to ecma queries (diff) | |
| download | nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.tar nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.tar.gz nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.tar.bz2 nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.tar.lz nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.tar.xz nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.tar.zst nvim-treesitter-7984975a2fa8e4c526359edf471a493307c0529c.zip | |
feat(install): allow ignore list when installing parsers (#1098)
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | doc/nvim-treesitter.txt | 1 | ||||
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 6 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 27 | ||||
| -rw-r--r-- | lua/nvim-treesitter/utils.lua | 25 |
5 files changed, 53 insertions, 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 diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index b5d214ba1..3d084e5e6 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -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 diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index 29da2e881..973b9cb6d 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -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 diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 65c47265d..e830a1afd 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -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", diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index 8d5191d0d..f82c2d4a7 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -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 |
