euclidianAce / ltreesitter

Standalone tree sitter bindings for the Lua language
MIT License
85 stars 4 forks source link

segfault when using query with predicate #13

Closed TorchedSammy closed 1 year ago

TorchedSammy commented 1 year ago

hi, i'm working on evergreen for treesitter highlighting in lite xl and while trying to add support for zig i noticed that it would just cleanly exit with no error. after that, i removed predicates that i didnt have (since i was copying them from nvim-treesitter) and it still had a problem with predicates that were stated to be builtin (like eq?).

i did some minimal testing outside lite xl and noticed that if was any predicate at all in the query it would be an issue.

here's the code i used to check: https://safe.kashima.moe/y4wq3yrbdzxq.lua if you remove the last part that queries for function builtins it will run successfully.

euclidianAce commented 1 year ago

I was able to reproduce this by just giving a predicate a large number of arguments. The changes in #14 were able to fix it for me, let me know if the issue persists!

TorchedSammy commented 1 year ago

seems like it still happens with the code i posted

euclidianAce commented 1 year ago

Apparently I misinterpreted the tree sitter api when I first implemented predicates. #17 should fix that but comes with a small change that the arguments passed to query's predicates could be Nodes if they come from captures.

So your reproduction would want to change to something like:

for node, name in parser:query(queryString):with {
    ['any-of?'] = function(t, ...)
        local t_src = t:source()
        for _, match in ipairs {...} do
            if t_src == match then return true end
        end
        return false
    end,
}:capture(tree:root()) do
    print(node, name)
end
euclidianAce commented 1 year ago

17 should hopefully have fixed this!

TorchedSammy commented 1 year ago

yes it works now thanks