From 043f5a291a7cee269a533119bdd300afe339b535 Mon Sep 17 00:00:00 2001 From: Harsh Kapse <134696869+HarshK97@users.noreply.github.com> Date: Sat, 20 Dec 2025 21:04:24 +0530 Subject: [PATCH] feat(health): show available queries for `treesitter` (#37005) Problem: Outdated query files in `runtimepath` can trigger errors which are hard to diagnose. Solution: Add section to `:check treesitter` that lists all query files in `runtimepath`, sorted by language and query type. Files are listed in `runtimepath` order so that the first of multiple entry is typically the one that is used. Note: Unlike the `nvim-treesitter` health check, this does not try to parse the queries so will not flag incompatible ones (which would be much more expensive). --- runtime/lua/vim/treesitter/health.lua | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua index f283341536..28571fa9a3 100644 --- a/runtime/lua/vim/treesitter/health.lua +++ b/runtime/lua/vim/treesitter/health.lua @@ -64,6 +64,48 @@ function M.check() ) end end + + health.start('Treesitter queries') + local query_files = vim.api.nvim_get_runtime_file('queries/**/*.scm', true) + + ---@class QueryEntry + ---@field lang string + ---@field type string + ---@field path string + ---@field index integer + local queries_by_lang = {} ---@type table + + for i, query_file in ipairs(query_files) do + local lang, query_type = query_file:match('queries/([^/]+)/([^/]+)%.scm$') + if lang and query_type then + if not queries_by_lang[lang] then + queries_by_lang[lang] = {} + end + table.insert(queries_by_lang[lang], { + lang = lang, + type = query_type, + path = query_file, + index = i, + }) + end + end + + if not vim.tbl_isempty(queries_by_lang) then + for lang, queries in vim.spairs(queries_by_lang) do + table.sort(queries, function(a, b) + if a.type == b.type then + return a.index < b.index + else + return a.type < b.type + end + end) + + for _, query in ipairs(queries) do + local dir = vim.fn.fnamemodify(query.path, ':h') + health.ok(string.format('%-15s %-15s %s', lang, query.type, dir)) + end + end + end end return M