From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars Date: Sat, 12 Aug 2023 08:41:45 +0300 Message-ID: <83sf8og6li.fsf@gnu.org> References: <87jzu1p8kt.fsf@dfreeman.email> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34387"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65234@debbugs.gnu.org, v.pupillo@gmail.com, dancol@dancol.org To: Danny Freeman , Yuan Fu , Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 12 07:42:22 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 1qUhOI-0008bg-1Z for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Aug 2023 07:42:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUhO6-00052s-5F; Sat, 12 Aug 2023 01:42:10 -0400 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 1qUhNz-0004ze-52 for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 01:42:03 -0400 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 1qUhNy-0002yf-Mu for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 01:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUhNy-0001Eo-Ho for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 01:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Aug 2023 05:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65234 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65234-submit@debbugs.gnu.org id=B65234.16918188864695 (code B ref 65234); Sat, 12 Aug 2023 05:42:02 +0000 Original-Received: (at 65234) by debbugs.gnu.org; 12 Aug 2023 05:41:26 +0000 Original-Received: from localhost ([127.0.0.1]:48442 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUhNN-0001Dd-S8 for submit@debbugs.gnu.org; Sat, 12 Aug 2023 01:41:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53936) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUhNL-0001DM-FU for 65234@debbugs.gnu.org; Sat, 12 Aug 2023 01:41:24 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUhNF-0002rI-6H; Sat, 12 Aug 2023 01:41:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=yyRNjtJlAYhHbg/LJCOdS87x1fSGf3VEdBqfUaCUwyY=; b=fsdzXnyURwNh 1bcfNnhu+4j+Q9+RKfD99cPCyYwN+Qu3WXQkXXVmJPWElsDGncvQ8TcGQPkXkZS4Ub0CPRWbOGb8y aUehcpCMLdpeto0v1vf44q2+Yf4Vse/5gzlN60G75A21CmYpb1qkDM8IHsNeZjhcacShZ/7qvpksT +tV2nZHXLwu/SKb6qaYxOwMvGlVpwV1W9W/vNjszQ6Y273KchEdVq3R3lw23hUVysJulxHwokULyg s0HHahl9X4Z5fVJeUBL5xJSmeDJEt1F5q/ivi1yhAIQYooV38Xd5CjmQKvB2i4rawqlRSeXTeVSrM B79T5ELpAgnW0U2cNdqa5A==; In-Reply-To: <87jzu1p8kt.fsf@dfreeman.email> (bug-gnu-emacs@gnu.org) 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:267248 Archived-At: > Cc: Vincenzo Pupillo , > Daniel Colascione > Date: Fri, 11 Aug 2023 17:18:32 -0400 > From: Danny Freeman via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > I have a patch to fix a bug I found in js-ts-mode. > > Description of Problem: > A new function was wrtiten to account for a breaking change in the > tree-sitter-javascript grammar, see [0] > > This function returns some tree-sitter queries used by the js-ts-mode > font lock settings. > > We attempted to check for the breaking change by running a query > (treesit-query-capture 'javascript '((member_expression) @capture)) > which would in theory fail when an old grammar is being used. > > The problem is that this query does not fail on old grammars, so the > backwards incompatible font-lock queries are always used. When > font-locking a JSX file, the queries that look like > (jsx_opening_element [(member_expression) ... > throw errors and font locking fails (only on jsx elements). > > Solution: > Instead of fixing the bb1f97b compatibility check with something like > > (treesit-query-capture 'javascript > '((jsx_opening_element (member_expression) @capture))) > > I have opted re-write the font lock rules that capture the same > nodes by the "name:" field instead of by the specific node names (where > the backwards incompatible change took place). > > The possible nodes that can be in the "name" field: > After [1]: "identifier" "member_expression" "jsx_namespace_name" > Before [2]: "identifier" "nested_identifier" "jsx_namespace_name" > > "jsx_namespace_name" is an additional node captured by these rules. As > an example, in the JSX expression > > > > "Foo:bar" is a node of type "jsx_namespace_name" and would be captured > with @font-lock-function-call-face, where before this change it was not > captured or highlighted at all. If there is a reason this should not be > captured and highlighted, a new query can be added in to capture these > nodes first with @default so they are not highlighted like before. > > Some thoughts: > These backwards incompatible grammar changes are rough to deal with, but > I'm glad they are taken into account. I use nixos, and the current > stable version 23.05 packages the older version of the JS grammar for > emacs which is how I noticed this. I wish the developers of the js > grammar were more careful about backwards compatible changes. The fact > that they were renaming a node without much reason didn't seem to bother > any of the maintainers. Yuan, Theo: any comments on this? Is this safe enough to go into the emacs-29 branch? Thanks.