diff options
Diffstat (limited to 'lua/nvim-treesitter/health.lua')
| -rw-r--r-- | lua/nvim-treesitter/health.lua | 104 |
1 files changed, 59 insertions, 45 deletions
diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua index 3573e7f5a..4d5e39c43 100644 --- a/lua/nvim-treesitter/health.lua +++ b/lua/nvim-treesitter/health.lua @@ -3,6 +3,7 @@ local parsers = require('nvim-treesitter.parsers') local config = require('nvim-treesitter.config') local util = require('nvim-treesitter.util') local tsq = vim.treesitter.query +local health = vim.health local M = {} @@ -22,89 +23,109 @@ local function ts_cli_version() end local function install_health() - vim.health.start('Installation') + health.start('Requirements') if vim.fn.has('nvim-0.10') ~= 1 then - vim.health.error('Nvim-treesitter requires Neovim Nightly') + health.error('Nvim-treesitter requires Neovim Nightly') end if vim.fn.executable('tree-sitter') == 0 then - vim.health.warn( + health.warn( '`tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar,' .. ' not required for :TSInstall)' ) else - vim.health.ok( + health.ok( '`tree-sitter` found ' .. (ts_cli_version() or '(unknown version)') - .. ' (parser generator, only needed for :TSInstallFromGrammar)' + .. ' (only needed for `:TSInstallFromGrammar`)' ) end if vim.fn.executable('node') == 0 then - vim.health.warn( - '`node` executable not found (only needed for :TSInstallFromGrammar,' - .. ' not required for :TSInstall)' - ) + health.warn('`node` executable not found (only needed for `:TSInstallFromGrammar`.') else local handle = assert(io.popen('node --version')) local result = handle:read('*a') handle:close() local version = vim.split(result, '\n')[1] - vim.health.ok('`node` found ' .. version .. ' (only needed for :TSInstallFromGrammar)') + health.ok('`node` found ' .. version .. ' (only needed for `:TSInstallFromGrammar`)') end if vim.fn.executable('git') == 0 then - vim.health.error('`git` executable not found.', { - 'Install it with your package manager.', - 'Check that your `$PATH` is set correctly.', - }) + health.error( + '`git` executable not found.', + 'Install it with your package manager and check that your `$PATH` is set correctly.' + ) else - vim.health.ok('`git` executable found.') + health.ok('`git` executable found.') end local cc = install.select_executable(install.compilers) if not cc then - vim.health.error('`cc` executable not found.', { + health.error('`cc` executable not found.', { 'Check that any of ' - .. vim.inspect(install.compilers) + .. table.concat(install.compilers, ', ') .. ' is in your $PATH' - .. ' or set the environment variable CC or `require"nvim-treesitter.install".compilers` explicitly!', + .. ' or set `$CC` or `require"nvim-treesitter.install".compilers` explicitly.', }) else local version = vim.fn.systemlist(cc .. (cc == 'cl' and '' or ' --version'))[1] - vim.health.ok( + health.ok( '`' .. cc - .. '` executable found. Selected from ' - .. vim.inspect(install.compilers) + .. '` executable found, selected from: ' + .. table.concat(install.compilers, ', ') .. (version and ('\nVersion: ' .. version) or '') ) end if vim.treesitter.language_version then if vim.treesitter.language_version >= NVIM_TREESITTER_MINIMUM_ABI then - vim.health.ok( + health.ok( 'Neovim was compiled with tree-sitter runtime ABI version ' .. vim.treesitter.language_version .. ' (required >=' .. NVIM_TREESITTER_MINIMUM_ABI - .. '). Parsers must be compatible with runtime ABI.' + .. ').' ) else - vim.health.error( + health.error( 'Neovim was compiled with tree-sitter runtime ABI version ' .. vim.treesitter.language_version .. '.\n' .. 'nvim-treesitter expects at least ABI version ' .. NVIM_TREESITTER_MINIMUM_ABI .. '\n' - .. 'Please make sure that Neovim is linked against are recent tree-sitter runtime when building' + .. 'Please make sure that Neovim is linked against a recent tree-sitter library when building' .. ' or raise an issue at your Neovim packager. Parsers must be compatible with runtime ABI.' ) end end - vim.health.start('OS Info:\n' .. vim.inspect(vim.uv.os_uname())) + health.start('OS Info') + for k, v in pairs(vim.uv.os_uname()) do + health.info(k .. ': ' .. v) + end + + local installdir = config.get_install_dir('') + health.start('Install directory for parsers and queries') + health.info(installdir) + if vim.uv.fs_access(installdir, 'w') then + health.ok('is writable.') + else + health.error('is not writable.') + end + if + vim.iter(vim.api.nvim_list_runtime_paths()):any(function(p) + if installdir == p .. '/' then + return true + end + end) + then + health.ok('is in runtimepath.') + else + health.error('is not in runtimepath.') + end end local function query_status(lang, query_group) @@ -123,12 +144,13 @@ function M.check() local error_collection = {} -- Installation dependency checks install_health() + -- Parser installation checks + health.start('Installed languages' .. string.rep(' ', 5) .. 'H L F I J') local languages = config.installed_parsers() - local parser_installation = { 'Parser/Features' .. string.rep(' ', 9) .. 'H L F I J' } for _, lang in pairs(languages) do local parser = parsers.configs[lang] - local out = ' - ' .. lang .. string.rep(' ', 20 - #lang) + local out = lang .. string.rep(' ', 22 - #lang) if parser.install_info then for _, query_group in pairs(M.bundled_queries) do local status, err = query_status(lang, query_group) @@ -145,35 +167,27 @@ function M.check() end end end - table.insert(parser_installation, vim.fn.trim(out, ' ', 2)) + health.info(vim.fn.trim(out, ' ', 2)) end - local legend = [[ + health.start(' Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[J]ections') - Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[J]ections - x) errors found in the query, try to run :TSUpdate {lang}]] - table.insert(parser_installation, legend) - -- Finally call the report function - vim.health.start(table.concat(parser_installation, '\n')) if #error_collection > 0 then - vim.health.start('The following errors have been detected:') + health.start('The following errors have been detected in query files:') for _, p in ipairs(error_collection) do - local lang, type, err = p[1], p[2], p[3] + local lang, type = p[1], p[2] local lines = {} - table.insert(lines, lang .. '(' .. type .. '): ' .. err) + table.insert(lines, lang .. '(' .. type .. '): ') local files = tsq.get_files(lang, type) if #files > 0 then - table.insert(lines, lang .. '(' .. type .. ') is concatenated from the following files:') for _, file in ipairs(files) do local query = util.read_file(file) - local ok, file_err = pcall(tsq.parse, lang, query) - if ok then - table.insert(lines, '| [OK]:"' .. file .. '"') - else - table.insert(lines, '| [ERR]:"' .. file .. '", failed to load: ' .. file_err) + local _, file_err = pcall(tsq.parse, lang, query) + if file_err then + table.insert(lines, file) end end end - vim.health.error(table.concat(lines, '\n')) + health.error(table.concat(lines, '')) end end end |
