From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Tree sitter support for C-like languages Date: Tue, 15 Nov 2022 12:37:00 +0100 Message-ID: <87k03w5u03.fsf@thornhill.no> References: <87tu36em9t.fsf@thornhill.no> <834jv4nz2g.fsf@gnu.org> <871qq8hsj1.fsf@thornhill.no> <83iljklzmo.fsf@gnu.org> <87v8nkgcqj.fsf@thornhill.no> <87sfiogcbm.fsf@thornhill.no> <83pmdrkyj7.fsf@gnu.org> <87v8njw5th.fsf@thornhill.no> <83leofkwjm.fsf@gnu.org> <9E9244D3-2EFB-4621-91E0-FC8B8C1C2D52@gmail.com> <186915C1-1C47-43DC-A386-B447A2E7528D@gmail.com> <83h6z1k6z8.fsf@gnu.org> <52D18BA8-C9A8-4E9A-9DDA-76E48744DDC9@gmail.com> <837czxjrxu.fsf@gnu.org> <8BEF109A-A5B3-4CF4-AE07-AEB9388B0A07@gmail.com> <83zgcti9gh.fsf@gnu.org> <83y1scj3s8.fsf@gnu.org> <7082237A-2BD6-4A1C-8BEC-4D470B0D204F@gmail.com> 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="1464"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Yuan Fu , Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 15 12:38:21 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 1ouuGi-00005C-KX for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 12:38:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouuFn-0003Wd-CZ; Tue, 15 Nov 2022 06:37:23 -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 1ouuFb-0003Vm-Q2 for emacs-devel@gnu.org; Tue, 15 Nov 2022 06:37:17 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouuFV-0006qS-Dn; Tue, 15 Nov 2022 06:37:08 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1668512221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhzHyQ5fpXB7dLaPNuhZazXyR4TUBNHGZJAivKrzjgk=; b=Yuy16jRUSHLMmn+8P8hPpZ5l15A1XNaR/5TkTiPWHfsCRHBcu4jLQgkJeaP5pEZHPWsw2v 5fukfoB/yfGbBjvz1PGtIGvBDSNCNC557oLI0+9zIJXHErYQaRzTCdmeJg/DoWpD1Y4fbm lzjH2tyzZIU4VWXF+vkLSD4TbBDg+owI7yPlmeGmAnmkUEmpAQoiKaNVFWEfvOZTnL/sdq Az5oQXnxrBllZ8dmJXD8te9sbDquzViYmMxE/rq3A9OcdoVo8qzGvgOWxU7Arduxdu/m7N FD0RyYeeoFB7kRn3QPMYjuPyXE54clykAIC3AQa47H1Ji9Txm637fzUZHq5bmA== In-Reply-To: <7082237A-2BD6-4A1C-8BEC-4D470B0D204F@gmail.com> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=94.23.1.103; envelope-from=theo@thornhill.no; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_PASS=-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:299841 Archived-At: > > We can update the nodes. (With ts_node_edit, similar to ts_tree_edit.) > > But, I looked further, and the facility for updating a node is not > really what we need/want. I won=E2=80=99t go into details here, because= =E2=80=A6 there > is a feature perfect for our use case! Tree-sitter can tell you what > has changed when you re-parse a tree, that=E2=80=99s exactly what we need= and > very easy to use. It=E2=80=99s foolish for me to overlook this feature. > > Specifically, when we re-parse a buffer, we can compare the > before/after parse tree for differences. Tree-sitter can tell us the > ranges in which nodes have changed during that re-parse. The =E2=80=9Cint= =E2=80=9D in > the original example would be included in the ranges reported. > > I=E2=80=99ve pushed a change that utilizes this feature. If you pull the > latest commit and open c-ts-mode, error faces should appear and > disappear as you type. There is no documentation for now, but > basically we now allow users to register =E2=80=9Cafter-change-function= =E2=80=9Ds to > tree-sitter parsers. The parser will call these functions when with > the changed ranges when it re-parses. > > The new functions are treesit-parser-add-notifier, > treesit-parser-notifiers, treesit-parser-remove-notifier. I didn=E2=80=99= t use > treesit-parser-add-after-change-function because that is hideously > long. It works like a charm! Great job :-) --=20 Theo