From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_Paulo_Labegalini_de_Carvalho?= Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter modes and nested functions Date: Sat, 3 Dec 2022 13:00:17 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f8b33f05eef1e780" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35856"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 03 21:01:15 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p1YhG-00098s-OZ for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Dec 2022 21:01:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1Ygl-0002Nq-7h; Sat, 03 Dec 2022 15:00:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p1Ygc-0002MH-RR for emacs-devel@gnu.org; Sat, 03 Dec 2022 15:00:34 -0500 Original-Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p1Yga-0004mF-0T for emacs-devel@gnu.org; Sat, 03 Dec 2022 15:00:33 -0500 Original-Received: by mail-ej1-x629.google.com with SMTP id n20so18976636ejh.0 for ; Sat, 03 Dec 2022 12:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FxkMhXP2uUFAr90d/MLSbqn+d1L/gdF6WiiseEeAs2A=; b=SyjaRG7oAzES+x4GBLtoi6f6c4XjMD8pUGJjjllB0Yfw2//635mXPLNczkTleGvztc M/zGgrsjXg8juJZZs9VP3zTSp9H9vF/uaFnA95+PLOWNgZ4sEWNUb5a2caHN5asPzyPj WGTl1qyj89tEdOngWPU8o2+Q8aGRmpkGUOCmeM4ooqEfutxmPQ8vPFwUORHFXjCIb00U pfEikWei6gHIHzU2ypWUk1d4CueJvkFWWHc5cmK8rDzqlwK2C4kOcmiiMRNb8L6VhMzt U213ilA3/QtwGV6nQZr0chDIFJVfjH7eviL6NhQxrq1UflcMngs8vI5nikgGfbKNzq4+ stZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FxkMhXP2uUFAr90d/MLSbqn+d1L/gdF6WiiseEeAs2A=; b=A122h8JXQA+wULsbIFCyvLsbAbbOd57/Ulu1Z9z5vwc2j18RVXkpYxn1Qj7Cmt9EVN 6ZObg0DJ9Sd/vE/bZEvYtP7SOwFJvDh1tUbhuqS2sNrOVbbuCAIiU510QGUUx74UzRxr jp/pgdpYu9/ivu+0pjpjbt4Nh50dGQtKC+as6cureTeJ9n8er3sFGUalPXVh8BvWFNk9 tU5wGxideBujBadNnK+eoo3fJP9U6h/m1SpfEnGb400C38ERtXwHTqtU6k/rAvdpND9z kzXl68nC7H0yLlZQYzHuCMU+qIORABTTJ8DIx39bNlvk8IQf/Hgikz5MXqMEIveZYQzN 2MjA== X-Gm-Message-State: ANoB5pmYpN3M9A4vhk2iE6hQH257X+tI1lHhhaLaCAm4BKrWbb8TwqKQ S6VQg6x1A8Ls7QQYfJsHJabdna6rEXMykxBSQvf8DaUY X-Google-Smtp-Source: AA0mqf7koNm9RDVWh2R/SrIIwzByaTUi9jGNIAn4d88vvzES5eGv+Lgu87Yvux0Z830u83Jkcl28L6P76mdx7tvVk/8= X-Received: by 2002:a17:906:c449:b0:7ae:cbae:af1 with SMTP id ck9-20020a170906c44900b007aecbae0af1mr64303292ejb.31.1670097629916; Sat, 03 Dec 2022 12:00:29 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=jaopaulolc@gmail.com; helo=mail-ej1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300876 Archived-At: --000000000000f8b33f05eef1e780 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 wrote: > > > > On Dec 1, 2022, at 1:55 PM, Jo=C3=A3o 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 --=20 Jo=C3=A3o Paulo L. de Carvalho Ph.D Computer Science | IC-UNICAMP | Campinas , SP - Brazil Postdoctoral Research Fellow | University of Alberta | Edmonton, AB - Canad= a joao.carvalho@ic.unicamp.br joao.carvalho@ualberta.ca --000000000000f8b33f05eef1e780 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Yuan.

The word forward made me confused but = the behavior is described=C2=A0in the docstring.



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


> On Dec 1, 2022, at 1:55 PM, Jo=C3=A3o 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
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 <---- Point position 1
> def foo():
>=C2=A0 =C2=A0 =C2=A0def bar():=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= <---- Point destination 1
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 21
>=C2=A0 =C2=A0 =C2=A0return 2 * bar()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 <---- Point position 2
> def fuz():
>=C2=A0 =C2=A0 =C2=A0def bur():
>=C2=A0 =C2=A0 =C2=A0 =C2=A0def buz():=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= <---- Point destination 2
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 21
>=C2=A0 =C2=A0 =C2=A0 =C2=A0return buz() + buz()
>=C2=A0 =C2=A0 =C2=A0return 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 sugge= st taking a look at treesit-defun-type-regexp and treesit-defun-prefer-top-= level.

Yuan


--
Jo=C3=A3o Paulo L. de Carvalho
Ph.D Computer Science | =C2=A0IC-UNICAM= P | Campinas , SP - Brazil
Postdoctoral Research Fellow | University of = Alberta | Edmonton, AB - Canada
--000000000000f8b33f05eef1e780--