mirror of
https://github.com/neovim/neovim.git
synced 2026-09-09 07:25:51 +00:00
fix(treesitter): #has-parent? errors on a node with no parent
Problem:
The #has-parent? predicate indexes the result of node:parent() without
checking it, so a capture that matches a tree's root node raises
query.lua:600: attempt to index a nil value
instead of simply not matching. In a highlights query that breaks
highlighting for the whole buffer. The sibling #has-ancestor? predicate
handles the same situation.
Solution:
Treat a missing parent as "does not match".
AI-assisted
This commit is contained in:
committed by
Christian Clason
parent
e8a0b400d8
commit
2f5df7add7
@@ -597,7 +597,8 @@ local predicate_handlers = {
|
||||
end
|
||||
|
||||
for _, node in ipairs(nodes) do
|
||||
if vim.list_contains({ unpack(predicate, 3) }, node:parent():type()) then
|
||||
local parent = node:parent()
|
||||
if parent and vim.list_contains({ unpack(predicate, 3) }, parent:type()) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user