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: Sat, 16 Dec 2023 10:22:41 -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> <765D713E-9923-4F66-9044-9D69C104C9B0@gmail.com> <33fe5d61-5022-67c5-6a65-babde4fb7f91@gutov.dev> <92CACD38-9534-4A07-8DE3-CE8408272FB6@gmail.com> <59CC46F7-867E-4C74-83EC-49B41DF0FAB8@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28076"; 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 Sat Dec 16 16:23:31 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 1rEWVl-00072k-RS for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Dec 2023 16:23:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEWVP-0003ev-A1; Sat, 16 Dec 2023 10:23:07 -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 1rEWVN-0003eE-Ns for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 10:23:05 -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 1rEWVJ-0008HX-JX for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 10:23:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rEWVK-0003mc-6r for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 10:23: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: Sat, 16 Dec 2023 15:23: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.170274017214524 (code B ref 66732); Sat, 16 Dec 2023 15:23:02 +0000 Original-Received: (at 66732) by debbugs.gnu.org; 16 Dec 2023 15:22:52 +0000 Original-Received: from localhost ([127.0.0.1]:55750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEWVA-0003mC-C1 for submit@debbugs.gnu.org; Sat, 16 Dec 2023 10:22:52 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54677) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEWV8-0003lw-3x for 66732@debbugs.gnu.org; Sat, 16 Dec 2023 10:22:50 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 204D1100068; Sat, 16 Dec 2023 10:22:44 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1702740163; bh=xoURttSO5FYT5tiHtcFDjVEwwPIoR7ZF+EV8+gnk1Hw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bipnacYbMqPIT+DxsYI/m933l4vzmeWwswT/Xlvgx1OUKrDnlhCVc1p+z4c7K8EpA cFVPXnxMZDhRGc/K/bk0Ev2AXgsU29xtHsGu3gtuhF8Esg0rvNngjgGMrMflpqRv+e 083lozRxiiidcBND2Sq2CJPQE1BNnZ5vL8iFxb89J1UrCtYiwBG40KzxeiPKNfBW6c 416R7+/rbT2F7yBllh2kEr5qykF/idIoNtT90YALICu5kEdAJNK1fdNOO9PKCtHR5J K4kUunuFTI5dCQ3DnJmL8sAuwBaLuIvMr6J9AwGmUMiPn0mgeI4VZSkVbyl7ljB86P SzAOeNF1PF1pg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 362C9100033; Sat, 16 Dec 2023 10:22:43 -0500 (EST) Original-Received: from pastel (65-110-221-238.cpe.pppoe.ca [65.110.221.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 032DD120887; Sat, 16 Dec 2023 10:22:42 -0500 (EST) In-Reply-To: <59CC46F7-867E-4C74-83EC-49B41DF0FAB8@gmail.com> (Yuan Fu's message of "Fri, 15 Dec 2023 21:56:18 -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:276356 Archived-At: > diff --git a/lisp/treesit.el b/lisp/treesit.el > index 8a07f5023a9..a6ca6334133 100644 > --- a/lisp/treesit.el > +++ b/lisp/treesit.el > @@ -1080,13 +1080,39 @@ treesit--font-lock-notifier > "Ensures updated parts of the parse-tree are refontified. > RANGES is a list of (BEG . END) ranges, PARSER is the tree-sitter > parser notifying of the change." > - (with-current-buffer (treesit-parser-buffer parser) > - (dolist (range ranges) > - (when treesit--font-lock-verbose > - (message "Notifier received range: %s-%s" > - (car range) (cdr range))) > - (with-silent-modifications > - (put-text-property (car range) (cdr range) 'fontified nil))))) > + ;; (with-current-buffer (treesit-parser-buffer parser) > + ;; (dolist (range ranges) > + ;; (when treesit--font-lock-verbose > + ;; (message "Notifier received range: %s-%s" > + ;; (car range) (cdr range))) > + ;; (with-silent-modifications > + ;; (put-text-property (car range) (cdr range) 'fontified nil)))) > + ) > + > +(defun treesit--font-lock-extend-region () > + (treesit-update-ranges) > + (dolist (parser (treesit-parser-list nil nil t)) > + (treesit-parser-root-node parser)) > + (let ((old-beg font-lock-beg) > + (old-end font-lock-end)) > + (dolist (parser (treesit-parser-list nil nil t)) > + (when-let ((table treesit--parser-updated-ranges) > + (ranges (gethash parser table))) > + (dolist (range ranges) > + (setq font-lock-beg (max (min font-lock-beg (car range)) (point-min))) > + (setq font-lock-end (min (max font-lock-end (cdr range)) (point-max)))))) > + (put-text-property font-lock-beg font-lock-end 'fontified nil) > + (message "extend region: %s-%s %s-%s this-command: %s" old-beg old-end > + font-lock-beg font-lock-end this-command))) Hmm... This `put-text-property` can't be right. Can you trace `font-lock-fontify-region` and `font-lock-default-fontify-region` to check that they correctly return the proper (extended) bounds of the region they (re)fontified? Stefan