aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/check-queries.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-12 09:54:30 -0600
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit692b051b09935653befdb8f7ba8afdb640adf17b (patch)
tree167162b6b129ae04f68c5735078521a72917c742 /scripts/check-queries.lua
parentfeat(c-family): inherit injections (diff)
downloadnvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'scripts/check-queries.lua')
-rwxr-xr-xscripts/check-queries.lua80
1 files changed, 44 insertions, 36 deletions
diff --git a/scripts/check-queries.lua b/scripts/check-queries.lua
index f3b45ea1a..f5d6d463b 100755
--- a/scripts/check-queries.lua
+++ b/scripts/check-queries.lua
@@ -1,36 +1,35 @@
#!/usr/bin/env -S nvim -l
-vim.opt.rtp:prepend "./"
+vim.opt.runtimepath:append('.')
-- Equivalent to print(), but this will ensure consistent output regardless of
-- operating system.
local function io_print(text)
if not text then
- text = ""
+ text = ''
end
- io.write(text, "\n")
+ io.write(text, '\n')
end
local function extract_captures()
- local lines = vim.fn.readfile "CONTRIBUTING.md"
local captures = {}
local current_query
- for _, line in ipairs(lines) do
- if vim.startswith(line, "### ") then
- current_query = vim.fn.tolower(line:sub(5))
- elseif vim.startswith(line, "@") and current_query then
+ for line in io.lines('CONTRIBUTING.md') do
+ if vim.startswith(line, '### ') then
+ current_query = line:sub(5):lower()
+ elseif vim.startswith(line, '@') and current_query then
if not captures[current_query] then
captures[current_query] = {}
end
- table.insert(captures[current_query], vim.split(line:sub(2), " ", true)[1])
+ table.insert(captures[current_query], vim.split(line:sub(2), ' ', true)[1])
end
end
-- Complete captures for injections.
- local parsers = vim.tbl_keys(require("nvim-treesitter.parsers").list)
+ local parsers = vim.tbl_keys(require('nvim-treesitter.parsers').configs)
for _, lang in pairs(parsers) do
- table.insert(captures["injections"], lang)
+ table.insert(captures['injections'], lang)
end
return captures
@@ -38,36 +37,38 @@ end
local function do_check()
local timings = {}
- local queries = require "nvim-treesitter.query"
- local parsers = #_G.arg > 0 and { unpack(_G.arg) } or require("nvim-treesitter.info").installed_parsers()
- local query_types = queries.built_in_query_groups
+ local parsers = require('nvim-treesitter.config').installed_parsers()
+ local query_types = require('nvim-treesitter.health').bundled_queries
local captures = extract_captures()
local errors = {}
- io_print "::group::Check parsers"
+ io_print('::group::Check parsers')
for _, lang in pairs(parsers) do
timings[lang] = {}
for _, query_type in pairs(query_types) do
local before = vim.loop.hrtime()
- local ok, query = pcall(queries.get_query, lang, query_type)
+ local ok, query = pcall(vim.treesitter.query.get, lang, query_type)
local after = vim.loop.hrtime()
local duration = after - before
table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
- io_print("Checking " .. lang .. " " .. query_type .. string.format(" (%.02fms)", duration * 1e-6))
+ io_print(
+ 'Checking ' .. lang .. ' ' .. query_type .. string.format(' (%.02fms)', duration * 1e-6)
+ )
if not ok then
- local err_msg = lang .. " (" .. query_type .. "): " .. query
+ local err_msg = lang .. ' (' .. query_type .. '): ' .. query
errors[#errors + 1] = err_msg
else
if query then
for _, capture in ipairs(query.captures) do
local is_valid = (
- vim.startswith(capture, "_") -- Helpers.
- or vim.tbl_contains(captures[query_type], capture)
+ vim.startswith(capture, '_') -- Helpers.
+ or vim.list_contains(captures[query_type], capture)
)
if not is_valid then
- local error = string.format("(x) Invalid capture @%s in %s for %s.", capture, query_type, lang)
+ local error =
+ string.format('(x) Invalid capture @%s in %s for %s.', capture, query_type, lang)
errors[#errors + 1] = error
end
end
@@ -76,10 +77,10 @@ local function do_check()
end
end
- io_print "::endgroup::"
+ io_print('::endgroup::')
if #errors > 0 then
- io_print "\nCheck failed!\nErrors:"
+ io_print('\nCheck failed!\nErrors:')
for _, err in ipairs(errors) do
print(err)
end
@@ -89,35 +90,42 @@ local function do_check()
end
local ok, result = pcall(do_check)
-local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or "", ",", true)
+local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or '', ',', true)
-for k, v in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
- if not require("nvim-treesitter.parsers").has_parser(k) then
+for k, v in pairs(require('nvim-treesitter.parsers').configs) do
+ if #vim.api.nvim_get_runtime_file('parser/' .. k .. '.*', false) == 0 then
-- On CI all parsers that can be installed from C files should be installed
if
vim.env.CI
and not v.install_info.requires_generate_from_grammar
- and not vim.tbl_contains(allowed_to_fail, k)
+ and not vim.list_contains(allowed_to_fail, k)
then
- io_print("Error: parser for " .. k .. " is not installed")
- vim.cmd "cq"
+ io_print('Error: parser for ' .. k .. ' is not installed')
+ vim.cmd('cq')
else
- io_print("Warning: parser for " .. k .. " is not installed")
+ io_print('Warning: parser for ' .. k .. ' is not installed')
end
end
end
if ok then
- io_print "::group::Timings"
+ io_print('::group::Timings')
table.sort(result, function(a, b)
return a.duration < b.duration
end)
for i, val in ipairs(result) do
- io_print(string.format("%i. %.02fms %s %s", #result - i + 1, val.duration * 1e-6, val.lang, val.query_type))
+ io_print(
+ string.format(
+ '%i. %.02fms %s %s',
+ #result - i + 1,
+ val.duration * 1e-6,
+ val.lang,
+ val.query_type
+ )
+ )
end
- io_print "::endgroup::"
- io_print "Check successful!"
- vim.cmd "q"
+ io_print('::endgroup::')
+ io_print('Check successful!')
else
- vim.cmd "cq"
+ vim.cmd('cq')
end