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: Tree sitter support for C-like languages Date: Tue, 15 Nov 2022 02:51:31 -0800 Message-ID: <7082237A-2BD6-4A1C-8BEC-4D470B0D204F@gmail.com> References: <87tu36em9t.fsf@thornhill.no> <45FD2F78-F15B-488B-9348-A8E298D8AD35@gmail.com> <87v8nmyqqp.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> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="27651"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, theo@thornhill.no, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 15 11:52: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 1outYL-0006zk-R2 for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 11:52:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1outXd-0006mG-Bf; Tue, 15 Nov 2022 05:51:45 -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 1outXW-0006hv-Qo for emacs-devel@gnu.org; Tue, 15 Nov 2022 05:51:40 -0500 Original-Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1outXV-0006Xs-3V; Tue, 15 Nov 2022 05:51:38 -0500 Original-Received: by mail-pg1-x52f.google.com with SMTP id 62so4582953pgb.13; Tue, 15 Nov 2022 02:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=xRC7OPqzi1jIqe+WTFW+tNKmDIFuA2HlGuIkmvZP7MM=; b=cJbk4j+wdOimhndccuCQlvK6wvQDkASvOGkH66j1TgapmgejDhMaWEhbrD74W8rV7M 97QwBa+Lu9aA4Ecu8Hvd9c5sI9Mf0v3MpVYtja5K177FTBkA5eYkyjO9j6ZLu7afRufz 4/UdYhKGItNHYNafTnH8+pgRWeOkEvVW9uIjM3GiXamG8i8cUmm1JxtD7x7c4Ng4S5Y8 iaKow4CP56rqM9NPzjlpjQjXEGpOy5rcLEi9bexoftMjkdX5VJKE5JqKtUTX8LP90Okw TCAkaL6GxoJHndEXUo7n6tFuD/UUzftLwHwCKBYcpY59FsOZxCDpvH+E0Xg2CcSbTaO3 8jqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=xRC7OPqzi1jIqe+WTFW+tNKmDIFuA2HlGuIkmvZP7MM=; b=VrcWX2bT/6hmkH4QT7PnWuKMHQxQbVRkmwGBI/iZAACLeCDpS+dimEsuvXPZd2BG2s 1Q8/r0uN23jQTURiUprMgCkdgOOWSAk3T5BKPCcl/koePVu1/q9k83lJrzGsYwMTOhPH cCK5dxPGLYls556i7ov7+9D0WiVYv6l/8Z54fayZB5KCdGPhWVPKZ3dtZRjgHSe/HFyT pe1OJkZwnIE4VPjo2PF/Wl8R+pbEHuc+q9bigRC1KuGK6Vhc4RVKs1g3Cnl+KSO08fWJ 7rA2AXhlyE/pNwt/zs6V1Zr3n1W8OcuLIim8I2r91FYj+1nQuXIEyovkDiYQRtl8LEz7 k7pQ== X-Gm-Message-State: ANoB5pnPRF4e0raf76hPE/tWQfxU6U0kl0J1hkGE+KAoWdvcF4vwvlrL V7sZcLtQZQpZxwaYLRd9sjCsVYdfYA4= X-Google-Smtp-Source: AA0mqf77QddJo0Eu4WwUp1H6to7LajB015YvpNgvjATqfNry6Mu9HPyXHPtzBwKstK43ZDj0EfL9OQ== X-Received: by 2002:a05:6a00:b94:b0:562:7f16:7407 with SMTP id g20-20020a056a000b9400b005627f167407mr18093582pfj.15.1668509494038; Tue, 15 Nov 2022 02:51:34 -0800 (PST) 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 d17-20020a170902f15100b00186b3c3e2dasm9459752plb.155.2022.11.15.02.51.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Nov 2022 02:51:33 -0800 (PST) In-Reply-To: <83y1scj3s8.fsf@gnu.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=casouri@gmail.com; helo=mail-pg1-x52f.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:299839 Archived-At: > On Nov 14, 2022, at 7:27 PM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Mon, 14 Nov 2022 13:57:46 -0800 >> Cc: monnier@iro.umontreal.ca, >> theo@thornhill.no, >> emacs-devel@gnu.org >>=20 >>> Doesn't the call to ts_tree_edit update those nodes? =20 >>=20 >> No. >>=20 >>> That is, aren't >>> those nodes a part of the tree that gets updated by the ts_tree_edit >>> call? >>=20 >> The node stores some information in itself (start_byte, end_byte, = inlined data, etc), and references the tree for the rest. The = information it stores needs to be updated separately. >=20 > Can we do that? What are the difficulties? 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=99t= use treesit-parser-add-after-change-function because that is hideously = long. Yuan=