[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ec3f9434c7d 10/10: Make typescript-ts-mode work with latest gramm
From: |
Yuan Fu |
Subject: |
master ec3f9434c7d 10/10: Make typescript-ts-mode work with latest grammar |
Date: |
Mon, 30 Dec 2024 03:24:10 -0500 (EST) |
branch: master
commit ec3f9434c7d615dc37ba444a2200f13c84984299
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Make typescript-ts-mode work with latest grammar
* lisp/progmodes/typescript-ts-mode.el:
(tsx-ts-mode--font-lock-compatibility-bb1f97b): Return dummy
query when neither query works. In latest grammar, neither will
work, because typescript grammar doesn't include jsx grammar
anymore.
---
lisp/progmodes/typescript-ts-mode.el | 77 +++++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 27 deletions(-)
diff --git a/lisp/progmodes/typescript-ts-mode.el
b/lisp/progmodes/typescript-ts-mode.el
index df41c179e30..06635378dfd 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -22,6 +22,15 @@
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+;;; Tree-sitter language versions
+;;
+;; typescript-ts-mode is known to work with the following languages and
version:
+;; - tree-sitter-typescript: v0.23.2-2-g8e13e1d
+;;
+;; We try our best to make builtin modes work with latest grammar
+;; versions, so a more recent grammar version has a good chance to work.
+;; Send us a bug report if it doesn't.
+
;;; Commentary:
;;
@@ -192,32 +201,47 @@ Argument LANGUAGE is either `typescript' or `tsx'."
;; Warning: treesitter-query-capture says both node types are valid,
;; but then raises an error if the wrong node type is used. So it is
;; important to check with the new node type (member_expression)
+ ;;
+ ;; Later typescript grammar removed support for jsx, so the later
+ ;; grammar versions this function just return nil.
(typescript-ts-mode--check-dialect language)
- (condition-case nil
- (progn (treesit-query-capture language '((jsx_opening_element
(member_expression) @capture)))
- '((jsx_opening_element
- [(member_expression (identifier)) (identifier)]
- @typescript-ts-jsx-tag-face)
-
- (jsx_closing_element
- [(member_expression (identifier)) (identifier)]
- @typescript-ts-jsx-tag-face)
-
- (jsx_self_closing_element
- [(member_expression (identifier)) (identifier)]
- @typescript-ts-jsx-tag-face)))
- (treesit-query-error
- '((jsx_opening_element
- [(nested_identifier (identifier)) (identifier)]
- @typescript-ts-jsx-tag-face)
-
- (jsx_closing_element
- [(nested_identifier (identifier)) (identifier)]
- @typescript-ts-jsx-tag-face)
-
- (jsx_self_closing_element
- [(nested_identifier (identifier)) (identifier)]
- @typescript-ts-jsx-tag-face)))))
+ (let ((queries-a '((jsx_opening_element
+ [(member_expression (identifier)) (identifier)]
+ @typescript-ts-jsx-tag-face)
+
+ (jsx_closing_element
+ [(member_expression (identifier)) (identifier)]
+ @typescript-ts-jsx-tag-face)
+
+ (jsx_self_closing_element
+ [(member_expression (identifier)) (identifier)]
+ @typescript-ts-jsx-tag-face)
+
+ (jsx_attribute (property_identifier)
+ @typescript-ts-jsx-attribute-face)))
+ (queries-b '((jsx_opening_element
+ [(nested_identifier (identifier)) (identifier)]
+ @typescript-ts-jsx-tag-face)
+
+ (jsx_closing_element
+ [(nested_identifier (identifier)) (identifier)]
+ @typescript-ts-jsx-tag-face)
+
+ (jsx_self_closing_element
+ [(nested_identifier (identifier)) (identifier)]
+ @typescript-ts-jsx-tag-face)
+
+ (jsx_attribute (property_identifier)
+ @typescript-ts-jsx-attribute-face))))
+ (or (ignore-errors
+ (treesit-query-compile language queries-a t)
+ queries-a)
+ (ignore-errors
+ (treesit-query-compile language queries-b t)
+ queries-b)
+ ;; Return a dummy query that doens't do anything, if neither
+ ;; query works.
+ '("," @_ignore))))
(defun tsx-ts-mode--font-lock-compatibility-function-expression (language)
"Handle tree-sitter grammar breaking change for `function' expression.
@@ -386,8 +410,7 @@ Argument LANGUAGE is either `typescript' or `tsx'."
:language language
:feature 'jsx
- (append (tsx-ts-mode--font-lock-compatibility-bb1f97b language)
- `((jsx_attribute (property_identifier)
@typescript-ts-jsx-attribute-face)))
+ (tsx-ts-mode--font-lock-compatibility-bb1f97b language)
:language language
:feature 'number
- master updated (dc653bf0636 -> ec3f9434c7d), Yuan Fu, 2024/12/30
- master 9e1e9fdff44 03/10: Refactor treesit-admin--verify-major-mode-queries, Yuan Fu, 2024/12/30
- master c9624c21117 05/10: Add treesit-admin--last-compatible-grammar-for-modes, Yuan Fu, 2024/12/30
- master d9cfe1fe92f 07/10: Add treesit-admin-generate-compatibility-report, Yuan Fu, 2024/12/30
- master a22730f4d78 01/10: Support COMMIT in treesit-language-source-alist, Yuan Fu, 2024/12/30
- master d5ad51f25fb 04/10: Add treesit-admin--find-latest-compatible-revision, Yuan Fu, 2024/12/30
- master e2f79171529 02/10: Refactor treesit--install-language-grammar-1, Yuan Fu, 2024/12/30
- master 0b1986ba524 08/10: Generate compatibility report for multiple Emacs versions, Yuan Fu, 2024/12/30
- master 732a1108b0b 09/10: Add verified grammar version comment for tree-sitter modes, Yuan Fu, 2024/12/30
- master ec3f9434c7d 10/10: Make typescript-ts-mode work with latest grammar,
Yuan Fu <=
- master 5ec170985f4 06/10: ; Move treesit-admin into tree-sitter directory, Yuan Fu, 2024/12/30