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#66732: tree-sitter fontification doesn't update multi-line syntax reliably Date: Thu, 14 Dec 2023 00:29:44 -0800 Message-ID: <765D713E-9923-4F66-9044-9D69C104C9B0@gmail.com> References: <878r7s5cdf.fsf@honnef.co> <83fs1tbou1.fsf@gnu.org> <835y1zo3rw.fsf@gnu.org> <2ce274aa-6d01-4d0a-b10c-07f821343fed@gmail.com> <50920549-006c-0153-2471-02e41a3dada7@gutov.dev> <8c7cd429-bdc3-4fac-ad1c-fbad793bf1a0@gmail.com> <231ebcd1-ec30-0432-82e7-d63e11cd65f7@gutov.dev> 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="15721"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 66732@debbugs.gnu.org, Stefan Monnier , dominik@honnef.co To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 14 09:31:05 2023 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 1rDh7Z-0003s1-PO for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 14 Dec 2023 09:31:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDh7M-0006Bu-7D; Thu, 14 Dec 2023 03:30:52 -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 1rDh7H-0006Au-Su for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2023 03:30:48 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rDh7F-0001dq-ST for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2023 03:30:47 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rDh7V-0003dc-Ps for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2023 03:31:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Dec 2023 08:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66732 X-GNU-PR-Package: emacs Original-Received: via spool by 66732-submit@debbugs.gnu.org id=B66732.170254262113935 (code B ref 66732); Thu, 14 Dec 2023 08:31:01 +0000 Original-Received: (at 66732) by debbugs.gnu.org; 14 Dec 2023 08:30:21 +0000 Original-Received: from localhost ([127.0.0.1]:60181 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDh6q-0003ch-IS for submit@debbugs.gnu.org; Thu, 14 Dec 2023 03:30:20 -0500 Original-Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:53570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDh6o-0003cP-JX for 66732@debbugs.gnu.org; Thu, 14 Dec 2023 03:30:19 -0500 Original-Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5c68da9d639so4520021a12.3 for <66732@debbugs.gnu.org>; Thu, 14 Dec 2023 00:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702542596; x=1703147396; darn=debbugs.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=0xsmDL3BvNK77BsdJEPboKaNXsIhrW1VGAbWHOuSsNA=; b=UJxziifIrgPAtiIc6kMQuehyBhW5uwpQGfgjUiwgyL5LS/EIRlq0riTT9a0/a67dCd HqHY6LopBNUXskMivW5vhamhi5ZIbko9gydfyguiSDXO/Mmkyancnha9KT0h4IUgrbmW 2QOmnDd/xHw+gvOZv4yqREtIpAkihxCEBZjurvm5nK1145ow4xmJi6NXdvWLl+NT7y4/ zVOBfFt082N+9Vhmm8JQGa76mP+gZFk9tRsaBFb7KECtMd+YU/Djj9YAqxumLgRyf1wH HhsTmkPyJfi4Kokc2+P+uw/BhroR7oPnt8PVFPcXcuXHKRmrMZgYqwNiMa1f2PMu/Vyh 8C6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702542596; x=1703147396; 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=0xsmDL3BvNK77BsdJEPboKaNXsIhrW1VGAbWHOuSsNA=; b=OKoO5SdaurMHln12XbWnBh7UactPFRVCB7KN8suQm2iatqWmmWqDTxMa3N3Y0PRcpF CrPajjXAOo9IuWMAbC95Gua1OfHuhl3kDQBA2zJ1uWuKorIJLFim0DpX1EnCvDpmTARe lk6BsB9czov/dErIRxOfLtwGoUwqYUzf1cylfpqOcd1E8BrvSgDnPmTjAhMapp5vSoVq V1sQmjgBU8YYQJCj69msKFpm+0wQOHdxr+Hid+O1NxOacsqNkLIn1/DUZtjkjxakjPjP Gu4hqUy8TWgYZTX54diC0jX8g4nBHIpLJrRxg3VLKghzX+D7y6eETkadz1y0xcWOVWhi ARvA== X-Gm-Message-State: AOJu0Yyn9TamP8KKcXTI7BqZWa37M6dGSYi/FUG0I4/yG0J55VuubxjO KYJrim57guvvpMxa+9Q5Dhk= X-Google-Smtp-Source: AGHT+IFv3gVwRhT6PxtH1ef6a7uuuj12CLrb55yGebWGCjqOOk7BbkH1lmVj+j1nb2ctwVdlZWZ1qA== X-Received: by 2002:a05:6a20:8e07:b0:190:2973:512f with SMTP id y7-20020a056a208e0700b001902973512fmr6085660pzj.111.1702542596053; Thu, 14 Dec 2023 00:29:56 -0800 (PST) Original-Received: from smtpclient.apple (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id z3-20020a170902834300b001d1d1ef8be5sm11816669pln.173.2023.12.14.00.29.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2023 00:29:55 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.700.6) 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:276180 Archived-At: > On Dec 13, 2023, at 5:43 PM, Dmitry Gutov wrote: >=20 > On 13/12/2023 05:28, Yuan Fu wrote: >>>> c-ts-mode--emacs-set-ranges is registered as a range rule, so many = tree-sitter function calls it before doing anything to make sure range = is up-to-date. treesit-font-lock-fontify-region calls = treesit-update-ranges at the beginning of its body, and = treesit-update-ranges calls c-ts-mode--emacs-set-ranges. >>>=20 >>> That seems to mean that any feature accessing the parse tree should = call treesit-update-ranges first. Including syntax-propertize-functions = and *-extend-region-functions, which we currently don't do. >>>=20 >>> But which boundaries is it supposed to use? Should = treesit--syntax-extend-region call treesit-update-ranges, when wait for = the parser updates, then possibly call treesit-update-ranges again on = the extended boundaries, and so on, until the parser stops sending = notifications? Will it stop? >> It'll stop. If the ranges don't change, no reparse will happen. And = only buffer content change can cause range change. Reparse itself can't. = So at most you'll see reparse -> update ranges -> reparse. >>> Anyway, could you try my patch? Like I said, I'm not sure if the = insufficient fontification I'm observing in c-ts-mode is due to the = problem with the solution, or due to the other redisplay-related = problems on my system. >> Yeah, it doesn't solve the problem in c-ts-mode regarding block = comments. >> We might need to run (progn (force-parse) (update-ranges) = (force-parse)) before jit-lock-fontify-now and sytax-ppss. >=20 > Well... I've replaced >=20 > (treesit-buffer-root-node (treesit-language-at (point))) >=20 > in treesit--syntax-extend-region with >=20 > (treesit-buffer-root-node (treesit-language-at (point))) > (treesit-update-ranges beg end) > (treesit-buffer-root-node (treesit-language-at (point))) >=20 > and even tried commenting out the call to 'treesit-update-ranges' = inside treesit-font-lock-fontify-region, but the result looks unchanged. = And the region does get extended, according to my print-debugging inside = font-lock-default-fontify-region. >=20 > Could you check if you're seeing the same? It should be (treesit-buffer-root-node 'emacs-c) (treesit-update-ranges) (treesit-buffer-root-node =E2=80=98c) I tried, and it doesn=E2=80=99t make a difference. But I must admit = I=E2=80=99m not very clear on what your patch tries to do. Does it try = to extend the to-be-fontified region before jit-lock runs? Yuan