all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Danny Freeman <danny@dfreeman.email>, Yuan Fu <casouri@gmail.com>,
	Theodor Thornhill <theo@thornhill.no>
Cc: 65234@debbugs.gnu.org, v.pupillo@gmail.com, dancol@dancol.org
Subject: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars
Date: Sat, 12 Aug 2023 08:41:45 +0300	[thread overview]
Message-ID: <83sf8og6li.fsf@gnu.org> (raw)
In-Reply-To: <87jzu1p8kt.fsf@dfreeman.email> (bug-gnu-emacs@gnu.org)

> Cc: Vincenzo Pupillo <v.pupillo@gmail.com>,
>  Daniel Colascione <dancol@dancol.org>
> 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" <bug-gnu-emacs@gnu.org>
> 
> 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/>
> 
> "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.





  reply	other threads:[~2023-08-12  5:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11 21:18 bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-12  5:41 ` Eli Zaretskii [this message]
2023-08-16  2:04   ` Dmitry Gutov
2023-08-17  8:06     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83sf8og6li.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=65234@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=dancol@dancol.org \
    --cc=danny@dfreeman.email \
    --cc=theo@thornhill.no \
    --cc=v.pupillo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.