elixir-lang / tree-sitter-elixir

Elixir grammar for tree-sitter
https://elixir-lang.org/tree-sitter-elixir
Apache License 2.0
245 stars 24 forks source link

Predicate syntax reference #39

Closed andrhua closed 2 years ago

andrhua commented 2 years ago

There's perhaps a small typo in injections queries, where #eq should've been #eq?, at least that's what Lua TS binding lib uses, as well as Rust and Webassembly. Here's an error from nvim:

Error detected while processing FileType Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:418: No handler for eq
stack traceback:
        [C]: in function 'error'
        /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:418: in function 'match_preds'
        /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:564: in function '(for generator)'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:314: in function '_get_injections'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:131: in function 'parse'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:68: in function '_create_parser'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:94: in function 'get_parser'

But I'm not sure since docs (Predicates section) state that predicates are handled by "higher level code", so perhaps the author of this query had used parser where question mark is omitted from predicate syntax. Anyway, adding ? fixed mentioned error for me.

Minimal reproducing code:

defmodule Foo do
  @foo ~w(bar) # error happens here
end
the-mikedavis commented 2 years ago

Good catch! That line should be #eq?. All tree-sitter consumers that I know of use #eq?, but you're right that they're implemented by higher level code. For example, neovim implements #any-of? while tree-sitter-cli does not.

I'll push a commit to fix this. Thanks for the report!

jonatanklosko commented 2 years ago

Good catch, currently I get this:

image

and it's the same when changing #eq to #whatever, so it seems like there's some error that is being silently ignored. With the change it works as expected

image