diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/check-queries.lua | 8 | ||||
| -rwxr-xr-x | scripts/format-queries.lua | 26 | ||||
| -rwxr-xr-x | scripts/install-parsers.lua | 2 | ||||
| -rwxr-xr-x | scripts/update-parsers.lua | 5 | ||||
| -rwxr-xr-x | scripts/update-readme.lua | 5 |
5 files changed, 22 insertions, 24 deletions
diff --git a/scripts/check-queries.lua b/scripts/check-queries.lua index dddaf80d7..66b947914 100755 --- a/scripts/check-queries.lua +++ b/scripts/check-queries.lua @@ -7,13 +7,13 @@ local parsers = #_G.arg > 0 and { unpack(_G.arg) } or require('nvim-treesitter.config').installed_parsers() -- Extract captures from documentation for validation -local captures = {} +local captures = {} ---@type table[] do local current_query ---@type string for line in io.lines('CONTRIBUTING.md') do if vim.startswith(line, '### ') then - current_query = line:sub(5):lower() + current_query = line:sub(5):lower() ---@type string elseif vim.startswith(line, '@') and current_query then if not captures[current_query] then captures[current_query] = {} @@ -24,14 +24,14 @@ do end -- Complete captures for injections. - for _, lang in pairs(vim.tbl_keys(configs)) do + for lang, _ in pairs(configs) do table.insert(captures['injections'], lang) end end -- Check queries for each installed parser in parsers local errors = {} ---@type string[] -local timings = {} ---@type number[][] +local timings = {} ---@type { duration: number, lang: string, query_type: string }[] do print('::group::Check parsers') diff --git a/scripts/format-queries.lua b/scripts/format-queries.lua index c7362687e..bc2cf70ce 100755 --- a/scripts/format-queries.lua +++ b/scripts/format-queries.lua @@ -351,7 +351,7 @@ end ---@param bufnr integer ---@param node TSNode ---@param lines string[] ----@param q table<string, vim.treesitter.query.TSMetadata> +---@param q table<string, table[]> ---@param level integer local function iter(bufnr, node, lines, q, level) --- Sometimes 2 queries apply append twice. This is to prevent the case from happening @@ -430,19 +430,19 @@ end ---@param queries string local function format(bufnr, queries) local lines = { '' } - -- stylua: ignore + ---@type table<string,table<string,table>> local map = { - ['format.ignore'] = {}, -- Ignore the node and its children - ['format.indent.begin'] = {}, -- +1 shiftwidth for all nodes after this - ['format.indent.dedent'] = {}, -- -1 shiftwidth for this line only - ['format.prepend-space'] = {}, -- Prepend a space before inserting the node - ['format.prepend-newline'] = {}, -- Prepend a \n before inserting the node - ['format.append-space'] = {}, -- Append a space after inserting the node - ['format.append-newline'] = {}, -- Append a newline after inserting the node - ['format.cancel-append'] = {}, -- Cancel any `@format.append-*` applied to the node - ['format.cancel-prepend'] = {}, -- Cancel any `@format.prepend-*` applied to the node - ['format.replace'] = {}, -- Dedicated capture used to store results of `(#gsub!)` - ['format.remove'] = {}, -- Do not add the syntax node to the result, i.e. brackets [], parens () + ['format.ignore'] = {}, -- Ignore the node and its children + ['format.indent.begin'] = {}, -- +1 shiftwidth for all nodes after this + ['format.indent.dedent'] = {}, -- -1 shiftwidth for this line only + ['format.prepend-space'] = {}, -- Prepend a space before inserting the node + ['format.prepend-newline'] = {}, -- Prepend a \n before inserting the node + ['format.append-space'] = {}, -- Append a space after inserting the node + ['format.append-newline'] = {}, -- Append a newline after inserting the node + ['format.cancel-append'] = {}, -- Cancel any `@format.append-*` applied to the node + ['format.cancel-prepend'] = {}, -- Cancel any `@format.prepend-*` applied to the node + ['format.replace'] = {}, -- Dedicated capture used to store results of `(#gsub!)` + ['format.remove'] = {}, -- Do not add the syntax node to the result, i.e. brackets [], parens () } local root = ts.get_parser(bufnr, 'query'):parse(true)[1]:root() local query = ts.query.parse('query', queries) diff --git a/scripts/install-parsers.lua b/scripts/install-parsers.lua index cb7389e19..1d9448ca7 100755 --- a/scripts/install-parsers.lua +++ b/scripts/install-parsers.lua @@ -12,7 +12,7 @@ for i = 1, #_G.arg do elseif _G.arg[i]:find('^%-%-max%-jobs') then max_jobs = _G.arg[i]:match('=(%d+)') else - parsers[#parsers + 1] = _G.arg[i] + parsers[#parsers + 1] = _G.arg[i] ---@type string end end diff --git a/scripts/update-parsers.lua b/scripts/update-parsers.lua index 83f54e9da..70055c81d 100755 --- a/scripts/update-parsers.lua +++ b/scripts/update-parsers.lua @@ -55,8 +55,9 @@ if #updates > 0 then local update_list = table.concat(updates, ', ') print(string.format('\nUpdated parsers: %s', update_list)) -- pass list to workflow - if os.getenv('GITHUB_ENV') then - local env = io.open(os.getenv('GITHUB_ENV'), 'a') + local gh_env = os.getenv('GITHUB_ENV') + if gh_env then + local env = assert(io.open(gh_env, 'a')) env:write(string.format('UPDATED_PARSERS=%s\n', update_list)) env:close() end diff --git a/scripts/update-readme.lua b/scripts/update-readme.lua index 2505f845b..37eae6826 100755 --- a/scripts/update-readme.lua +++ b/scripts/update-readme.lua @@ -3,11 +3,8 @@ vim.opt.runtimepath:append('.') local util = require('nvim-treesitter.util') local parsers = require('nvim-treesitter.parsers') local tiers = require('nvim-treesitter.config').tiers ----@class Parser ----@field name string ----@field parser ParserInfo -local sorted_parsers = {} +local sorted_parsers = {} ---@type { name: string, parser: ParserInfo }[] for k, v in pairs(parsers) do table.insert(sorted_parsers, { name = k, parser = v }) end |
