From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66732: tree-sitter fontification doesn't update multi-line syntax reliably Date: Wed, 13 Dec 2023 09:30:22 -0500 Message-ID: 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> Reply-To: Stefan Monnier 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="29627"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Dmitry Gutov , Eli Zaretskii , 66732@debbugs.gnu.org, dominik@honnef.co To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 13 15:31:19 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 1rDQGc-0007Wr-JY for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Dec 2023 15:31:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDQGQ-00085C-Sm; Wed, 13 Dec 2023 09:31:06 -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 1rDQGD-000820-U0 for bug-gnu-emacs@gnu.org; Wed, 13 Dec 2023 09:30:57 -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 1rDQG6-0008Dc-AU for bug-gnu-emacs@gnu.org; Wed, 13 Dec 2023 09:30:49 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rDQGM-000827-A2 for bug-gnu-emacs@gnu.org; Wed, 13 Dec 2023 09:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Dec 2023 14:31:02 +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.170247784930858 (code B ref 66732); Wed, 13 Dec 2023 14:31:02 +0000 Original-Received: (at 66732) by debbugs.gnu.org; 13 Dec 2023 14:30:49 +0000 Original-Received: from localhost ([127.0.0.1]:58482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDQG8-00081e-KQ for submit@debbugs.gnu.org; Wed, 13 Dec 2023 09:30:48 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:44241) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDQG5-00081M-Hg for 66732@debbugs.gnu.org; Wed, 13 Dec 2023 09:30:47 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 25310100043; Wed, 13 Dec 2023 09:30:24 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1702477823; bh=AmcrTFVvJahMftNm9CQXQ8XA3LcOhmdw3dw9KedTPx4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=T4yEwxeOqEgf08gCi8HD3AmZce0grpz5EHY7P3KGHeKjJJVjGuKL2JIAbcUSqKAx6 8yzrhjBgWE5vrgcFimBshD96UBBt1Eq2Iaq8A52rPnjrm8qxTLuxSIf902ISeCyJ+V C8QerMc+oFDq3SMzAdQM0vLwz1l9znc+gXiKm1ZAweUbKLo/9+RgyrrmOBYcWlNbKn naE7ergWrzM+QQIpWwrvlDXQTZ7aY+23y2jEzo5StTLYpQeD/zy7acryA5gyumPXJy vKt03nHItI+R6RJ/EI6R7C1pqozV8d+rgFDi0xGu8tV6ukqbAR+88HrQo28NCA3jJo 01jt2bJofac1A== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 187041000AD; Wed, 13 Dec 2023 09:30:23 -0500 (EST) Original-Received: from pastel (unknown [45.72.203.88]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id DB3F912090D; Wed, 13 Dec 2023 09:30:22 -0500 (EST) In-Reply-To: (Yuan Fu's message of "Tue, 12 Dec 2023 23:12:31 -0800") 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:276138 Archived-At: > The problem is, when you type /* RET foo RET */ the block comment is not = fontified in comment face > > x > > > > That=E2=80=99s because before the user types the final =E2=80=9C/=E2=80= =9C, there isn=E2=80=99t a complete > comment node in the parse tree. When the user types the =E2=80=9C/=E2=80= =9C, we need to mark > the whole block comment for refontification. > > We actually have that, when the parser reparses, it=E2=80=99ll also compu= te the > affected region, the region that changed during the last reparse, and it= =E2=80=99ll > call the =E2=80=9Cnotifiers=E2=80=9D with that region. We install a font-= lock-notifier, > which simply sets fontified text property to nil in that region, so > redisplay would call jit-lock to fontify that region. > > In our example, the region would be the block comment. Thanks. If the reparse is done during `jit-lock` then, depending on how we do it, it may indeed require re-running jit-lock, tho not necessarily. E.g. if the reparse+notification is used to extend-region, then fontification will already have been done and doesn't need to be repeated. OTOH the rendering will have already been done with the pre-reparse state of the buffer for the beginning of the buffer (i.e. before the "*/"), so we need to re-render (i.e. re-run the redisplay) for that part of the buffer. But that should not need any re-parse nor re-fontification. If your `font-lock-extend-region-function` returns correct bounds, jit-lock should take care of re-rendering as needed. If the reparse (and the corresponding setting of `fontified`) is done before redisplay, then there should be no need to do any double work at all. So maybe reparsing from a `pre-redisplay-functions` is an even better option. The downside is that it doesn't save you from needing to handle reparses from the `font-lock-extend-region-function`, in order to handle the cases where the redisplay wasn't involved. Stefan