aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorKiyan Yazdani <yazdani.kiyan@protonmail.com>2020-04-21 18:26:07 +0200
committerGitHub <noreply@github.com>2020-04-21 18:26:07 +0200
commitb72559f9c2d87a90dbe8417276571c953b7b5292 (patch)
tree916f722c69f23c85247b65528a74ff9c17382f87 /lua
parentMerge pull request #10 from vigoux/feature/node-utils (diff)
parentfeat: add checkhealth (diff)
downloadnvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.tar
nvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.tar.gz
nvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.tar.bz2
nvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.tar.lz
nvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.tar.xz
nvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.tar.zst
nvim-treesitter-b72559f9c2d87a90dbe8417276571c953b7b5292.zip
Merge pull request #12 from vigoux/checkhealth
feat: checkhealth
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/health.lua49
-rw-r--r--lua/nvim-treesitter/install.lua26
-rw-r--r--lua/nvim-treesitter/locals.lua16
3 files changed, 90 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua
new file mode 100644
index 000000000..b5e869804
--- /dev/null
+++ b/lua/nvim-treesitter/health.lua
@@ -0,0 +1,49 @@
+local api = vim.api
+
+local install = require'nvim-treesitter.install'
+local queries = require'nvim-treesitter.query'
+local locals = require'nvim-treesitter.locals'
+
+local health_start = vim.fn["health#report_start"]
+local health_ok = vim.fn['health#report_ok']
+local health_info = vim.fn['health#report_info']
+local health_warn = vim.fn['health#report_warn']
+local health_error = vim.fn['health#report_error']
+
+local M = {}
+
+-- TODO(vigoux): Maybe we should move each check to be perform in its own module
+function M.checkhealth()
+ -- Installation dependency checks
+ health_start('Installation')
+ install.checkhealth()
+
+ local missing_parsers = {}
+ -- Parser installation checks
+ for parser_name, repo in pairs(install.repositories) do
+ local installed = #api.nvim_get_runtime_file('parser/'..parser_name..'.so', false)
+
+ -- Only print informations about installed parsers
+ if installed == 1 then
+ health_start(parser_name .. " parser healthcheck")
+ health_ok(parser_name .. " parser found.")
+
+ locals.checkhealth(parser_name)
+ elseif installed > 1 then
+ health_warn(string.format("Multiple parsers found for %s, only %s will be used.", parser_name, installed[1]))
+ else
+ table.insert(missing_parsers, parser_name)
+ end
+ end
+
+ -- Add informations on parsers we dont find
+ if #missing_parsers > 0 then
+ health_start('Missing parsers')
+
+ -- TODO(vigoux): The installation command should be changed so that its easier to find
+ health_warn('Some parsers are not installed:\n' .. table.concat(missing_parsers, '\n'), {
+ "Install them using `:lua require'nvim-treesitter'.install_parser('language')`"})
+ end
+end
+
+return M
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 62af9a628..7674c4b08 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -3,7 +3,7 @@ local fn = vim.fn
local luv = vim.loop
local M = {}
-local repositories = {
+M.repositories = {
javascript = {
url = "https://github.com/tree-sitter/tree-sitter-javascript",
files = { "src/parser.c", "src/scanner.c" },
@@ -198,4 +198,28 @@ function M.install_parser(ft)
run_install(cache_folder, package_path, ft, repository)
end
+function M.checkhealth()
+ local health_ok = vim.fn['health#report_ok']
+ local health_info = vim.fn['health#report_info']
+ local health_warn = vim.fn['health#report_warn']
+ local health_error = vim.fn['health#report_error']
+
+ if fn.executable('git') == 0 then
+ health_error('`git` executable not found.', {
+ 'Install it with your package manager.',
+ 'Check that your `$PATH` is set correctly.'})
+ else
+ health_ok('`git` executable found.')
+ end
+
+ if fn.executable('cc') == 0 then
+ health_error('`cc` executable not found.', {
+ 'Install `gcc` with your package manager.',
+ 'Install `clang` with your package manager.',
+ 'Check that your `$PATH` is set correctly.'})
+ else
+ health_ok('`cc` executable found.')
+ end
+end
+
return M
diff --git a/lua/nvim-treesitter/locals.lua b/lua/nvim-treesitter/locals.lua
index 808b0f3ff..388c7e489 100644
--- a/lua/nvim-treesitter/locals.lua
+++ b/lua/nvim-treesitter/locals.lua
@@ -10,6 +10,22 @@ local M = {
locals={}
}
+function M.checkhealth(lang)
+ local health_start = vim.fn["health#report_start"]
+ local health_ok = vim.fn['health#report_ok']
+ local health_info = vim.fn['health#report_info']
+ local health_warn = vim.fn['health#report_warn']
+ local health_error = vim.fn['health#report_error']
+
+ if not queries.get_query(lang, "locals") then
+ health_warn("No `locals.scm` query found for " .. lang, {
+ "Open an issue at https://github.com/nvim-treesitter/nvim-treesitter"
+ })
+ else
+ health_ok("`locals.scm` found.")
+ end
+end
+
function M.collect_locals(bufnr)
local ft = api.nvim_buf_get_option(bufnr, "ft")
if not ft then return end