nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

[Question] Why is Alternations not working in this case?

Open
#482 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

I'm trying to write an aQuery to select the inner range of either a list_lit or a vec_lit TSNode for Clojure

(+ 1 2 3)     ;; list_lit
[1 2 3]       ;; vec_lit

I've created individual queries for each type which work however, within an alternation it doesn't.

; -- Works: Get List start and end
(list_lit . value: (_) @_list_start value: (_) @_list_end .)

; -- Works: Get Vector start and end
(vec_lit . value: (_) @_vec_start value: (_) @_vec_end .)

; -- Alternations Fails: List or Vector inner start and end
([list_lit vec_lit] . value: (_) @_start value: (_) @_end .)

I don't know how to debug why it's not working. Could anyone help explain what's happening please?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the three Clojure query examples and compare the results for the individual patterns and the alternation. Consult the Tree-sitter query behavior relevant to alternations and document an explanation of why the combined query behaves differently, including a working form if the behavior is expected.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.