]> git.eshelyaron.com Git - emacs.git/commitdiff
Fontificatiomn improvements for typescrip-ts-mode.el (bug#78594)
authorJostein Kjønigsen <jostein@kjonigsen.net>
Fri, 7 Mar 2025 13:39:11 +0000 (14:39 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 7 Jun 2025 19:59:29 +0000 (21:59 +0200)
- Fontify type-names for static function calls directly on types.
- Special-case "document" and "console" and constants/builtins.
- Fontify variable-use in string-interpolation expressions.
- Fontify variable-use in function-calls.
- Fontify variable-use in member-access expressions.
- Fontify variable-use in JSX-expressions.
- Fontify variable-use when using explicit nullability override.

* lisp/progmodes/typescript-ts-mode.el:
(tsx-ts-mode--font-lock-compatibility-bb1f97b):
(typescript-ts-mode--font-lock-settings): Improve font-lock settings.

(cherry picked from commit c3f4e6ca0e379bf082b1262ff5d4c07a79a434f7)

lisp/progmodes/typescript-ts-mode.el

index 19cbbdf8d61f387bcf2f441a24bcbd12a0d78c79..eafaad876bd9542e4bdac30276d7ec55a5791526 100644 (file)
@@ -254,7 +254,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
                      @typescript-ts-jsx-tag-face)
 
                      (jsx_attribute (property_identifier)
-                                    @typescript-ts-jsx-attribute-face)))
+                                    @typescript-ts-jsx-attribute-face)
+
+                     (jsx_expression (identifier)
+                                     @font-lock-variable-use-face)))
         (queries-b '((jsx_opening_element
                      [(nested_identifier (identifier)) (identifier)]
                      @typescript-ts-jsx-tag-face)
@@ -268,7 +271,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
                      @typescript-ts-jsx-tag-face)
 
                      (jsx_attribute (property_identifier)
-                                    @typescript-ts-jsx-attribute-face))))
+                                    @typescript-ts-jsx-attribute-face)
+
+                     (jsx_expression (identifier)
+                                     @font-lock-variable-use-face))))
     (or (and (treesit-query-valid-p language queries-a)
              queries-a)
         (and (treesit-query-valid-p language queries-b)
@@ -305,6 +311,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
      :feature 'constant
      `(((identifier) @font-lock-constant-face
         (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
+       ((identifier) @font-lock-constant-face
+        (:equal "document" @font-lock-constant-face))
+       ((identifier) @font-lock-constant-face
+        (:equal "console" @font-lock-constant-face))
        [(true) (false) (null) (undefined)] @font-lock-constant-face)
 
      :language language
@@ -404,7 +414,28 @@ Argument LANGUAGE is either `typescript' or `tsx'."
         parameters:
         [(_ (identifier) @font-lock-variable-name-face)
          (_ (_ (identifier) @font-lock-variable-name-face))
-         (_ (_ (_ (identifier) @font-lock-variable-name-face)))]))
+         (_ (_ (_ (identifier) @font-lock-variable-name-face)))])
+
+       (template_substitution (identifier) @font-lock-variable-use-face)
+
+       (call_expression
+        arguments: (arguments (identifier) @font-lock-variable-use-face))
+
+       (pair
+        value: (identifier) @font-lock-variable-use-face)
+
+       ;; What is being called could be a static Type (convention
+       ;; CamelCase, leading caps).
+       ((member_expression
+         object: (identifier) @font-lock-type-face)
+        (:match "\\`[A-Z_][0-9A-Za-z_]*\\'" @font-lock-type-face))
+       ;; If not, assume what is being called is a instance-value
+       ;; and in that it's a variable. Properties are less used in
+       ;; javascript/typescript)
+       (member_expression
+        object: (identifier) @font-lock-variable-use-face)
+
+       (non_null_expression (identifier) @font-lock-variable-use-face))
 
      :language language
      :feature 'property