mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-03 20:10:10 -04:00
queries: add is? predicate
This commit is contained in:
parent
255d1756b0
commit
a2ba854001
2 changed files with 19 additions and 1 deletions
|
|
@ -89,4 +89,14 @@ function M.get_references(bufnr)
|
|||
return refs
|
||||
end
|
||||
|
||||
function M.is(node, deftype, bufnr)
|
||||
for def in M.get_definitions(bufnr) do
|
||||
if def[deftype] and def[deftype].node == node then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
local api = vim.api
|
||||
local ts = vim.treesitter
|
||||
-- local locals = require'nvim-treesitter.locals'
|
||||
|
||||
local M = {}
|
||||
|
||||
|
|
@ -99,7 +100,7 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
|
|||
|
||||
local matches = query:iter_matches(qnode, bufnr, start_row, end_row)
|
||||
|
||||
return function()
|
||||
local function iter()
|
||||
local pattern, match = matches()
|
||||
if pattern ~= nil then
|
||||
local prepared_match = {}
|
||||
|
|
@ -120,12 +121,19 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
|
|||
if pred[1] == "set!" and type(pred[2]) == "string" then
|
||||
insert_to_path(prepared_match, split(pred[2]), pred[3])
|
||||
end
|
||||
if pred[1] == "is?" and type(pred[3]) == "string" then
|
||||
if not locals.is(pred[2], pred[3], bufnr) then
|
||||
return iter() -- We should ignore this one, tail call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return prepared_match
|
||||
end
|
||||
end
|
||||
|
||||
return iter
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue