From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Update on tree-sitter structure navigation Date: Fri, 8 Sep 2023 09:46:32 -0700 Message-ID: References: <5E7F2A94-4377-45C0-8541-7F59F3B54BA1@gmail.com> <87h6odhxs6.fsf@localhost> <87msxzsee1.fsf@localhost> <8A2B8A2E-FC24-401B-ACF8-688F2B157FB6@gmail.com> <878r9h9gkx.fsf@localhost> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="17336"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Danny Freeman , Theodor Thornhill , =?utf-8?Q?Jostein_Kj=C3=B8nigsen?= , Randy Taylor , Wilhelm Kirschbaum , Perry Smith , Dmitry Gutov To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 08 18:47:15 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 1qeedX-0004J2-8a for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Sep 2023 18:47:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeedH-0006s2-CD; Fri, 08 Sep 2023 12:46:59 -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 1qeed6-0006rM-KT for emacs-devel@gnu.org; Fri, 08 Sep 2023 12:46:55 -0400 Original-Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeed4-0005Cd-3U for emacs-devel@gnu.org; Fri, 08 Sep 2023 12:46:48 -0400 Original-Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-273ca7ab3f5so1569140a91.2 for ; Fri, 08 Sep 2023 09:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694191604; x=1694796404; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AlGACoDVigsX9QLDv88Aye/6tQrkPRnRI9ImRG0IAKo=; b=WoQ6VBWTbCuMS5W9rOP4x18llC5LQ+gAQ2bU4nApwwrbvVKH0yMLC34SDnj/qrkmOC vqT3f7KMewaFrTya8Hk5CSyy7scSEMqx5CysspD6nAQEJi9p7sRPE1qg8jfTVDj747jr +iqSh/bwjY+L2/HlXHPyAcQK3YO1jlR3ZLMIl09p50OU0qIe9B9vctPnhOqRVeUajWAd tH1aQ6ToNg4SbfDOpu1+sUqm5we8FAXKwvZMCiShqd5u1Mv9zDa+YYTwU5hzMTJZxdZH e6Js6OAL8URz9xuRsB/n4bffqfFvoEyOB9+bruvDf1lmesXTp+VzulJDVYrOVRLPSgjk 43Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694191604; x=1694796404; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AlGACoDVigsX9QLDv88Aye/6tQrkPRnRI9ImRG0IAKo=; b=dmf84VUVuid9CB4Z37ReuqnQEf1wgv4hOa7qtIcvo2ID7Y7WMfACLadryoo6Bc2r+e Jidsn+fXBysYsqzdwXonlRaJtrCUpJQYCHp99qIKd2hiddWFaC6MXXCqAkKbnaeFbk6x B9tNnr/14puqwegWzWleAFzf0FjQFEMZRZhtHAEFnMp+HMoXpniY3puXeuAalXUUVyWC EEOuY2VIlCu3rWoUedZLipiOrj3IuKtYYvwYnjlOmSV9DYDCAugMa7sxsCPsqLufbVvi KVwADqqLjNTft+YHmF8VYclM1pgG8ofCWckM55qC4IhQWgsz4ety66/xTG1jwvqxaZ/d vm5A== X-Gm-Message-State: AOJu0Yw+cE+sG+SxemAAs6pf7wBG5/Z2p0QTltS3dAyD6uNtl3Mdxk3I aD6MlLgY2lmPNtE//m/PNiw= X-Google-Smtp-Source: AGHT+IF813714OcEInE9gOMJPC8A3wwKpCMukaSaiwLsujXani/rcTQzECrlDThTNp0uXMkWcZ6pGQ== X-Received: by 2002:a17:90b:28f:b0:26b:7d8e:edf9 with SMTP id az15-20020a17090b028f00b0026b7d8eedf9mr2579698pjb.49.1694191604519; Fri, 08 Sep 2023 09:46:44 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id p26-20020a63741a000000b005742092c211sm703889pgc.64.2023.09.08.09.46.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2023 09:46:44 -0700 (PDT) In-Reply-To: <878r9h9gkx.fsf@localhost> X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=casouri@gmail.com; helo=mail-pj1-x102c.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, 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:310343 Archived-At: > On Sep 8, 2023, at 2:09 AM, Ihor Radchenko = wrote: >=20 > Yuan Fu writes: >=20 >>>> 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=99t work like that. They search the node and returns = all the matches within that node, which could be potentially wasteful. >>>=20 >>> Isn't ts_query_cursor_next_match only searching a single match? >>=20 >> Seems so, that=E2=80=99s good. But there=E2=80=99s no guarantee that = the first match with be the top node, even thought implementation-wise, = I think that=E2=80=99s probably the case. Maybe we can ask tree-sitter = developer to add such a promise. >=20 > I have found several potentially useful things in the ABI > = https://github.com/tree-sitter/tree-sitter/blob/524bf7e2c664d4a5dbd0c20d4d= 10f1e58f99e8ce/lib/include/tree_sitter/api.h >=20 > /** > * Set the maximum start depth for a query cursor. > * > * This prevents cursors from exploring children nodes at a certain = depth. > * Note if a pattern includes many children, then they will still be = checked. > * > * The zero max start depth value can be used as a special behavior and > * it helps to destructure a subtree by staying on a node and using = captures > * for interested parts. Note that the zero max start depth only limit = a search > * depth for a pattern's root node but other nodes that are parts of = the pattern > * may be searched at any depth what defined by the pattern structure. > * > * Set to `UINT32_MAX` to remove the maximum start depth. > */ > void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t = max_start_depth); >=20 > /** > * Set the range of bytes or (row, column) positions in which the query > * will be executed. > */ > void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t = start_byte, uint32_t end_byte); > void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint = start_point, TSPoint end_point); That=E2=80=99s great. Seems like a new addition to the API. That solves = every problem I had! Yuan=