mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-21 21:00:08 -04:00
feat(highlights): add is predicate
This commit is contained in:
parent
994baf4539
commit
ae2b88e45f
4 changed files with 43 additions and 18 deletions
|
|
@ -5,6 +5,9 @@ local info = require'nvim-treesitter.info'
|
|||
local configs = require'nvim-treesitter.configs'
|
||||
local parsers = require'nvim-treesitter.parsers'
|
||||
|
||||
-- Registers all query predicates
|
||||
require"nvim-treesitter.query_predicates"
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
|
|
|
|||
|
|
@ -35,3 +35,18 @@ query.add_predicate('has-ancestor?', function(match, pattern, bufnr, pred)
|
|||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
query.add_predicate('is?', function(match, pattern, bufnr, pred)
|
||||
if #pred < 3 then error("is? must have at least two arguments!") return end
|
||||
|
||||
-- Avoid circular dependencies
|
||||
local locals = require"nvim-treesitter.locals"
|
||||
local node = match[pred[2]]
|
||||
local types = {unpack(pred, 3)}
|
||||
|
||||
if not node then return true end
|
||||
|
||||
local _, _, kind = locals.find_definition(node, bufnr)
|
||||
|
||||
return vim.tbl_contains(types, kind)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue