mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-05 21:10:15 -04:00
feat(api): expose list of available and installed languages
This commit is contained in:
parent
0860b9b107
commit
ce903fde5d
8 changed files with 36 additions and 13 deletions
|
|
@ -41,7 +41,7 @@ end
|
|||
|
||||
---@param type 'queries'|'parsers'?
|
||||
---@return string[]
|
||||
function M.installed_languages(type)
|
||||
function M.get_installed(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
|
||||
|
|
@ -107,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_languages()
|
||||
return M.get_installed()
|
||||
end
|
||||
languages = M.get_available()
|
||||
end
|
||||
|
|
@ -115,7 +115,7 @@ function M.norm_languages(languages, skip)
|
|||
languages = expand_tiers(languages)
|
||||
|
||||
if skip and skip.installed then
|
||||
local installed = M.installed_languages()
|
||||
local installed = M.get_installed()
|
||||
languages = vim.tbl_filter(
|
||||
--- @param v string
|
||||
function(v)
|
||||
|
|
@ -126,7 +126,7 @@ function M.norm_languages(languages, skip)
|
|||
end
|
||||
|
||||
if skip and skip.missing then
|
||||
local installed = M.installed_languages()
|
||||
local installed = M.get_installed()
|
||||
languages = vim.tbl_filter(
|
||||
--- @param v string
|
||||
function(v)
|
||||
|
|
|
|||
|
|
@ -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_languages()
|
||||
local languages = config.get_installed()
|
||||
for _, lang in pairs(languages) do
|
||||
local parser = parsers[lang]
|
||||
local out = lang .. string.rep(' ', 22 - #lang)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@ function M.setup(...)
|
|||
require('nvim-treesitter.config').setup(...)
|
||||
end
|
||||
|
||||
function M.get_available(...)
|
||||
return require('nvim-treesitter.config').get_available(...)
|
||||
end
|
||||
|
||||
function M.get_installed(...)
|
||||
return require('nvim-treesitter.config').get_installed(...)
|
||||
end
|
||||
|
||||
function M.install(...)
|
||||
return require('nvim-treesitter.install').install(...)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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_languages(), lang) then
|
||||
if not force and vim.list_contains(config.get_installed(), lang) then
|
||||
install_status[lang] = 'installed'
|
||||
return 'installed'
|
||||
end
|
||||
|
|
@ -537,7 +537,7 @@ M.uninstall = a.async(function(languages)
|
|||
|
||||
local parser_dir = config.get_install_dir('parser')
|
||||
local query_dir = config.get_install_dir('queries')
|
||||
local installed = config.installed_languages()
|
||||
local installed = config.get_installed()
|
||||
|
||||
local task_funs = {} ---@type async.TaskFun[]
|
||||
local done = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue