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: Tree-sitter modes and nested functions Date: Thu, 1 Dec 2022 14:55:28 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000024a9a805eecb489f" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39830"; mail-complaints-to="usenet@ciao.gmane.io" To: Yuan Fu , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 01 22:56:29 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 1p0rXg-000A7O-Gh for ged-emacs-devel@m.gmane-mx.org; Thu, 01 Dec 2022 22:56:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0rX1-0002Tp-Qc; Thu, 01 Dec 2022 16:55:47 -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 1p0rX0-0002TS-Mj for emacs-devel@gnu.org; Thu, 01 Dec 2022 16:55:46 -0500 Original-Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0rWv-0007UL-QB for emacs-devel@gnu.org; Thu, 01 Dec 2022 16:55:43 -0500 Original-Received: by mail-ed1-x52a.google.com with SMTP id l11so4175598edb.4 for ; Thu, 01 Dec 2022 13:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=wjAzVvApPAIzV/0XFs5VbbccAkpz0SzR4sNORLSRHPI=; b=pKmSFLAEDTA6GOAXa1NgbLlpxmKB3Wc1KkYYJuhsnM5WXyxEjcvmS3K3NkNglacH0n TS3sXr1ImmoR/73rXx6YvyuFzNaUN7ldm+tRO5TMKt2ZrF0opRs6/Rjl0mbhBnqNYVV3 8cJJqatCwXDl3eS+MRUX97n+PPjSqvJtnn37eCnRrWdUTeUZSbB0/40aUSUBSf8yFeNI NRhoz/5byszjz04dfIrzQNMZ6b6StkQBUr5DUF8hGWNEeXu9027nZxYBFLYyWFU6oJs4 q0HqFP4iPAa71K4R2K6yovDsChxH8PGX3HAMJmzTYE29L47iQHuON49m+dRFrK5dKyDj yuWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wjAzVvApPAIzV/0XFs5VbbccAkpz0SzR4sNORLSRHPI=; b=eAbqMPR4riMH5TbX8Gu3RwsGNXD678Vvid6BIhFJDbWUjqftaNxTG6S9JD2KQNrBQo zJwsTv1hOXnCBP9AjvPj/4V6n0Ho1/KS70BKyxoVu18ZanuHS3iQUOC1ZOE8uARzbeCk LwtJIBP9wscTgzmSJlo6V+ya+w1pxQ2e16G2Ewie4TFDc0bYLmnqH7l7UQLx3aro3za7 TQIiOodWvgSPUFI6myZET6HebHMwST7/a27UJ9tSQ5XivKBAgiNXxlglyG/kYMBMJoKK Fq6zJ8govvwqZVZT7i5ltaG5EqstkAIIQ0tE/tWqwj3vpQjnakWBq2b+AIBqPLa7+dfn FNuw== X-Gm-Message-State: ANoB5pl8KSFBZ+5SxQ231bVloi9GUDa6yBycIK8LvkwLUySg/dra8Ajc 9lAw/pudqN5aZjFVE7edG/w9J3PvwxeRVJJlU1Q= X-Google-Smtp-Source: AA0mqf6kOEPKfSTOG2Xwr76C10AdVaEx+f2qajm+6p/WZXRQW/lWZj44BBUMzPAqnP0GnrwJAO2+Ca+SXHXrcCpSxH0= X-Received: by 2002:a50:fe8d:0:b0:461:9183:834b with SMTP id d13-20020a50fe8d000000b004619183834bmr46589570edt.196.1669931739685; Thu, 01 Dec 2022 13:55:39 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=jaopaulolc@gmail.com; helo=mail-ed1-x52a.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:300825 Archived-At: --00000000000024a9a805eecb489f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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? --=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 --00000000000024a9a805eecb489f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

W= hile working on code navigation for sh-mode with tree-sitter I think I foun= d a bug.

When invoking `treesit-search-forward' the deepest nest= ed 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 def b= ar():=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<---- Point destination 1<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 21
=C2=A0 =C2=A0 return 2 * bar()<= br>=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 def bur():
=C2=A0 =C2=A0 =C2= =A0 def buz():=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<---- Point destination = 2
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 21
=C2=A0 =C2=A0 =C2=A0 return b= uz() + buz()
=C2=A0 =C2=A0 return 1 * bur()

Step to reprod= uce:
emacs -nw -Q=C2=A0 ;; built from master
M-: (require '= ;treesit)
C-x C-f test.py
M-x python-ts-mode
;; move point = to=C2=A0position=C2=A01
M-:=C2=A0=C2=A0(goto-char (treesit-node-start (t= reesit-search-forward (treesit-node-at (point)) "function_definition&q= uot;)))
;; point is now at destination 1
;; move point to posi= tion 2
M-:=C2=A0=C2=A0(goto-char (treesit-node-start (treesi= t-search-forward (treesit-node-at (point)) "function_definition")= ))
;; point is now at destination 2

Is this the= intended behaviour?

--
Jo=C3=A3o Paulo L. d= e Carvalho
Ph.D Computer Science | =C2=A0IC-UNICAMP | Campinas , SP - Br= azil
Postdoctoral Research Fellow | University of Alberta | Edmonton, AB= - Canada
--00000000000024a9a805eecb489f--