* Tree-sitter modes and nested functions
@ 2022-12-01 21:55 João Paulo Labegalini de Carvalho
2022-12-02 2:51 ` Yuan Fu
0 siblings, 1 reply; 4+ messages in thread
From: João Paulo Labegalini de Carvalho @ 2022-12-01 21:55 UTC (permalink / raw)
To: Yuan Fu, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]
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()
Step to reproduce:
emacs -nw -Q ;; built from master
M-: (require 'treesit)
C-x C-f test.py
M-x python-ts-mode
;; move point to position 1
M-: (goto-char (treesit-node-start (treesit-search-forward
(treesit-node-at (point)) "function_definition")))
;; point is now at destination 1
;; move point to position 2
M-: (goto-char (treesit-node-start (treesit-search-forward
(treesit-node-at (point)) "function_definition")))
;; point is now at destination 2
Is this the intended behaviour?
--
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
[-- Attachment #2: Type: text/html, Size: 2015 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tree-sitter modes and nested functions
2022-12-01 21:55 Tree-sitter modes and nested functions João Paulo Labegalini de Carvalho
@ 2022-12-02 2:51 ` Yuan Fu
2022-12-03 20:00 ` João Paulo Labegalini de Carvalho
0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2022-12-02 2:51 UTC (permalink / raw)
To: João Paulo Labegalini de Carvalho; +Cc: emacs-devel
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tree-sitter modes and nested functions
2022-12-02 2:51 ` Yuan Fu
@ 2022-12-03 20:00 ` João Paulo Labegalini de Carvalho
2022-12-05 20:56 ` Yuan Fu
0 siblings, 1 reply; 4+ messages in thread
From: João Paulo Labegalini de Carvalho @ 2022-12-03 20:00 UTC (permalink / raw)
To: Yuan Fu; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1473 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 2316 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tree-sitter modes and nested functions
2022-12-03 20:00 ` João Paulo Labegalini de Carvalho
@ 2022-12-05 20:56 ` Yuan Fu
0 siblings, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2022-12-05 20:56 UTC (permalink / raw)
To: João Paulo Labegalini de Carvalho; +Cc: emacs-devel
> On Dec 3, 2022, at 12:00 PM, João Paulo Labegalini de Carvalho <jaopaulolc@gmail.com> wrote:
>
> Thanks Yuan.
>
> The word forward made me confused but the behavior is described in the docstring.
>
Yeah, we have to choose one way to traverse the tree and that’s overall the best way for treesit-search-forward’s purpose, I think.
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-05 20:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 21:55 Tree-sitter modes and nested functions João Paulo Labegalini de Carvalho
2022-12-02 2:51 ` Yuan Fu
2022-12-03 20:00 ` João Paulo Labegalini de Carvalho
2022-12-05 20:56 ` Yuan Fu
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).