nvim-treesitter/scripts/check-queries.lua

63 lines
1.7 KiB
Lua
Raw Normal View History

2023-08-15 20:28:55 +03:00
#!/usr/bin/env -S nvim -l
vim.o.rtp = vim.o.rtp .. ',.'
2020-09-07 12:07:17 +02:00
2024-01-26 13:09:44 +01:00
local query_types = require('nvim-treesitter.health').bundled_queries
local configs = require('nvim-treesitter.parsers')
2024-01-26 13:09:44 +01:00
local parsers = #_G.arg > 0 and { unpack(_G.arg) }
or require('nvim-treesitter.config').get_installed('queries')
2024-01-26 13:09:44 +01:00
-- Check queries for each installed parser in parsers
local errors = {} ---@type string[]
2025-04-27 16:08:59 +02:00
local timings = {} ---@type { duration: number, lang: string, query_type: string }[]
2024-01-26 13:09:44 +01:00
do
print('::group::Check parsers')
2020-07-14 16:17:00 +02:00
for _, lang in pairs(parsers) do
2024-01-26 13:09:44 +01:00
if configs[lang] and configs[lang].install_info then
2023-06-03 12:08:14 +02:00
for _, query_type in pairs(query_types) do
local before = vim.uv.hrtime()
local ok, query = pcall(vim.treesitter.query.get, lang, query_type)
2024-01-26 13:09:44 +01:00
local duration = vim.uv.hrtime() - before
if query then
table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
print(string.format('Checking %s %s (%.02fms)', lang, query_type, duration * 1e-6))
end
2023-06-03 12:08:14 +02:00
if not ok then
2024-01-26 13:09:44 +01:00
errors[#errors + 1] = string.format('%s (%s): %s', lang, query_type, query)
2020-09-07 12:07:17 +02:00
end
end
2020-07-14 16:17:00 +02:00
end
end
2024-01-26 13:09:44 +01:00
print('::endgroup::')
2020-07-14 16:17:00 +02:00
end
2024-01-26 13:09:44 +01:00
-- Output
if #errors > 0 then
print('::group::Errors')
for _, err in ipairs(errors) do
print(err)
end
print('::endgroup::')
print('Check failed!\n')
vim.cmd.cq()
else
print('::group::Timings')
table.sort(timings, function(a, b)
2022-01-07 21:38:33 +01:00
return a.duration < b.duration
end)
2024-01-26 13:09:44 +01:00
for i, val in ipairs(timings) do
print(
string.format(
'%i. %.02fms %s %s',
2024-01-26 13:09:44 +01:00
#timings - i + 1,
val.duration * 1e-6,
val.lang,
val.query_type
)
)
2022-01-07 21:38:33 +01:00
end
2024-01-26 13:09:44 +01:00
print('::endgroup::')
print('Check successful!')
2020-07-14 16:17:00 +02:00
end