diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2021-04-07 16:40:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-07 16:40:56 +0200 |
commit | cd75d3289aa7ae4176b9cee9aceafb4b9abdba5e (patch) | |
tree | a32873fb0e3c9d6b5f6e6a409381bb42c3ffde58 | |
parent | 91cdc11984465287539ed8f63716bb371f440ea1 (diff) | |
parent | 952508d4056b7869720f4a446f2d49963eaf937d (diff) | |
download | rneovim-cd75d3289aa7ae4176b9cee9aceafb4b9abdba5e.tar.gz rneovim-cd75d3289aa7ae4176b9cee9aceafb4b9abdba5e.tar.bz2 rneovim-cd75d3289aa7ae4176b9cee9aceafb4b9abdba5e.zip |
Merge pull request #14200 from teto/treesitter-checkhealth
feat: treesitter checkhealth
-rw-r--r-- | runtime/autoload/health/treesitter.vim | 5 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/health.lua | 34 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 5 | ||||
-rw-r--r-- | test/functional/treesitter/language_spec.lua | 2 |
5 files changed, 48 insertions, 1 deletions
diff --git a/runtime/autoload/health/treesitter.vim b/runtime/autoload/health/treesitter.vim new file mode 100644 index 0000000000..5f167310ce --- /dev/null +++ b/runtime/autoload/health/treesitter.vim @@ -0,0 +1,5 @@ +function! health#treesitter#check() abort + call health#report_start('Checking treesitter configuration') + lua require 'vim.treesitter.health'.check_health() +endfunction + diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index cac0ab864b..f223c7b8c8 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -17,6 +17,9 @@ setmetatable(M, { if k == "highlighter" then t[k] = require'vim.treesitter.highlighter' return t[k] + elseif k == "language" then + t[k] = require"vim.treesitter.language" + return t[k] end end }) diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua new file mode 100644 index 0000000000..dd0b11a6c7 --- /dev/null +++ b/runtime/lua/vim/treesitter/health.lua @@ -0,0 +1,34 @@ +local M = {} +local ts = vim.treesitter + +function M.list_parsers() + return vim.api.nvim_get_runtime_file('parser/*', true) +end + +function M.check_health() + local report_info = vim.fn['health#report_info'] + local report_ok = vim.fn['health#report_ok'] + local report_error = vim.fn['health#report_error'] + local parsers = M.list_parsers() + + report_info(string.format("Runtime ABI version : %d", ts.language_version)) + + for _, parser in pairs(parsers) do + local parsername = vim.fn.fnamemodify(parser, ":t:r") + + local is_loadable, ret = pcall(ts.language.require_language, parsername) + + if not is_loadable then + report_error(string.format("Impossible to load parser for %s: %s", parsername, ret)) + elseif ret then + local lang = ts.language.inspect_language(parsername) + report_ok(string.format("Loaded parser for %s: ABI version %d", + parsername, lang._abi_version)) + else + report_error(string.format("Unable to load parser for %s", parsername)) + end + end +end + +return M + diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 38848b0266..c186928ae2 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -230,6 +230,11 @@ int tslua_inspect_lang(lua_State *L) } lua_setfield(L, -2, "fields"); // [retval] + + uint32_t lang_version = ts_language_version(lang); + lua_pushinteger(L, lang_version); // [retval, version] + lua_setfield(L, -2, "_abi_version"); + return 1; } diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua index a5801271cb..afb17dd2cf 100644 --- a/test/functional/treesitter/language_spec.lua +++ b/test/functional/treesitter/language_spec.lua @@ -45,7 +45,7 @@ describe('treesitter API', function() return {keys, lang.fields, symbols} ]])) - eq({fields=true, symbols=true}, keys) + eq({fields=true, symbols=true, _abi_version=true}, keys) local fset = {} for _,f in pairs(fields) do |