diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2025-05-28 13:55:33 +0200 |
|---|---|---|
| committer | Christian Clason <ch.clason+github@icloud.com> | 2025-05-29 11:52:58 +0200 |
| commit | 0860b9b1070c4e1bcce66416844b633acd8e0d2a (patch) | |
| tree | abd825da1a791c5df714c64695db14d6fd3b6618 /lua | |
| parent | fix(install): only install queries for bundled parsers (diff) | |
| download | nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.tar nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.tar.gz nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.tar.bz2 nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.tar.lz nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.tar.xz nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.tar.zst nvim-treesitter-0860b9b1070c4e1bcce66416844b633acd8e0d2a.zip | |
fix(config): check both installed parsers and queries
Problem: Can't uninstall custom parsers without queries since
`installed_parsers` only iterates over installed queries (to include
query-only languages, and to avoid string manipulation).
Solution: Iterate over both queries and parsers to collect list of
installed languages (optionally only queries or only parsers).
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/config.lua | 28 | ||||
| -rw-r--r-- | lua/nvim-treesitter/health.lua | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 6 |
3 files changed, 21 insertions, 15 deletions
diff --git a/lua/nvim-treesitter/config.lua b/lua/nvim-treesitter/config.lua index d073e3516..e46e2d5d1 100644 --- a/lua/nvim-treesitter/config.lua +++ b/lua/nvim-treesitter/config.lua @@ -39,22 +39,28 @@ function M.get_install_dir(dir_name) return dir end +---@param type 'queries'|'parsers'? ---@return string[] -function M.installed_parsers() - local install_dir = M.get_install_dir('queries') - - local installed = {} --- @type string[] - for f in vim.fs.dir(install_dir) do - installed[#installed + 1] = f +function M.installed_languages(type) + local installed = {} --- @type table<string, boolean> + if not (type and type == 'parsers') then + for f in vim.fs.dir(M.get_install_dir('queries')) do + installed[f] = true + end end - - return installed + if not (type and type == 'queries') then + for f in vim.fs.dir(M.get_install_dir('parser')) do + installed[vim.fn.fnamemodify(f, ':r')] = true + end + end + return vim.tbl_keys(installed) end -- Get a list of all available parsers ---@param tier integer? only get parsers of specified tier ---@return string[] function M.get_available(tier) + vim.api.nvim_exec_autocmds('User', { pattern = 'TSUpdate' }) local parsers = require('nvim-treesitter.parsers') --- @type string[] local languages = vim.tbl_keys(parsers) @@ -101,7 +107,7 @@ function M.norm_languages(languages, skip) if vim.list_contains(languages, 'all') then if skip and skip.missing then - return M.installed_parsers() + return M.installed_languages() end languages = M.get_available() end @@ -109,7 +115,7 @@ function M.norm_languages(languages, skip) languages = expand_tiers(languages) if skip and skip.installed then - local installed = M.installed_parsers() + local installed = M.installed_languages() languages = vim.tbl_filter( --- @param v string function(v) @@ -120,7 +126,7 @@ function M.norm_languages(languages, skip) end if skip and skip.missing then - local installed = M.installed_parsers() + local installed = M.installed_languages() languages = vim.tbl_filter( --- @param v string function(v) diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua index 57131f778..4095bce00 100644 --- a/lua/nvim-treesitter/health.lua +++ b/lua/nvim-treesitter/health.lua @@ -136,7 +136,7 @@ function M.check() -- Parser installation checks health.start('Installed languages' .. string.rep(' ', 5) .. 'H L F I J') - local languages = config.installed_parsers() + local languages = config.installed_languages() for _, lang in pairs(languages) do local parser = parsers[lang] local out = lang .. string.rep(' ', 22 - #lang) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index b669127ad..6391beba9 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -402,7 +402,7 @@ local install_status = {} ---@type table<string,InstallStatus?> ---@param generate? boolean ---@return InstallStatus status local function install_lang(lang, cache_dir, install_dir, force, generate) - if not force and vim.list_contains(config.installed_parsers(), lang) then + if not force and vim.list_contains(config.installed_languages(), lang) then install_status[lang] = 'installed' return 'installed' end @@ -532,12 +532,12 @@ end ---@param languages string[]|string M.uninstall = a.async(function(languages) - reload_parsers() + vim.api.nvim_exec_autocmds('User', { pattern = 'TSUpdate' }) languages = config.norm_languages(languages or 'all', { missing = true, dependencies = true }) local parser_dir = config.get_install_dir('parser') local query_dir = config.get_install_dir('queries') - local installed = config.installed_parsers() + local installed = config.installed_languages() local task_funs = {} ---@type async.TaskFun[] local done = 0 |
