diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/config.lua | 13 | ||||
| -rw-r--r-- | lua/nvim-treesitter/health.lua | 26 | ||||
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 137 | ||||
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 57 |
4 files changed, 152 insertions, 81 deletions
diff --git a/lua/nvim-treesitter/config.lua b/lua/nvim-treesitter/config.lua index b8a9f6e91..c77ee1358 100644 --- a/lua/nvim-treesitter/config.lua +++ b/lua/nvim-treesitter/config.lua @@ -74,12 +74,11 @@ end ---@return string[] function M.installed_parsers() - local install_dir = M.get_install_dir('parser') + local install_dir = M.get_install_dir('queries') local installed = {} --- @type string[] for f in vim.fs.dir(install_dir) do - local lang = assert(f:match('(.*)%..*')) - installed[#installed + 1] = lang + installed[#installed + 1] = f end return installed @@ -139,6 +138,14 @@ function M.norm_languages(languages, skip) end, languages) --[[@as string[] ]] end + if not (skip and skip.dependencies) then + for _, lang in pairs(languages) do + if parsers.configs[lang].requires then + vim.list_extend(languages, parsers.configs[lang].requires) + end + end + end + return languages end diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua index 1e17bb00b..037887c59 100644 --- a/lua/nvim-treesitter/health.lua +++ b/lua/nvim-treesitter/health.lua @@ -1,4 +1,5 @@ local install = require('nvim-treesitter.install') +local parsers = require('nvim-treesitter.parsers') local config = require('nvim-treesitter.config') local util = require('nvim-treesitter.util') local tsq = vim.treesitter.query @@ -123,14 +124,25 @@ function M.check() -- Installation dependency checks install_health() -- Parser installation checks + local languages = config.installed_parsers() local parser_installation = { 'Parser/Features' .. string.rep(' ', 9) .. 'H L F I J' } - for _, parser_name in pairs(config.installed_parsers()) do - local out = ' - ' .. parser_name .. string.rep(' ', 20 - #parser_name) - for _, query_group in pairs(M.bundled_queries) do - local status, err = query_status(parser_name, query_group) - out = out .. status .. ' ' - if err then - table.insert(error_collection, { parser_name, query_group, err }) + for _, lang in pairs(languages) do + local parser = parsers.configs[lang] + local out = ' - ' .. lang .. string.rep(' ', 20 - #lang) + if parser.install_info then + for _, query_group in pairs(M.bundled_queries) do + local status, err = query_status(lang, query_group) + out = out .. status .. ' ' + if err then + table.insert(error_collection, { lang, query_group, err }) + end + end + end + if parser.requires then + for _, p in pairs(parser.requires) do + if not vim.list_contains(languages, p) then + table.insert(error_collection, { lang, 'queries', 'dependency ' .. p .. ' missing' }) + end end end table.insert(parser_installation, vim.fn.trim(out, ' ', 2)) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index ab9543673..3fba73db4 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -449,74 +449,76 @@ local function install_lang(lang, cache_dir, install_dir, force, generate_from_g end end - local cc = M.select_executable(M.compilers) - if not cc then - cc_err() - return - end + local logger = log.new('install/' .. lang) + local err local repo = get_parser_install_info(lang) + if repo then + local cc = M.select_executable(M.compilers) + if not cc then + cc_err() + return + end - local project_name = 'tree-sitter-' .. lang - - local logger = log.new('install/' .. lang) + local project_name = 'tree-sitter-' .. lang - generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar + generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar - if generate_from_grammar and vim.fn.executable('tree-sitter') ~= 1 then - logger:error('tree-sitter CLI not found: `tree-sitter` is not executable') - end + if generate_from_grammar and vim.fn.executable('tree-sitter') ~= 1 then + logger:error('tree-sitter CLI not found: `tree-sitter` is not executable') + end - if generate_from_grammar and vim.fn.executable('node') ~= 1 then - logger:error('Node JS not found: `node` is not executable') - end + if generate_from_grammar and vim.fn.executable('node') ~= 1 then + logger:error('Node JS not found: `node` is not executable') + end - local revision = repo.revision or get_target_revision(lang) + local revision = repo.revision or get_target_revision(lang) - local maybe_local_path = fs.normalize(repo.url) - local from_local_path = vim.fn.isdirectory(maybe_local_path) == 1 - if from_local_path then - repo.url = maybe_local_path - end + local maybe_local_path = fs.normalize(repo.url) + local from_local_path = vim.fn.isdirectory(maybe_local_path) == 1 + if from_local_path then + repo.url = maybe_local_path + end - if not from_local_path then - util.delete(fs.joinpath(cache_dir, project_name)) - local project_dir = fs.joinpath(cache_dir, project_name) + if not from_local_path then + util.delete(fs.joinpath(cache_dir, project_name)) + local project_dir = fs.joinpath(cache_dir, project_name) - revision = revision or repo.branch or 'master' + revision = revision or repo.branch or 'master' - if can_download_tar(repo) then - do_download_tar(logger, repo, project_name, cache_dir, revision, project_dir) - else - do_download_git(logger, repo, project_name, cache_dir, revision, project_dir) + if can_download_tar(repo) then + do_download_tar(logger, repo, project_name, cache_dir, revision, project_dir) + else + do_download_git(logger, repo, project_name, cache_dir, revision, project_dir) + end end - end - local compile_location = get_compile_location(repo, cache_dir, project_name, from_local_path) + local compile_location = get_compile_location(repo, cache_dir, project_name, from_local_path) - if generate_from_grammar then - do_generate_from_grammar(logger, repo, compile_location) - end + if generate_from_grammar then + do_generate_from_grammar(logger, repo, compile_location) + end - logger:info('Compiling parser') - local r = do_compile(repo, cc, compile_location) - if r.exit_code > 0 then - logger:error('Error during compilation: ' .. vim.inspect(r.stderr)) - end + logger:info('Compiling parser') + local r = do_compile(repo, cc, compile_location) + if r.exit_code > 0 then + logger:error('Error during compilation: ' .. vim.inspect(r.stderr)) + end - local parser_lib_name = fs.joinpath(install_dir, lang) .. '.so' + local parser_lib_name = fs.joinpath(install_dir, lang) .. '.so' - local err = uv_copyfile(fs.joinpath(compile_location, 'parser.so'), parser_lib_name) - a.main() - if err then - logger:error(err) - end + err = uv_copyfile(fs.joinpath(compile_location, 'parser.so'), parser_lib_name) + a.main() + if err then + logger:error(err) + end - local revfile = fs.joinpath(config.get_install_dir('parser-info') or '', lang .. '.revision') - util.write_file(revfile, revision or '') + local revfile = fs.joinpath(config.get_install_dir('parser-info') or '', lang .. '.revision') + util.write_file(revfile, revision or '') - if not from_local_path then - util.delete(fs.joinpath(cache_dir, project_name)) + if not from_local_path then + util.delete(fs.joinpath(cache_dir, project_name)) + end end local queries = fs.joinpath(config.get_install_dir('queries'), lang) @@ -527,7 +529,7 @@ local function install_lang(lang, cache_dir, install_dir, force, generate_from_g if err then logger:error(err) end - logger:info('Parser installed') + logger:info('Language installed') end --- Throttles a function using the first argument as an ID @@ -617,7 +619,7 @@ local function install(languages, options, _callback) a.join(max_jobs, nil, tasks) if #tasks > 1 then a.main() - log.info('Installed %d/%d parsers', done, #tasks) + log.info('Installed %d/%d languages', done, #tasks) end end @@ -650,34 +652,35 @@ end, 2) local function uninstall_lang(lang, parser, queries) local logger = log.new('uninstall/' .. lang) logger:debug('Uninstalling ' .. lang) - if vim.fn.filereadable(parser) ~= 1 then - return - end - logger:debug('Unlinking ' .. parser) - local perr = uv_unlink(parser) - a.main() + if vim.fn.filereadable(parser) == 1 then + logger:debug('Unlinking ' .. parser) + local perr = uv_unlink(parser) + a.main() - if perr then - log.error(perr) + if perr then + log.error(perr) + end end - logger:debug('Unlinking ' .. queries) - local qerr = uv_unlink(queries) - a.main() + if vim.fn.isdirectory(queries) == 1 then + logger:debug('Unlinking ' .. queries) + local qerr = uv_unlink(queries) + a.main() - if qerr then - logger:error(qerr) + if qerr then + logger:error(qerr) + end end - logger:info('Parser uninstalled') + logger:info('Language uninstalled') end --- @param languages string[]|string --- @param _options? UpdateOptions --- @param _callback fun() M.uninstall = a.sync(function(languages, _options, _callback) - languages = config.norm_languages(languages or 'all', { missing = true }) + 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') @@ -701,7 +704,7 @@ M.uninstall = a.sync(function(languages, _options, _callback) a.join(max_jobs, nil, tasks) if #tasks > 1 then a.main() - log.info('Uninstalled %d/%d parsers', done, #tasks) + log.info('Uninstalled %d/%d languages', done, #tasks) end end, 2) diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 114ab40c6..3a9a36aaf 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -12,6 +12,7 @@ ---@field install_info InstallInfo ---@field filetype string[] ---@field maintainers string[] +---@field requires string[] ---@field tier integer|nil |
