From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Update on tree-sitter structure navigation Date: Wed, 06 Sep 2023 11:57:26 +0000 Message-ID: <87msxzsee1.fsf@localhost> References: <5E7F2A94-4377-45C0-8541-7F59F3B54BA1@gmail.com> <87h6odhxs6.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18734"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Danny Freeman , Theodor Thornhill , Jostein =?utf-8?Q?Kj=C3=B8nigsen?= , Randy Taylor , Wilhelm Kirschbaum , Perry Smith , Dmitry Gutov To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 06 13:57:35 2023 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 1qdrA5-0004fi-QX for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Sep 2023 13:57:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdr9G-0007kR-Nc; Wed, 06 Sep 2023 07:56:42 -0400 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 1qdr9G-0007kE-0r for emacs-devel@gnu.org; Wed, 06 Sep 2023 07:56:42 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdr9C-0004w8-Nz for emacs-devel@gnu.org; Wed, 06 Sep 2023 07:56:41 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id BD725240104 for ; Wed, 6 Sep 2023 13:56:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1694001396; bh=M+gTePV6OXeJDd1gC51R45w1wx9NC4ccC6uhyYroARg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=jzsv+sJmeEZIFWR95rgDcTNeoHooSvevKpIzdOXDbhYTVNe2fM1sZmXwNX25fQ5a9 VcJS28Icr1QlVLCOaub87adfmXOHLAQ8E9jVUr68/+x1+E8SuySmyGemyv0vgrkyxk ijrLVCky9yVZDCzvfHBDYWtEEhDsC63HE67gR2wTewX7S6U70388KbPlmt3yv7wXHi i/Kl6w1XM1GbFX8N2zJ6uXX/eQVQsdpb+56DTYR2AsvchyN11onin/qLlRIoCTH/pW 48u3UqhCaQ0UIil5XtaU/YtA6Laaf3BgP8cDB+vds1RefInrqBi2PYZ9qXj6lBQU/J BV4fNmLZiqbwQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Rggnv28q2z9rxF; Wed, 6 Sep 2023 13:56:35 +0200 (CEST) In-Reply-To: Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:310186 Archived-At: Yuan Fu writes: > I think that both NODE types and attributes can be standardized. > > If we come up with a thing-at-point interface that provides more informat= ion than the current (BEG . END), tree-sitter surely can support it as a ba= ckend. Just need SomeOne to come up with it :-) But I don=E2=80=99t see how= this interface can support semantic information like arglist of a defun, o= r type of a declaration=E2=80=94these things are not universal to all =E2= =80=9Cnodes=E2=80=9D. For example, consider something like (thing-slot 'arglist (thing-at-point 'defun)) ; =3D> (ARGLIST_BEG . ARGLIST= _END) (thing-slot 'arglist (thing-at-point 'variable)) ; =3D> nil >>> - I can=E2=80=99t think of a good way to integrate tree-sitter queries = with >>> the navigation functions we have right now. Most importantly, >>> tree-sitter query always search top-down, and you can=E2=80=99t limit t= he >>> depth it searches. OTOH, our navigation functions work by traversing >>> the tree node-to-node. >>=20 >> May you elaborate about the difficulties you encountered? > > Ideally I=E2=80=99d like to pass a query and a node to treesit-node-match= -p, which returns t if the query matches the node. But queries don=E2=80=99= t work like that. They search the node and returns all the matches within t= hat node, which could be potentially wasteful. Isn't ts_query_cursor_next_match only searching a single match? >>> - Major mode fallback/inheritance, this has been discussed many times, = no good solution emerged. >>=20 >> I think that integration of tree-sitter with navigation functions might >> be a step towards solving this problem. If common Emacs commands can >> automatically choose between tree-sitter and classic implementations, it >> might become easier to unify foo-ts-mode with foo-mode. > > Unifying tree-sitter and non-tree-sitter modes creates many problems. I= =E2=80=99m rather thinking about some way to share some configuration betwe= en two modes. We=E2=80=99ve had many discussions before with no fruitful co= nclusion. Any chance you have links to these discussions? >>> - Isolated ranges. For many embedded languages, each blocks should be i= ndependent from another, but currently all the embedded blocks are connecte= d together and parsed by a single parser. We probably need to spawn a parse= r for each block. I=E2=80=99ll probably work on this one next. >>=20 >> Do you mean that a single parser sees subsequent block as a continuation >> of the previous? > > Exactly. Then, I can see cases when we do and also when we do _not_ want separate parsers for different blocks. For example, literate programming often uses other language blocks that are intended to be continuous. --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at