emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tree-sitter modes and nested functions


From: João Paulo Labegalini de Carvalho
Subject: Re: Tree-sitter modes and nested functions
Date: Sat, 3 Dec 2022 13:00:17 -0700

Thanks Yuan.

The word forward made me confused but the behavior is described in the docstring.



On Thu, Dec 1, 2022 at 7:51 PM Yuan Fu <casouri@gmail.com> wrote:


> On Dec 1, 2022, at 1:55 PM, João Paulo Labegalini de Carvalho <jaopaulolc@gmail.com> wrote:
>
> Hi,
>
> While working on code navigation for sh-mode with tree-sitter I think I found a bug.
>
> When invoking `treesit-search-forward' the deepest nested function is returned instead of the first found node.
>
> ;; Contests of test.py
> #!/usr/bin/env python
>                          <---- Point position 1
> def foo():
>     def bar():           <---- Point destination 1
>         return 21
>     return 2 * bar()
>                          <---- Point position 2
> def fuz():
>     def bur():
>       def buz():         <---- Point destination 2
>         return 21
>       return buz() + buz()
>     return 1 * bur()

Yeah this is expected, treesit-search-forward searches leaf nodes first and then parent nodes. If you want to implement beginning/end-of-defun I suggest taking a look at treesit-defun-type-regexp and treesit-defun-prefer-top-level.

Yuan


--
João Paulo L. de Carvalho
Ph.D Computer Science |  IC-UNICAMP | Campinas , SP - Brazil
Postdoctoral Research Fellow | University of Alberta | Edmonton, AB - Canada
joao.carvalho@ic.unicamp.br
joao.carvalho@ualberta.ca

reply via email to

[Prev in Thread] Current Thread [Next in Thread]