From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#66732: tree-sitter fontification doesn't update multi-line syntax reliably Date: Sun, 17 Dec 2023 01:02:39 +0200 Message-ID: <63cf5320-d680-8548-9f05-90eab7644da6@gutov.dev> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3233"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: Yuan Fu , 66732@debbugs.gnu.org, Eli Zaretskii , dominik@honnef.co To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 17 00:03:18 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 1rEdgi-0000Zh-7E for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 17 Dec 2023 00:03:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEdgU-0004Mq-MV; Sat, 16 Dec 2023 18:03:02 -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 1rEdgT-0004Mi-KL for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 18:03:01 -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 1rEdgT-0002KV-9y for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 18:03:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rEdgU-00053c-2v for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 18:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Dec 2023 23:03: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.170276777119423 (code B ref 66732); Sat, 16 Dec 2023 23:03:02 +0000 Original-Received: (at 66732) by debbugs.gnu.org; 16 Dec 2023 23:02:51 +0000 Original-Received: from localhost ([127.0.0.1]:56320 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEdgJ-00053C-GX for submit@debbugs.gnu.org; Sat, 16 Dec 2023 18:02:51 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39753) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEdgH-00052x-4d for 66732@debbugs.gnu.org; Sat, 16 Dec 2023 18:02:50 -0500 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 25FFF5C0083; Sat, 16 Dec 2023 18:02:43 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 16 Dec 2023 18:02:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1702767763; x=1702854163; bh=lswI3kh5rAJsAGkOwVhGJSthnkiTaX5s/XuBqtbB4ug=; b= Bcrj/WEGuXJqyvtPj3sgcl0tgqu2yxGvCPYwhFB/t/zQGMIdYrxvGkV9fl6Bg4QK 7CFx8KbwRHM7DHkS33ncoVHtsv4lb1s5NOJ7maI7b9T1vQc3zyfoRw+zlZqvZDSz Rz+T9Wuhk4KtfPVvMuSclqjT1IKKWxKi3SkJ//JRxF5pF7isuskdEbhnSn9RzeLk vy+Ki0mMO9aBbdsnQPz4sYqChm0MVK5e64wW+OdPU/2IsY7Fj3AplDitcTDhcoxc 8AqRSM+Jm2UmRY8XdCD7wrp/DrIXTlDd5a8oC0jTQ7/PUIOYwMJTrU9+pOKOwenS b31tKlB3ngxm882dDQRQDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1702767763; x= 1702854163; bh=lswI3kh5rAJsAGkOwVhGJSthnkiTaX5s/XuBqtbB4ug=; b=G xmaul3SGIZoNIQitaz1h1YBSp7t9L8nzvYzHAX4SbiIv8+42qvKZS25E8aK1GfnI VZJgiX31L7cAYMA9PK5lF/CuKvNpQQ9IJlhATtWp5BYqIUW24YFyjk6l2kFqN0Yq S80tX5SmxSkQzv6KEYgj+Is9PygkEnamaX8r395yJvy96BLKofSp8mxn3fgJVmt2 5VOPKj0k9p0KjXb8v0Ijnbx/P8N93LYrJIQ9TkcU1as2UWz5YONi+SKadhkKkr0H pZI8SwEZ/KFQz470BSlMSM4Q28iWAXElnDen8an3TRqybCn1KOS+cVzGT3RpDUpy lLX1KGWFU8k3EzbtK/JvQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddthedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepiefgteevheevveffheeltdeukeeiieekueefgedugfefgefhudelgfefveel vdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 16 Dec 2023 18:02:41 -0500 (EST) Content-Language: en-US In-Reply-To: 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:276389 Archived-At: On 16/12/2023 19:43, Stefan Monnier wrote: >> I think most of the time the parser notifier will send ranges of limited >> size (as one or other piece of text gets recognized as e.g. a comment, or >> a raw string -- the bounds of the respective node that changed). > > Yes, of course, in practice it will usually work OK. > I'm talking about what should happen ideally so that we can make an > informed decision about the code we decide to use in the end, knowing > its downsides. I figured that it would be useful at least to start with the same solution for both font-lock and syntax, because bugs in the former are usually easier to notice earlier. But you have a point that doing invalidation earlier will mean that font-lock won't have to refontify the whole big region (whenever that actually happens in practice), only the visible part. >>> One of the places where we'd need the sprinkle would be >>> `pre-redisplay-functions`. Another one might be `syntax-ppss`? >> syntax-ppss has syntax-propertize-extend-region-functions. I haven't found >> any better suitable hooks than that. > > Indeed, I don't think there's a good hook for that yet, tho maybe > `syntax-propertize-extend-region-functions` is good enough (basically > make it call `treesit--font-lock-notifier` but return nil), assuming we > have set a `syntax-propertize-function`. Solutions for syntax and font-lock will likely need to work independently: - syntax-ppss can be called outside of font-lock (e.g. by electric-pair) - font-lock can work without syntax-propertize (e.g. when syntax-propertize-function is nil), and even when it does get called, it can happen somewhere inside font-lock highlighting code. E.g. by the time we reach treesit-font-lock-fontify-region, the region to refontify has already been decided.