mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-21 12:50:09 -04:00
fix: appease lua_ls locals.lua warnings
This commit is contained in:
parent
2428b96081
commit
ac1828d2ee
1 changed files with 14 additions and 17 deletions
|
|
@ -18,15 +18,7 @@ end
|
|||
---@param node TSNode
|
||||
---@return TSNode result
|
||||
local function get_root_for_node(node)
|
||||
local parent = node ---@type TSNode?
|
||||
local result = node
|
||||
|
||||
while parent ~= nil do
|
||||
result = parent
|
||||
parent = result:parent()
|
||||
end
|
||||
|
||||
return result
|
||||
return node:tree():root()
|
||||
end
|
||||
|
||||
-- Creates unique id for a node based on text and range
|
||||
|
|
@ -103,7 +95,9 @@ function M.recurse_local_nodes(local_def, accumulator, full_match, last_match)
|
|||
if local_def.node then
|
||||
accumulator(local_def, local_def.node, full_match, last_match)
|
||||
else
|
||||
for match_key, def in pairs(local_def) do
|
||||
for match_key, def in
|
||||
pairs(local_def --[[@as {[string]: TSLocal}]])
|
||||
do
|
||||
M.recurse_local_nodes(
|
||||
def,
|
||||
accumulator,
|
||||
|
|
@ -120,16 +114,16 @@ end
|
|||
---@param hash_fn fun(...): any
|
||||
---@return F
|
||||
local function memoize(fn, hash_fn)
|
||||
local cache = setmetatable({}, { __mode = 'kv' }) ---@type table<any,any>
|
||||
local cache = setmetatable({}, { __mode = 'kv' }) ---@type table<any,any[]>
|
||||
|
||||
return function(...)
|
||||
local key = hash_fn(...)
|
||||
if cache[key] == nil then
|
||||
local v = { fn(...) } ---@type any
|
||||
local v = { fn(...) } ---@type any[]
|
||||
|
||||
for k, value in pairs(v) do
|
||||
if value == nil then
|
||||
value[k] = vim.NIL
|
||||
value[k] = vim.NIL ---@type table
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -138,9 +132,9 @@ local function memoize(fn, hash_fn)
|
|||
|
||||
local v = cache[key]
|
||||
|
||||
for k, value in pairs(v) do
|
||||
for k, value in ipairs(v) do
|
||||
if value == vim.NIL then
|
||||
value[k] = nil
|
||||
value[k] = nil ---@type table
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -200,7 +194,9 @@ M.get = memoize(function(bufnr)
|
|||
local kind = query.captures[id]
|
||||
|
||||
local scope = 'local' ---@type string
|
||||
for k, v in pairs(metadata) do
|
||||
for k, v in
|
||||
pairs(metadata --[[@as {[integer|string]: string}]])
|
||||
do
|
||||
if type(k) == 'string' and vim.endswith(k, 'local.scope') then
|
||||
scope = v
|
||||
end
|
||||
|
|
@ -379,7 +375,8 @@ function M.containing_scope(node, bufnr, allow_scope)
|
|||
local iter_node = node ---@type TSNode?
|
||||
|
||||
while iter_node ~= nil and not vim.tbl_contains(scopes, iter_node) do
|
||||
iter_node = iter_node:parent()
|
||||
local parent = iter_node:parent()
|
||||
iter_node = parent
|
||||
end
|
||||
|
||||
return iter_node or (allow_scope and node or nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue