diff options
Diffstat (limited to 'runtime/lua/vim/treesitter')
-rw-r--r-- | runtime/lua/vim/treesitter/health.lua | 34 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 14 |
2 files changed, 46 insertions, 2 deletions
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/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 79a88c5dbb..ed5146be44 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -22,6 +22,16 @@ local function dedupe_files(files) return result end +local function safe_read(filename, read_quantifier) + local file, err = io.open(filename, 'r') + if not file then + error(err) + end + local content = file:read(read_quantifier) + io.close(file) + return content +end + function M.get_query_files(lang, query_name, is_included) local query_path = string.format('queries/%s/%s.scm', lang, query_name) local lang_files = dedupe_files(a.nvim_get_runtime_file(query_path, true)) @@ -38,7 +48,7 @@ function M.get_query_files(lang, query_name, is_included) local MODELINE_FORMAT = "^;+%s*inherits%s*:?%s*([a-z_,()]+)%s*$" for _, file in ipairs(lang_files) do - local modeline = io.open(file, 'r'):read('*l') + local modeline = safe_read(file, '*l') if modeline then local langlist = modeline:match(MODELINE_FORMAT) @@ -73,7 +83,7 @@ local function read_query_files(filenames) local contents = {} for _,filename in ipairs(filenames) do - table.insert(contents, io.open(filename, 'r'):read('*a')) + table.insert(contents, safe_read(filename, '*a')) end return table.concat(contents, '') |