feat(highlights): add is predicate

This commit is contained in:
Steven Sojka 2020-08-15 09:24:24 -05:00
parent 994baf4539
commit ae2b88e45f
4 changed files with 43 additions and 18 deletions

View file

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

View file

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