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: Mon, 14 Nov 2022 13:57:46 -0800 Message-ID: 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> 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="29913"; 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 02:06:45 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 1oukPU-0007ZM-C4 for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 02:06:44 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouihh-0001Hh-Cs; Mon, 14 Nov 2022 18:17:26 -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 1ouie2-0001o2-16 for emacs-devel@gnu.org; Mon, 14 Nov 2022 18:13:38 -0500 Original-Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ouhSh-0003tl-Di; Mon, 14 Nov 2022 16:57:52 -0500 Original-Received: by mail-pj1-x1033.google.com with SMTP id h14so11582088pjv.4; Mon, 14 Nov 2022 13:57:50 -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=jdh9uJ7xnSWXg07DTdIaEvNtz6C+7gyRx9E0bi0q5o0=; b=J9jKpqmiqBkhWJ8sjGPqYjy2prxvx3MsZYU6Fyq1XiKlXSnTUOUlQbNHAREZDISTqK ShG5B0M6TGcyHJcdimbhZDDDI/9NshkZ8BPpgaS+V4z/UNdG16H5AXvfTEPJdrZZQQUC YaR8+9EP7/Ia01R94obltCtKuQ2UK0J4fTlQNlqTt07X4uYURbjKWvG77+wXalR0W9Ka FGXpuF2lryvt+AAOBD3zECbyDjsC6MicxVTQjcRUHG7cbZF/DGjjtri+D/E1/YKJ8tKU P0mmSokklA8w3QUewQiGItnZ8xryjOhGJE74/uChQ97o6jlVEnsikmS/bqXvAepnLP7h o77A== 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=jdh9uJ7xnSWXg07DTdIaEvNtz6C+7gyRx9E0bi0q5o0=; b=G4h2hBeVRKkgptgdqRPFtyd7NK8boBpgbxRRMaxct9fx46RwHhIaf3GUkj/KvmlBbL SXIB3WYfb1vVRgchDoEaSkWl5N72SQriVhDReId/W60YaDEAquHjJtseMsoHirwvhMFX fywUk1X/YGE9/P1MR/XGgvg1BnPNaEmXLlJuaYcLyJmYXAaNJuH2pDsZa2TAudh8gxxo 01UzD3jMeCzRlzFQuv2mSHBjEVqR2/EFcd9trSZmiLgIcb7EonmYUQIgpP9VtcfqTgN/ JkI5KmXHyb6YpCSSOp9VBDU/vYtBF832SyzZaT2iKlWITRXMQZRWQOfJCXf4FO7KNHzc gcBA== X-Gm-Message-State: ANoB5pmXfXJ1dYi9DuPPHw9mo4SYEDEUFKUQr/BphvMBGHoceurOkHly nZAUyMvnLbruQGbuG+pq4gVDMkubchKyKw== X-Google-Smtp-Source: AA0mqf7aRQaP2qRUkJt+kHwc7Q5L19axszM98Fo+8+GdKBm0BsVM8xwlsWkhKIYAmF+fEHqhLLUyrA== X-Received: by 2002:a17:90b:2750:b0:212:c87e:dc8b with SMTP id qi16-20020a17090b275000b00212c87edc8bmr15532915pjb.229.1668463068931; Mon, 14 Nov 2022 13:57:48 -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 y188-20020a6364c5000000b00451f4071151sm6179007pgb.65.2022.11.14.13.57.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Nov 2022 13:57:48 -0800 (PST) In-Reply-To: <83zgcti9gh.fsf@gnu.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=casouri@gmail.com; helo=mail-pj1-x1033.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:299808 Archived-At: > On Nov 14, 2022, at 12:10 PM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Mon, 14 Nov 2022 11:51:59 -0800 >> Cc: monnier@iro.umontreal.ca, >> theo@thornhill.no, >> emacs-devel@gnu.org >>=20 >>>> Well we update the parse tree and re-parse, but we currently = don=E2=80=99t update the nodes created from the old tree. Keeping all = nodes updated requires us to track all live nodes and update them = whenever the buffer is edited. >>>=20 >>> I guess I still don't understand what exactly do you mean by "update >>> the node". Can you explain that in more detail? >>=20 >> My bad. So when buffer changes (insert in X, delete from X to Y), we = inform tree-sitter of this change by =E2=80=9Cupdating=E2=80=9D the = tree: >>=20 >> const TSInputEdit edit =3D >> treesit_prepare_input_edit (start_byte, old_end_byte, = new_end_byte); >>=20 >> ts_tree_edit (tree, &edit); >>=20 >> Then when we re-parse, tree-sitter knows which part of the buffer has = changed and needs to be re-parsed, and only parses those, hence = =E2=80=9Cincremental parsing=E2=80=9D.=20 >>=20 >> Tree-sitter nodes needs similar updates, so that it is in sync with = the buffer text. >=20 > Doesn't the call to ts_tree_edit update those nodes? =20 No. > That is, aren't > those nodes a part of the tree that gets updated by the ts_tree_edit > call? 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. Yuan