diff options
Diffstat (limited to 'lua/nvim-treesitter/query.lua')
| -rw-r--r-- | lua/nvim-treesitter/query.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index 896b11da..678c7b68 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -2,6 +2,7 @@ local api = vim.api local ts = vim.treesitter local utils = require'nvim-treesitter.utils' local parsers = require'nvim-treesitter.parsers' +local predicates = require'nvim-treesitter.query_predicates' local M = {} @@ -129,7 +130,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 iterator() local pattern, match = matches() if pattern ~= nil then local prepared_match = {} @@ -147,15 +148,25 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row) local preds = query.info.patterns[pattern] if preds then for _, pred in pairs(preds) do + -- functions if pred[1] == "set!" and type(pred[2]) == "string" then insert_to_path(prepared_match, split(pred[2]), pred[3]) end + + -- predicates + if type(pred[1]) == 'string' then + if not predicates.check_predicate(query, prepared_match, pred) or + not predicates.check_negated_predicate(query, prepared_match, pred) then + return iterator() + end + end end end return prepared_match end end + return iterator end --- Return all nodes corresponding to a specific capture path (like @definition.var, @reference.type) |
