aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lua/nvim-treesitter/config.lua28
-rw-r--r--lua/nvim-treesitter/health.lua2
-rw-r--r--lua/nvim-treesitter/install.lua6
-rw-r--r--plugin/nvim-treesitter.lua2
-rwxr-xr-xscripts/check-parsers.lua2
-rwxr-xr-xscripts/check-queries.lua2
6 files changed, 24 insertions, 18 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
diff --git a/plugin/nvim-treesitter.lua b/plugin/nvim-treesitter.lua
index b007ca29b..d4ccf3049 100644
--- a/plugin/nvim-treesitter.lua
+++ b/plugin/nvim-treesitter.lua
@@ -21,7 +21,7 @@ local function complete_installed_parsers(arglead)
function(v)
return v:find(arglead) ~= nil
end,
- require('nvim-treesitter.config').installed_parsers()
+ require('nvim-treesitter.config').installed_languages()
)
end
diff --git a/scripts/check-parsers.lua b/scripts/check-parsers.lua
index 08e48740d..152c8f7ea 100755
--- a/scripts/check-parsers.lua
+++ b/scripts/check-parsers.lua
@@ -3,7 +3,7 @@ vim.opt.runtimepath:append('.')
local configs = require('nvim-treesitter.parsers')
local parsers = #_G.arg > 0 and { unpack(_G.arg) }
- or require('nvim-treesitter.config').installed_parsers()
+ or require('nvim-treesitter.config').installed_languages('parsers')
local data = {} ---@type table[]
local errors = {} ---@type string[]
diff --git a/scripts/check-queries.lua b/scripts/check-queries.lua
index 0a684f5eb..27869b6b5 100755
--- a/scripts/check-queries.lua
+++ b/scripts/check-queries.lua
@@ -4,7 +4,7 @@ vim.opt.runtimepath:append('.')
local query_types = require('nvim-treesitter.health').bundled_queries
local configs = require('nvim-treesitter.parsers')
local parsers = #_G.arg > 0 and { unpack(_G.arg) }
- or require('nvim-treesitter.config').installed_parsers()
+ or require('nvim-treesitter.config').installed_languages('queries')
-- Check queries for each installed parser in parsers
local errors = {} ---@type string[]