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.bugs Subject: bug#59630: 29.0.50; treesitter-buffer-root-node doesn't change when changing buffer restriction Date: Mon, 28 Nov 2022 14:37:18 -0800 Message-ID: <0AB3EC36-A80D-43C9-8CF6-B23D87958FE0@gmail.com> References: <87zgcc1s1n.fsf@miha-pc> 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="6566"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59630@debbugs.gnu.org, miha@kamnitnik.top To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 28 23:38:23 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1ozmla-0001Yh-Vx for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 28 Nov 2022 23:38:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozmlI-00066z-SI; Mon, 28 Nov 2022 17:38:04 -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 1ozmlH-00064R-I9 for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2022 17:38:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozmlH-0007oE-A1 for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2022 17:38:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ozmlG-0005dN-9J for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2022 17:38:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87zgcc1s1n.fsf@miha-pc> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Nov 2022 22:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59630 X-GNU-PR-Package: emacs Original-Received: via spool by 59630-submit@debbugs.gnu.org id=B59630.166967504821630 (code B ref 59630); Mon, 28 Nov 2022 22:38:02 +0000 Original-Received: (at 59630) by debbugs.gnu.org; 28 Nov 2022 22:37:28 +0000 Original-Received: from localhost ([127.0.0.1]:51358 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ozmkh-0005co-Nl for submit@debbugs.gnu.org; Mon, 28 Nov 2022 17:37:28 -0500 Original-Received: from mail-pl1-f178.google.com ([209.85.214.178]:42757) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ozmkf-0005cb-Mq for 59630@debbugs.gnu.org; Mon, 28 Nov 2022 17:37:26 -0500 Original-Received: by mail-pl1-f178.google.com with SMTP id b21so11614265plc.9 for <59630@debbugs.gnu.org>; Mon, 28 Nov 2022 14:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=PpgRoo3i7G1N5EFwUHDnLulmPy77f7VC+U7sVSHQ5Jc=; b=IVuKR0EdATcEoai9Z1xytMwb9gnYTTA5sCscVgqqoroWPm5ZZQWU45iyX3IwkZRHEW 4i5Huo+W7H9tDKq3ksfb/3IaOtfk7aiY1Gjc3+3NTLKoe5xdFJ6I+bAwVi9I6AL9lHqQ M3DvIsgwTAM3keodUEzSIQLtbN9e7vKVm89YTdRRPpXCmtSCordZSEfAOCWXbf8qaFyM +JIcZ6QdQLIJEcpVsSZQXj2QQ1fu2dpAIgefduJNmZbR9yhcd08K98BPCSW8/B49HoaK mBhSuvccbjjUEvfrrAgp4yzCB98pLJPXeYFVFVRnk2qFLBxsWutZlBbFtetS/UP0cubR Ynbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PpgRoo3i7G1N5EFwUHDnLulmPy77f7VC+U7sVSHQ5Jc=; b=I57zCqbdguF2hm4vFjNnp2hvKkDe+O0ni5ZeTV1lKGa1M7diL2OW/+1NH0Y4hyLBrn xVCuyz2HDagtZUB/Cd5eMtibmbmKdnyHCn9h+eS1lBKP+2rh5ISaU2C8mC/1N3Nc9QHB QFHgdJF6m6FJ+tQPxTAHIz1+FxPZuybNzVBDTkTdzoeRqtw3AxLuK92R2+DpCLabLYKo uFEVrZd4AaE50SclHB6WyoRaOeOejA0YdPEm9jIbeWqpmecjqsCvqd+m4GIYSAZfnDNv NJzNiQlubzMRfyhFJhFjvgWo0qvWtP3lXUJU1HL8BqI17D/Y7PVCiizWBUZTCEwDN3oo vTWQ== X-Gm-Message-State: ANoB5pns65F/4YB7aKelZ4mB5yJaZ3os9xAQqrjR4yKKp91sFYUCljhU XEHrS9z8L58p9J+F2yR1CEk= X-Google-Smtp-Source: AA0mqf7+gvvACBMLdVOZ4Y0fzAntkPLZDOmbqTWCzfZBdKbvkyxmWsZ04UARXVrLEKVyN2kjB66ZQA== X-Received: by 2002:a17:903:2683:b0:186:6f1e:5087 with SMTP id jf3-20020a170903268300b001866f1e5087mr35152115plb.119.1669675039666; Mon, 28 Nov 2022 14:37:19 -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 cq16-20020a17090af99000b00219220edf0dsm4190221pjb.48.2022.11.28.14.37.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2022 14:37:19 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:249345 Archived-At: Eli Zaretskii writes: >> From: Yuan Fu >> Date: Sun, 27 Nov 2022 14:40:41 -0800 >> Cc: 59630@debbugs.gnu.org, >> Eli Zaretskii >>=20 >> > ELISP> (widen) >> > ELISP> (treesit-buffer-root-node 'bash) >> > #> > (program) >> > in 1-4> ;; <---- This is not expected, the root node should span = 1-9 >> >=20 >> > ELISP> (buffer-string) >> > "echo '123'" >>=20 >> Thanks. We didn=E2=80=99t edit the buffer after widening, so = tree-sitter >> didn=E2=80=99t reparse and used the old tree, which sees the narrowed >> buffer. Eli, what would be a good and reliable way to know that >> narrowing has changed? I see current_buffer->clip_changed set to 1 >> in narrow-to-region and widen, but when are they set to 0? > > Not sure what exactly are you after. If you want to catch the moment = when > we change the buffer restriction, you will have to add something to > Fnarrow_to_region and Fwiden. However, why does tree-sitter need to = know > about changes in the narrowing, unless it is asked to update something = or > produce a tree? I thought we decided to update this stuff lazily, = only when > actually needed? Being sensitive to these changes would require you = to have > some logic, because a buffer can be narrowed and widened several times = in a > sequence without any consequences for tree-sitter, and asking the = parser to > update itself will just burn CPU cycles. So if this is really needed, = let's > discuss for which purposes and under what conditions. > > I actually don't think why we should be worried by the above scenario; = can > you explain? > We still parse lazily, and narrow/widen wouldn=E2=80=99t affect the = parse tree, until user requests for a node when the restriction is different from last time we parsed the buffer. Basically: request-node <-- last time we parsed narrow widen narrow widen request-node <-- no need to reparse (1) request-node <-- last time we parsed edits-buffer request-node <-- need to reparse (2) request-node <-- last time we parsed narrow request-node <-- need to reparse (3) Right now in case (3) we don=E2=80=99t reparse the buffer. I have a = reasonable fix in f794263da20. > To answer your question: the clip_changed flag is reset in > reconsider_clip_changes, which is called at the beginning of = redisplay, and > when a window's redisplay is successfully completed (see > mark_window_display_accurate_1). However, this flag is not meaningful > outside of redisplay, in particular when redisplay cycle is NOT = running. So > I'm not sure it is what you want. Thanks. Yeah that=E2=80=99s not something we want to use. Yuan