mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
fix(treesitter): don't error when node argument of predicate is nil (#19355)
When the node mentioned in a predicate is not required for the query then predicates putting restrictions on that node shouldn't run. Fixes https://github.com/nvim-treesitter/nvim-treesitter/issues/2600
This commit is contained in:
@@ -221,6 +221,9 @@ end
|
|||||||
local predicate_handlers = {
|
local predicate_handlers = {
|
||||||
['eq?'] = function(match, _, source, predicate)
|
['eq?'] = function(match, _, source, predicate)
|
||||||
local node = match[predicate[2]]
|
local node = match[predicate[2]]
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
local node_text = M.get_node_text(node, source)
|
local node_text = M.get_node_text(node, source)
|
||||||
|
|
||||||
local str
|
local str
|
||||||
@@ -241,6 +244,9 @@ local predicate_handlers = {
|
|||||||
|
|
||||||
['lua-match?'] = function(match, _, source, predicate)
|
['lua-match?'] = function(match, _, source, predicate)
|
||||||
local node = match[predicate[2]]
|
local node = match[predicate[2]]
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
local regex = predicate[3]
|
local regex = predicate[3]
|
||||||
return string.find(M.get_node_text(node, source), regex)
|
return string.find(M.get_node_text(node, source), regex)
|
||||||
end,
|
end,
|
||||||
@@ -265,6 +271,9 @@ local predicate_handlers = {
|
|||||||
|
|
||||||
return function(match, _, source, pred)
|
return function(match, _, source, pred)
|
||||||
local node = match[pred[2]]
|
local node = match[pred[2]]
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
local regex = compiled_vim_regexes[pred[3]]
|
local regex = compiled_vim_regexes[pred[3]]
|
||||||
return regex:match_str(M.get_node_text(node, source))
|
return regex:match_str(M.get_node_text(node, source))
|
||||||
end
|
end
|
||||||
@@ -272,6 +281,9 @@ local predicate_handlers = {
|
|||||||
|
|
||||||
['contains?'] = function(match, _, source, predicate)
|
['contains?'] = function(match, _, source, predicate)
|
||||||
local node = match[predicate[2]]
|
local node = match[predicate[2]]
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
local node_text = M.get_node_text(node, source)
|
local node_text = M.get_node_text(node, source)
|
||||||
|
|
||||||
for i = 3, #predicate do
|
for i = 3, #predicate do
|
||||||
@@ -285,6 +297,9 @@ local predicate_handlers = {
|
|||||||
|
|
||||||
['any-of?'] = function(match, _, source, predicate)
|
['any-of?'] = function(match, _, source, predicate)
|
||||||
local node = match[predicate[2]]
|
local node = match[predicate[2]]
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
local node_text = M.get_node_text(node, source)
|
local node_text = M.get_node_text(node, source)
|
||||||
|
|
||||||
-- Since 'predicate' will not be used by callers of this function, use it
|
-- Since 'predicate' will not be used by callers of this function, use it
|
||||||
|
Reference in New Issue
Block a user