Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query only matches first node at field #2984

Open
pokey opened this issue Feb 9, 2024 · 2 comments
Open

Query only matches first node at field #2984

pokey opened this issue Feb 9, 2024 · 2 comments
Labels
bug query Related to tree-sitter queries executor

Comments

@pokey
Copy link

pokey commented Feb 9, 2024

Problem

If the same field is used for multiple child nodes, a query will only match the first node

Steps to reproduce

Inputs

test.elm
f x y = x

Its parse tree is as follows:

(file [0, 0] - [0, 9]
  (value_declaration [0, 0] - [0, 9]
    functionDeclarationLeft: (function_declaration_left [0, 0] - [0, 5]
      (lower_case_identifier [0, 0] - [0, 1])
      pattern: (lower_pattern [0, 2] - [0, 3]
        (lower_case_identifier [0, 2] - [0, 3]))
      pattern: (lower_pattern [0, 4] - [0, 5]
        (lower_case_identifier [0, 4] - [0, 5])))
    (eq [0, 6] - [0, 7])
    body: (value_expr [0, 8] - [0, 9]
      name: (value_qid [0, 8] - [0, 9]
        (lower_case_identifier [0, 8] - [0, 9])))))

Note how there are two nodes with field pattern

test.scm
(function_declaration_left pattern: (_) @argumentOrParameter)

Actual output

➜ npx tree-sitter query test.scm test.elm 
../../../test.elm
  pattern: 0
    capture: 0 - argumentOrParameter, start: (0, 2), end: (0, 3), text: `x`

Expected behavior

I'd expect matches for both x and y:

➜ npx tree-sitter query test.scm test.elm 
../../../test.elm
  pattern: 0
    capture: 0 - argumentOrParameter, start: (0, 2), end: (0, 3), text: `x`
  pattern: 0
    capture: 0 - argumentOrParameter, start: (0, 4), end: (0, 5), text: `y`

Tree-sitter version (tree-sitter --version)

tree-sitter 0.20.6 (ccd6bf5)

Operating system/version

macOS 14.3 (23D56)

@clason
Copy link
Contributor

clason commented Feb 9, 2024

Please try the latest version (0.20.9).

@amaanq
Copy link
Member

amaanq commented Feb 11, 2024

can reproduce on 0.20.9 & master

@ObserverOfTime ObserverOfTime added the query Related to tree-sitter queries executor label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug query Related to tree-sitter queries executor
Projects
None yet
Development

No branches or pull requests

5 participants