refactor(lua): fix some luals warnings

This commit is contained in:
Christian Clason 2025-04-27 16:08:59 +02:00
parent bdc2e01958
commit 53d7118483
12 changed files with 61 additions and 61 deletions

View file

@ -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')

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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