aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-05-15 19:46:47 +0200
committerGitHub <noreply@github.com>2023-05-15 19:46:47 +0200
commit8e3124493ce176843b9a66773d76a4422647dea9 (patch)
tree8d69ea596c19353f6584f9362b495ba5b79cee48 /runtime/lua/vim
parent88a202a01097de029beb01f60ad98aa0b5b44b50 (diff)
parent9ff59517cbf309d31f979a49b7dc82b237ecfcc4 (diff)
downloadrneovim-8e3124493ce176843b9a66773d76a4422647dea9.tar.gz
rneovim-8e3124493ce176843b9a66773d76a4422647dea9.tar.bz2
rneovim-8e3124493ce176843b9a66773d76a4422647dea9.zip
Merge pull request #23606 from clason/bump-tree-sitter-lua
fix(treesitter): update parser and queries
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/treesitter/query.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 75e5bf8870..73b561c777 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -382,6 +382,39 @@ local predicate_handlers = {
return string_set[node_text]
end,
+
+ ['has-ancestor?'] = function(match, _, _, predicate)
+ local node = match[predicate[2]]
+ if not node then
+ return true
+ end
+
+ local ancestor_types = {}
+ for _, type in ipairs({ unpack(predicate, 3) }) do
+ ancestor_types[type] = true
+ end
+
+ node = node:parent()
+ while node do
+ if ancestor_types[node:type()] then
+ return true
+ end
+ node = node:parent()
+ end
+ return false
+ end,
+
+ ['has-parent?'] = function(match, _, _, predicate)
+ local node = match[predicate[2]]
+ if not node then
+ return true
+ end
+
+ if vim.list_contains({ unpack(predicate, 3) }, node:parent():type()) then
+ return true
+ end
+ return false
+ end,
}
-- As we provide lua-match? also expose vim-match?