aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/nvim-treesitter.txt10
-rw-r--r--lua/nvim-treesitter/health.lua104
-rw-r--r--lua/nvim-treesitter/install.lua39
-rw-r--r--plugin/nvim-treesitter.lua4
4 files changed, 70 insertions, 87 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index a7c6bfa69..8b530550c 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -31,7 +31,7 @@ Install the parser for your language
To get a list of supported languages
>vim
- :TSInstallInfo
+ :TSInstall <tab>
<
To install supported parsers and queries, put this in your `init.lua` file:
@@ -50,9 +50,10 @@ To install supported parsers and queries, put this in your `init.lua` file:
-- List of parsers to ignore installing (for "core" etc.)
ignore_install = { "javascript" },
+ }
<
-See |nvim-treesitter-commands| for a list of all available commands.
+To check installed parsers and queries, use `:checkhealth nvim-treesitter`.
==============================================================================
COMMANDS *nvim-treesitter-commands*
@@ -64,11 +65,6 @@ Install one or more treesitter parsers.
You can use |:TSInstall| `all` to install all parsers. Use |:TSInstall!| to
force the reinstallation of already installed parsers.
- *:TSInstallInfo*
-:TSInstallInfo ~
-
-List information about currently installed parsers
-
*:TSUpdate*
:TSUpdate {language} ... ~
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
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 84bc99024..77242d730 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -1,4 +1,3 @@
-local api = vim.api
local fs = vim.fs
local uv = vim.uv
@@ -38,7 +37,10 @@ local iswin = uv.os_uname().sysname == 'Windows_NT'
local ismac = uv.os_uname().sysname == 'Darwin'
--- @diagnostic disable-next-line:missing-parameter
-M.compilers = { uv.os_getenv('CC'), 'cc', 'gcc', 'clang', 'cl', 'zig' }
+M.compilers = { 'cc', 'gcc', 'clang', 'cl', 'zig' }
+if uv.os_getenv('CC') then
+ table.insert(M.compilers, 1, uv.os_getenv('CC'))
+end
---
--- PARSER INFO
@@ -104,31 +106,6 @@ local function needs_update(lang)
return not revision or revision ~= get_installed_revision(lang)
end
-function M.info()
- local installed = config.installed_parsers()
- local parser_list = parsers.get_available()
-
- local max_len = 0
- for _, lang in pairs(parser_list) do
- if #lang > max_len then
- max_len = #lang
- end
- end
-
- for _, lang in pairs(parser_list) do
- local parser = (lang .. string.rep(' ', max_len - #lang + 1))
- local output --- @type string[]
- if vim.list_contains(installed, lang) then
- output = { parser .. '[✓] installed', 'DiagnosticOk' }
- elseif #api.nvim_get_runtime_file('parser/' .. lang .. '.*', true) > 0 then
- output = { parser .. '[·] not installed (but available from runtimepath)', 'DiagnosticInfo' }
- else
- output = { parser .. '[✗] not installed' }
- end
- api.nvim_echo({ output }, false, {})
- end
-end
-
---
--- PARSER MANAGEMENT FUNCTIONS
---
@@ -157,7 +134,7 @@ end
local function cc_err()
log.error('No C compiler found! "' .. table.concat(
- vim.tbl_filter(
+ vim.iter.filter(
---@param c string
---@return boolean
function(c)
@@ -328,11 +305,11 @@ end
---@param executables string[]
---@return string?
function M.select_executable(executables)
- return vim.tbl_filter(
+ return vim.iter.filter(
---@param c string
---@return boolean
function(c)
- return c ~= vim.NIL and vim.fn.executable(c) == 1
+ return vim.fn.executable(c) == 1
end,
executables
)[1]
@@ -378,7 +355,7 @@ local function select_compiler_args(repo, compiler)
}
if
- #vim.tbl_filter(
+ #vim.iter.filter(
--- @param file string
--- @return boolean
function(file)
diff --git a/plugin/nvim-treesitter.lua b/plugin/nvim-treesitter.lua
index fcf44d537..0bcbe07c3 100644
--- a/plugin/nvim-treesitter.lua
+++ b/plugin/nvim-treesitter.lua
@@ -18,10 +18,6 @@ local function complete_installed_parsers(arglead)
end
-- create user commands
-api.nvim_create_user_command('TSInstallInfo', function()
- require('nvim-treesitter.install').info()
-end, { nargs = 0, desc = 'List available treesitter parsers' })
-
api.nvim_create_user_command('TSInstall', function(args)
require('nvim-treesitter.install').install(args.fargs, { force = args.bang })
end, {