diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2025-03-26 13:08:49 +0100 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 328ee3db548db585208ae2ff0bf4fd06231581aa (patch) | |
| tree | acbcebfa02d3254b011ee8e40738bdd7ebc05429 | |
| parent | fix(install): don't prompt on installed parsers (skip) (diff) | |
| download | nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.tar nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.tar.gz nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.tar.bz2 nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.tar.lz nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.tar.xz nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.tar.zst nvim-treesitter-328ee3db548db585208ae2ff0bf4fd06231581aa.zip | |
fix(install): skip tier 4 parsers when installing and updating
| -rw-r--r-- | lua/nvim-treesitter/config.lua | 18 | ||||
| -rw-r--r-- | lua/nvim-treesitter/health.lua | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/indent.lua | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 19 | ||||
| -rw-r--r-- | lua/nvim-treesitter/locals.lua | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 48 |
6 files changed, 51 insertions, 40 deletions
diff --git a/lua/nvim-treesitter/config.lua b/lua/nvim-treesitter/config.lua index 473a97ee9..7ef5aeddf 100644 --- a/lua/nvim-treesitter/config.lua +++ b/lua/nvim-treesitter/config.lua @@ -27,8 +27,10 @@ function M.setup(user_data) end if #config.ensure_install > 0 then - local to_install = M.norm_languages(config.ensure_install, { ignored = true, installed = true }) - + 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 @@ -103,7 +105,7 @@ end ---Normalize languages ---@param languages? string[]|string ----@param skip? { ignored: boolean, missing: boolean, installed: boolean, dependencies: boolean } +---@param skip? { ignored: boolean, missing: boolean, unsupported: boolean, installed: boolean, dependencies: boolean } ---@return string[] function M.norm_languages(languages, skip) if not languages then @@ -164,6 +166,16 @@ function M.norm_languages(languages, skip) languages ) + if skip and skip.unsupported then + languages = vim.tbl_filter( + --- @param v string + function(v) + return parsers[v].tier < 4 + end, + languages + ) + end + if not (skip and skip.dependencies) then for _, lang in pairs(languages) do if parsers[lang].requires then diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua index 1776cffe7..68b01bb35 100644 --- a/lua/nvim-treesitter/health.lua +++ b/lua/nvim-treesitter/health.lua @@ -25,7 +25,7 @@ local function install_health() do -- nvim check if vim.fn.has('nvim-0.11') ~= 1 then - health.error('Nvim-treesitter requires the latest Neovim nightly') + health.error('Nvim-treesitter requires Neovim 0.11.0 or later.') end if vim.treesitter.language_version then diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua index 6b674dc63..03489f22e 100644 --- a/lua/nvim-treesitter/indent.lua +++ b/lua/nvim-treesitter/indent.lua @@ -134,7 +134,7 @@ function M.get_indent(lnum) end -- Get language tree with smallest range around node that's not a comment parser - local root, lang_tree ---@type TSNode, LanguageTree + local root, lang_tree ---@type TSNode, vim.treesitter.LanguageTree parser:for_each_tree(function(tstree, tree) if not tstree or M.comment_parsers[tree:lang()] then return diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index d49a7cbc9..c208a2709 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -148,7 +148,7 @@ local function do_generate(logger, repo, compile_location) 'generate', '--abi', tostring(vim.treesitter.language_version), - repo.generate_from_json and 'src/grammar.json', + repo.generate_from_json and 'src/grammar.json' or nil, }, { cwd = compile_location }) if r.code > 0 then return logger:error('Error during "tree-sitter generate": %s', r.stderr) @@ -432,14 +432,12 @@ local function install(languages, options, callback) end end +---@param languages string[] +---@param options? InstallOptions +---@param callback? fun(boolean) M.install = a.sync(function(languages, options, callback) reload_parsers() - if not languages or #languages == 0 then - languages = 'all' - end - - languages = config.norm_languages(languages, options and options.skip) - + languages = config.norm_languages(languages, { ignored = true, unsupported = true }) install(languages, options, callback) end, 3) @@ -447,13 +445,14 @@ end, 3) ---@param languages? string[]|string ---@param _options? UpdateOptions ----@param callback function +---@param callback? function M.update = a.sync(function(languages, _options, callback) reload_parsers() if not languages or #languages == 0 then languages = 'all' end - languages = config.norm_languages(languages, { ignored = true, missing = true }) + languages = + config.norm_languages(languages, { ignored = true, missing = true, unsupported = true }) languages = vim.tbl_filter(needs_update, languages) ---@type string[] if #languages > 0 then @@ -501,7 +500,7 @@ end ---@param languages string[]|string ---@param _options? UpdateOptions ----@param _callback fun() +---@param _callback? fun() M.uninstall = a.sync(function(languages, _options, _callback) languages = config.norm_languages(languages or 'all', { missing = true, dependencies = true }) diff --git a/lua/nvim-treesitter/locals.lua b/lua/nvim-treesitter/locals.lua index c8ebe0b0d..63b3d458c 100644 --- a/lua/nvim-treesitter/locals.lua +++ b/lua/nvim-treesitter/locals.lua @@ -159,7 +159,7 @@ local function get_root(bufnr) end ---@param bufnr integer: the buffer ----@return Query|nil query: `locals` query +---@return vim.treesitter.Query|nil query: `locals` query ---@return TSNode|nil root: root node of the bufferocal function get_query(bufnr) local function get_query(bufnr) local root = get_root(bufnr) |
