From: Vincenzo Pupillo <vincenzo.pupillo@unimi.it>
To: 68879@debbugs.gnu.org
Subject: bug#68879: [PATCH] Compatibility issue with a newer version of tree-sitter-javascript
Date: Thu, 1 Feb 2024 16:18:38 +0000 [thread overview]
Message-ID: <7625339.EvYhyI6sBW@3-191.divsi.unimi.it> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 435 bytes --]
Hi,
starting from version 0.20.2 (released yesterday) of tree-sitter-javascript
the "function" primary expression has been renamed to "function_expression".
The attached patch (for emacs 29) supports the old and new versions.
I also have a version for emacs 30.
Thank you.
V.
--
Vincenzo Pupillo
Direzione ICT
Università degli Studi di Milano / University of Milan (Italy)
Via Giuseppe Colombo, 46, 20133 Milano
[-- Attachment #1.2: 0001-Fixed-incompatibility-with-tree-sitter-javascrip-0.2.patch --]
[-- Type: text/x-patch, Size: 2806 bytes --]
From 91b8853fb71e72f65b135535cf4d2bb3f1d3722f Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Thu, 1 Feb 2024 16:57:39 +0100
Subject: [PATCH] Fixed incompatibility with tree-sitter-javascrip >= 0.20.2 .
Starting from version 0.20.2 it has the primary expression \"fuction\".
has been renamed to \"function_expression\". A new function checks if
the new primary expression is available, so it returns the correct rules.
*
lisp/progmodes/js.el (js--treesit-font-lock-compatibility-definition-feature):
the new function.
* lisp/progmodes/js.el (js--treesit-font-lock-settings): Use this.
---
lisp/progmodes/js.el | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e4ccfd73cc7..12c4d0aedb8 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3427,6 +3427,26 @@ c-paragraph-start
;;; Tree sitter integration
+(defun js--treesit-font-lock-compatibility-definition-feature ()
+ "Font lock helper, to handle different releases of tree-sitter-javascript.
+Check if a node type is available, then return the right font lock rules
+for \"definition\" feature."
+ (condition-case nil
+ (progn (treesit-query-capture 'javascript '((function_expression) @cap))
+ ;; starting from 0.20.2
+ '((function_expression
+ name: (identifier) @font-lock-function-name-face)
+ (variable_declarator
+ name: (identifier) @font-lock-function-name-face
+ value: [(function_expression) (arrow_function)])))
+ (error
+ ;; older version
+ '((function
+ name: (identifier) @font-lock-function-name-face)
+ (variable_declarator
+ name: (identifier) @font-lock-function-name-face
+ value: [(function) (arrow_function)])))))
+
(defun js-jsx--treesit-indent-compatibility-bb1f97b ()
"Indent rules helper, to handle different releases of tree-sitter-javascript.
Check if a node type is available, then return the right indent rules."
@@ -3538,8 +3558,7 @@ js--treesit-font-lock-settings
:language 'javascript
:feature 'definition
- '((function
- name: (identifier) @font-lock-function-name-face)
+ `(,@(js--treesit-font-lock-compatibility-definition-feature)
(class_declaration
name: (identifier) @font-lock-type-face)
@@ -3558,10 +3577,6 @@ js--treesit-font-lock-settings
(variable_declarator
name: (identifier) @font-lock-variable-name-face)
- (variable_declarator
- name: (identifier) @font-lock-function-name-face
- value: [(function) (arrow_function)])
-
(variable_declarator
name: [(array_pattern (identifier) @font-lock-variable-name-face)
(object_pattern
--
2.43.0
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next reply other threads:[~2024-02-01 16:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 16:18 Vincenzo Pupillo [this message]
2024-02-02 6:26 ` bug#68879: [PATCH] Compatibility issue with a newer version of tree-sitter-javascript Eli Zaretskii
2024-02-02 8:52 ` Vincenzo Pupillo
2024-02-03 9:21 ` Eli Zaretskii
2024-02-03 10:52 ` Vincenzo Pupillo
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=7625339.EvYhyI6sBW@3-191.divsi.unimi.it \
--to=vincenzo.pupillo@unimi.it \
--cc=68879@debbugs.gnu.org \
/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.