[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tree-sitter integration on feature/tree-sitter
From: |
Yoav Marco |
Subject: |
Re: Tree-sitter integration on feature/tree-sitter |
Date: |
Thu, 30 Jun 2022 14:21:54 +0300 |
User-agent: |
mu4e 1.6.3; emacs 29.0.50 |
Yoav Marco <yoavm448@gmail.com> writes:
> Okay, so the problem here is that neovim supports making up arbitrary
> captures as a range over other captures: (#make-range! "c" @a @b) means
> "make a new capture @c that spans from @a to @b". It helps when you e.g
> want to make a capture spanning only two children of a node and not the
> other children.
>
> The problem is, making up new captures in Lisp isn't trivial, it would
> need special support form the C side.
>
> Could we support this?
>
> 1. We could allow a special case where if Lisp predicate return a list
> (name beg end) that would have the same effect as "make new capture
> @c with range @a, @b".
>
> 2. But captures are returned from treesit-query-capture as pairs of
> (capture-name . node), and we can't just make up a node with
> arbitrary range.
>
> 3. We could report non-boolean capture results by just appending that
> result to the list of pairs, but that just adds complexity to users
> of treesit-query-capture. And it doesn't support the simpler use case
> of 1, where it's just reported as a normal capture.
I dug a little through the neovim code. #make-range! is implemented in
nvim-treesitter, not mainline neovim. And they don't create a new node
for the range, just compute the range itself.
I think the best course of action is to support elisp predicates in some
way, and let users post-process the output of treesit-query-capture if
they added queries that return non-boolean results.
> Abin Simon <abinsimon10@gmail.com> writes:
>
>> I ran into similar issues in the meain/evil-textobj-tree-sitter and had
>> to write scritps to convert them to something that works in emacs.
I see you wrote a go program to pre-process #make-range!. I also had to do
something similar in
https://github.com/emacs-tree-sitter/tree-sitter-langs/pull/99
due to predicate incompatibility, though I do it in Elisp right after
reading the query file. So I guess it's a valid solution too.
- Re: Tree-sitter integration on feature/tree-sitter, (continued)