diff options
| author | Santos Gallegos <stsewd@protonmail.com> | 2021-05-31 12:03:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-31 17:03:27 +0000 |
| commit | c1f61d4ca1319747c27ec97b5f050b3d936e0a55 (patch) | |
| tree | 9f1f65777ec4a7882e34ea1ff5517d910b08cc5e /scripts/check-queries.lua | |
| parent | Update lockfile.json (diff) | |
| download | nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.tar nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.tar.gz nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.tar.bz2 nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.tar.lz nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.tar.xz nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.tar.zst nvim-treesitter-c1f61d4ca1319747c27ec97b5f050b3d936e0a55.zip | |
Improve check-queries (#1253)
- Add checks for injections.
- Allow queries that start with [A-Z] for highlights only.
- Don't stop on the first error, finish checking all queries.
Diffstat (limited to 'scripts/check-queries.lua')
| -rwxr-xr-x | scripts/check-queries.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/scripts/check-queries.lua b/scripts/check-queries.lua index 623ad6bfd..1429c5546 100755 --- a/scripts/check-queries.lua +++ b/scripts/check-queries.lua @@ -17,6 +17,12 @@ local function extract_captures() end end + -- Complete captures for injections. + local parsers = require 'nvim-treesitter.info'.installed_parsers() + for _, lang in pairs(parsers) do + table.insert(captures['injections'], lang) + end + return captures end @@ -31,18 +37,21 @@ local function do_check() for _, lang in pairs(parsers) do for _, query_type in pairs(query_types) do print('Checking '..lang..' '..query_type) - local ok, query = pcall(queries.get_query,lang, query_type) + local ok, query = pcall(queries.get_query, lang, query_type) if not ok then vim.api.nvim_err_writeln(query) last_error = query else if query then for _, capture in ipairs(query.captures) do - if not vim.startswith(capture, "_") -- We ignore things like _helper - and captures[query_type] - and not capture:find("^[A-Z]") -- Highlight groups - and not vim.tbl_contains(captures[query_type], capture) then - error(string.format("Invalid capture @%s in %s for %s.", capture, query_type, lang)) + local is_valid = ( + vim.startswith(capture, "_") -- Helpers. + or vim.tbl_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) + print(error) + last_error = error end end end |
