[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tree-sitter modes and nested functions
From: |
Yuan Fu |
Subject: |
Re: Tree-sitter modes and nested functions |
Date: |
Thu, 1 Dec 2022 18:51:11 -0800 |
> 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