2020-04-20 22:33:13 +02:00
|
|
|
local api = vim.api
|
2020-04-21 23:40:23 +02:00
|
|
|
local fn = vim.fn
|
2020-04-20 22:33:13 +02:00
|
|
|
|
2021-07-04 16:12:17 -05:00
|
|
|
local queries = require "nvim-treesitter.query"
|
|
|
|
|
local info = require "nvim-treesitter.info"
|
|
|
|
|
local shell = require "nvim-treesitter.shell_command_selectors"
|
|
|
|
|
local install = require "nvim-treesitter.install"
|
2022-01-22 11:02:55 +01:00
|
|
|
local utils = require "nvim-treesitter.utils"
|
2023-03-24 09:43:14 +00:00
|
|
|
local ts = require "nvim-treesitter.compat"
|
2020-04-20 22:33:13 +02:00
|
|
|
|
2022-06-02 12:45:54 +02:00
|
|
|
local health = vim.health or require "health"
|
2020-04-20 22:33:13 +02:00
|
|
|
|
2023-04-16 12:59:46 +02:00
|
|
|
-- "report_" prefix has been deprecated, use the recommended replacements if they exist.
|
|
|
|
|
local _start = health.start or health.report_start
|
|
|
|
|
local _ok = health.ok or health.report_ok
|
|
|
|
|
local _warn = health.warn or health.report_warn
|
|
|
|
|
local _error = health.error or health.report_error
|
|
|
|
|
|
2020-04-20 22:33:13 +02:00
|
|
|
local M = {}
|
|
|
|
|
|
2021-04-01 12:01:10 +02:00
|
|
|
local NVIM_TREESITTER_MINIMUM_ABI = 13
|
|
|
|
|
|
2020-04-22 11:13:05 +02:00
|
|
|
local function install_health()
|
2023-04-16 12:59:46 +02:00
|
|
|
_start "Installation"
|
2021-03-31 10:59:06 +02:00
|
|
|
|
2024-01-15 12:51:58 +01:00
|
|
|
if fn.has "nvim-0.9.2" ~= 1 then
|
|
|
|
|
_error "Nvim-treesitter requires Nvim 0.9.2 or newer"
|
2022-04-16 10:35:06 +02:00
|
|
|
end
|
|
|
|
|
|
2021-07-04 16:12:17 -05:00
|
|
|
if fn.executable "tree-sitter" == 0 then
|
2023-04-16 12:59:46 +02:00
|
|
|
_warn(
|
2021-07-04 16:12:17 -05:00
|
|
|
"`tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar,"
|
|
|
|
|
.. " not required for :TSInstall)"
|
|
|
|
|
)
|
2021-03-05 21:47:41 +08:00
|
|
|
else
|
2023-04-16 12:59:46 +02:00
|
|
|
_ok(
|
2021-07-04 16:12:17 -05:00
|
|
|
"`tree-sitter` found "
|
2022-01-22 11:02:55 +01:00
|
|
|
.. (utils.ts_cli_version() or "(unknown version)")
|
2021-07-04 16:12:17 -05:00
|
|
|
.. " (parser generator, only needed for :TSInstallFromGrammar)"
|
2021-06-03 23:48:36 +02:00
|
|
|
)
|
2021-03-05 21:47:41 +08:00
|
|
|
end
|
|
|
|
|
|
2021-07-04 16:12:17 -05:00
|
|
|
if fn.executable "node" == 0 then
|
2023-04-16 12:59:46 +02:00
|
|
|
_warn("`node` executable not found (only needed for :TSInstallFromGrammar," .. " not required for :TSInstall)")
|
2021-04-01 11:37:07 +02:00
|
|
|
else
|
2021-07-04 16:12:17 -05:00
|
|
|
local handle = io.popen "node --version"
|
|
|
|
|
local result = handle:read "*a"
|
2021-04-01 11:37:07 +02:00
|
|
|
handle:close()
|
2021-07-04 16:12:17 -05:00
|
|
|
local version = vim.split(result, "\n")[1]
|
2023-04-16 12:59:46 +02:00
|
|
|
_ok("`node` found " .. version .. " (only needed for :TSInstallFromGrammar)")
|
2021-04-01 11:37:07 +02:00
|
|
|
end
|
|
|
|
|
|
2021-07-04 16:12:17 -05:00
|
|
|
if fn.executable "git" == 0 then
|
2023-04-16 12:59:46 +02:00
|
|
|
_error("`git` executable not found.", {
|
2021-07-04 16:12:17 -05:00
|
|
|
"Install it with your package manager.",
|
|
|
|
|
"Check that your `$PATH` is set correctly.",
|
2021-02-22 23:01:12 +01:00
|
|
|
})
|
2020-04-21 23:40:23 +02:00
|
|
|
else
|
2023-04-16 12:59:46 +02:00
|
|
|
_ok "`git` executable found."
|
2020-04-21 23:40:23 +02:00
|
|
|
end
|
|
|
|
|
|
2021-04-07 12:00:41 +02:00
|
|
|
local cc = shell.select_executable(install.compilers)
|
|
|
|
|
if not cc then
|
2023-04-16 12:59:46 +02:00
|
|
|
_error("`cc` executable not found.", {
|
2021-07-04 16:12:17 -05:00
|
|
|
"Check that any of "
|
|
|
|
|
.. vim.inspect(install.compilers)
|
|
|
|
|
.. " is in your $PATH"
|
|
|
|
|
.. ' or set the environment variable CC or `require"nvim-treesitter.install".compilers` explicitly!',
|
2021-02-22 23:01:12 +01:00
|
|
|
})
|
2020-04-21 23:40:23 +02:00
|
|
|
else
|
2021-10-02 00:18:55 +02:00
|
|
|
local version = vim.fn.systemlist(cc .. (cc == "cl" and "" or " --version"))[1]
|
2023-04-16 12:59:46 +02:00
|
|
|
_ok(
|
2021-10-02 00:18:55 +02:00
|
|
|
"`"
|
|
|
|
|
.. cc
|
|
|
|
|
.. "` executable found. Selected from "
|
|
|
|
|
.. vim.inspect(install.compilers)
|
|
|
|
|
.. (version and ("\nVersion: " .. version) or "")
|
|
|
|
|
)
|
2020-04-21 23:40:23 +02:00
|
|
|
end
|
2021-03-31 10:59:06 +02:00
|
|
|
if vim.treesitter.language_version then
|
2021-04-01 12:01:10 +02:00
|
|
|
if vim.treesitter.language_version >= NVIM_TREESITTER_MINIMUM_ABI then
|
2023-04-16 12:59:46 +02:00
|
|
|
_ok(
|
2021-07-04 16:12:17 -05:00
|
|
|
"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."
|
|
|
|
|
)
|
2021-04-01 12:01:10 +02:00
|
|
|
else
|
2023-04-16 12:59:46 +02:00
|
|
|
_error(
|
2021-07-04 16:12:17 -05:00
|
|
|
"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"
|
|
|
|
|
.. " or raise an issue at your Neovim packager. Parsers must be compatible with runtime ABI."
|
|
|
|
|
)
|
2021-04-01 12:01:10 +02:00
|
|
|
end
|
2021-03-31 10:59:06 +02:00
|
|
|
end
|
2022-11-22 21:10:40 +01:00
|
|
|
|
2023-04-16 12:59:46 +02:00
|
|
|
_start("OS Info:\n" .. vim.inspect(vim.loop.os_uname()))
|
2020-04-21 23:40:23 +02:00
|
|
|
end
|
|
|
|
|
|
2021-02-22 22:14:38 +01:00
|
|
|
local function query_status(lang, query_group)
|
2021-03-23 20:44:17 +01:00
|
|
|
local ok, err = pcall(queries.get_query, lang, query_group)
|
2020-09-19 17:05:46 +02:00
|
|
|
if not ok then
|
2021-03-23 20:44:17 +01:00
|
|
|
return "x", err
|
|
|
|
|
elseif not err then
|
2021-02-22 22:14:38 +01:00
|
|
|
return "."
|
2020-04-26 15:38:32 +02:00
|
|
|
else
|
2021-02-22 22:14:38 +01:00
|
|
|
return "✓"
|
2020-04-26 15:38:32 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-10-06 09:29:08 -05:00
|
|
|
function M.check()
|
2021-03-23 20:44:17 +01:00
|
|
|
local error_collection = {}
|
2020-04-20 22:33:13 +02:00
|
|
|
-- Installation dependency checks
|
2020-04-22 11:13:05 +02:00
|
|
|
install_health()
|
2021-03-23 20:44:17 +01:00
|
|
|
queries.invalidate_query_cache()
|
2020-04-20 22:33:13 +02:00
|
|
|
-- Parser installation checks
|
2022-12-21 12:22:45 +01:00
|
|
|
local parser_installation = { "Parser/Features" .. string.rep(" ", 9) .. "H L F I J" }
|
2020-08-27 20:53:45 +02:00
|
|
|
for _, parser_name in pairs(info.installed_parsers()) do
|
2021-07-04 16:12:17 -05:00
|
|
|
local installed = #api.nvim_get_runtime_file("parser/" .. parser_name .. ".so", false)
|
2020-04-20 22:33:13 +02:00
|
|
|
|
2021-10-06 09:29:08 -05:00
|
|
|
-- Only append information about installed parsers
|
2020-08-27 20:53:45 +02:00
|
|
|
if installed >= 1 then
|
2021-03-18 11:06:21 +05:30
|
|
|
local multiple_parsers = installed > 1 and "+" or ""
|
2022-12-21 12:22:45 +01:00
|
|
|
local out = " - " .. parser_name .. multiple_parsers .. string.rep(" ", 20 - (#parser_name + #multiple_parsers))
|
2020-07-15 00:38:09 +02:00
|
|
|
for _, query_group in pairs(queries.built_in_query_groups) do
|
2021-03-23 20:44:17 +01:00
|
|
|
local status, err = query_status(parser_name, query_group)
|
2021-07-04 16:12:17 -05:00
|
|
|
out = out .. status .. " "
|
2021-03-23 20:44:17 +01:00
|
|
|
if err then
|
2021-07-04 16:12:17 -05:00
|
|
|
table.insert(error_collection, { parser_name, query_group, err })
|
2021-03-23 20:44:17 +01:00
|
|
|
end
|
2020-07-15 00:38:09 +02:00
|
|
|
end
|
2022-08-02 01:33:35 +02:00
|
|
|
table.insert(parser_installation, vim.fn.trim(out, " ", 2))
|
2020-04-20 22:33:13 +02:00
|
|
|
end
|
|
|
|
|
end
|
2021-10-06 09:29:08 -05:00
|
|
|
local legend = [[
|
2021-03-17 15:20:10 +01:00
|
|
|
|
2021-10-06 09:29:08 -05:00
|
|
|
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
|
2021-03-18 11:06:21 +05:30
|
|
|
+) multiple parsers found, only one will be used
|
2021-07-04 16:12:17 -05:00
|
|
|
x) errors found in the query, try to run :TSUpdate {lang}]]
|
2021-10-06 09:29:08 -05:00
|
|
|
table.insert(parser_installation, legend)
|
|
|
|
|
-- Finally call the report function
|
2023-04-16 12:59:46 +02:00
|
|
|
_start(table.concat(parser_installation, "\n"))
|
2021-03-23 20:44:17 +01:00
|
|
|
if #error_collection > 0 then
|
2023-04-16 12:59:46 +02:00
|
|
|
_start "The following errors have been detected:"
|
2021-03-23 20:44:17 +01:00
|
|
|
for _, p in ipairs(error_collection) do
|
|
|
|
|
local lang, type, err = unpack(p)
|
2022-01-29 21:52:29 +01:00
|
|
|
local lines = {}
|
|
|
|
|
table.insert(lines, lang .. "(" .. type .. "): " .. err)
|
2023-03-24 09:43:14 +00:00
|
|
|
local files = ts.get_query_files(lang, type)
|
2022-01-29 21:52:29 +01:00
|
|
|
if #files > 0 then
|
|
|
|
|
table.insert(lines, lang .. "(" .. type .. ") is concatenated from the following files:")
|
|
|
|
|
for _, file in ipairs(files) do
|
|
|
|
|
local fd = io.open(file, "r")
|
|
|
|
|
if fd then
|
2023-03-24 09:43:14 +00:00
|
|
|
local ok, file_err = pcall(ts.parse_query, lang, fd:read "*a")
|
2022-01-29 21:52:29 +01:00
|
|
|
if ok then
|
|
|
|
|
table.insert(lines, '| [OK]:"' .. file .. '"')
|
|
|
|
|
else
|
|
|
|
|
table.insert(lines, '| [ERROR]:"' .. file .. '", failed to load: ' .. file_err)
|
|
|
|
|
end
|
|
|
|
|
fd:close()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-04-16 12:59:46 +02:00
|
|
|
_error(table.concat(lines, "\n"))
|
2021-03-23 20:44:17 +01:00
|
|
|
end
|
|
|
|
|
end
|
2020-04-20 22:33:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|