From 7049a66b54b59a9ff1d32193040e5dcdd9a441d5 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 29 Jan 2022 21:52:29 +0100 Subject: health: check which file caused an error --- lua/nvim-treesitter/health.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua index b26a9ef25..8cbe0db1c 100644 --- a/lua/nvim-treesitter/health.lua +++ b/lua/nvim-treesitter/health.lua @@ -142,7 +142,25 @@ function M.check() health_start "The following errors have been detected:" for _, p in ipairs(error_collection) do local lang, type, err = unpack(p) - health_error(lang .. "(" .. type .. "): " .. err) + local lines = {} + table.insert(lines, lang .. "(" .. type .. "): " .. err) + local files = vim.treesitter.query.get_query_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 fd = io.open(file, "r") + if fd then + local ok, file_err = pcall(vim.treesitter.query.parse_query, lang, fd:read "*a") + 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 + health_error(table.concat(lines, "\n")) end end end -- cgit v1.2.3-70-g09d2