nvim-treesitter / playground

Treesitter playground integrated into Neovim
Apache License 2.0
898 stars 47 forks source link

Query doesn't respect #any-of? #95

Closed dlight closed 2 years ago

dlight commented 2 years ago

So I'm trying to debug queries for the Elixir language and in locals.scm there's a query with this fragment:

(identifier) @_identifier (#any-of? @_identifier "def" "defp" "defmacro" "defmacrop" "defguard" "defguardp" "defn" "defnp" "for")

And when matching with this code:

def foo2(a, b) do
  :ok
end

It matches def, foo2, a and b (all identifiers), but it should match only def!

Why is #any-of? ignored? I guess that predicates aren't handled by treesitter itself but I supposed that nvim-treesitter would filter out the results that don't match.

Here's it running:

image

And here's the result of :checkhealth nvim-treesitter:

nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
  - OK: `tree-sitter` found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v16.16.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (GCC) 12.2.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - vim            ✓ ✓ ✓ . ✓
  - elixir         ✓ ✓ ✓ ✓ ✓
  - erlang         ✓ . ✓ . .
  - javascript     ✓ ✓ ✓ ✓ ✓
  - lua            ✓ ✓ ✓ ✓ ✓
  - cpp            ✓ ✓ ✓ ✓ ✓
  - c              ✓ ✓ ✓ ✓ ✓
  - typescript     ✓ ✓ ✓ ✓ ✓
  - css            ✓ . ✓ ✓ ✓
  - query          ✓ ✓ ✓ ✓ ✓
  - html           ✓ ✓ ✓ ✓ ✓
  - python         ✓ ✓ ✓ ✓ ✓
  - bash           ✓ ✓ ✓ . ✓
  - json           ✓ ✓ ✓ ✓ .

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

And I'm running nvim-treesitter from git

dlight commented 2 years ago

Oh. I just need to wrap the query in (), like this

((identifier) @_identifier (#any-of? @_identifier "def" "defp" "defmacro" "defmacrop" "defguard" "defguardp" "defn" "defnp" "for"))

It's working now