aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJostein Kjønigsen2025-03-07 14:39:11 +0100
committerYuan Fu2025-06-01 15:46:36 -0700
commitc3f4e6ca0e379bf082b1262ff5d4c07a79a434f7 (patch)
tree2fcfad553a397dd87fe2a11e37b937ad65427dde
parentdfd57f350a0cca1942c194685d3eb9fe7291ea4d (diff)
downloademacs-c3f4e6ca0e379bf082b1262ff5d4c07a79a434f7.tar.gz
emacs-c3f4e6ca0e379bf082b1262ff5d4c07a79a434f7.zip
Fontificatiomn improvements for typescrip-ts-mode.el (bug#78594)
- 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.
-rw-r--r--lisp/progmodes/typescript-ts-mode.el37
1 files changed, 34 insertions, 3 deletions
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 6f807c254bd..3c784d2b833 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -254,7 +254,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
254 @typescript-ts-jsx-tag-face) 254 @typescript-ts-jsx-tag-face)
255 255
256 (jsx_attribute (property_identifier) 256 (jsx_attribute (property_identifier)
257 @typescript-ts-jsx-attribute-face))) 257 @typescript-ts-jsx-attribute-face)
258
259 (jsx_expression (identifier)
260 @font-lock-variable-use-face)))
258 (queries-b '((jsx_opening_element 261 (queries-b '((jsx_opening_element
259 [(nested_identifier (identifier)) (identifier)] 262 [(nested_identifier (identifier)) (identifier)]
260 @typescript-ts-jsx-tag-face) 263 @typescript-ts-jsx-tag-face)
@@ -268,7 +271,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
268 @typescript-ts-jsx-tag-face) 271 @typescript-ts-jsx-tag-face)
269 272
270 (jsx_attribute (property_identifier) 273 (jsx_attribute (property_identifier)
271 @typescript-ts-jsx-attribute-face)))) 274 @typescript-ts-jsx-attribute-face)
275
276 (jsx_expression (identifier)
277 @font-lock-variable-use-face))))
272 (or (and (treesit-query-valid-p language queries-a) 278 (or (and (treesit-query-valid-p language queries-a)
273 queries-a) 279 queries-a)
274 (and (treesit-query-valid-p language queries-b) 280 (and (treesit-query-valid-p language queries-b)
@@ -305,6 +311,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
305 :feature 'constant 311 :feature 'constant
306 `(((identifier) @font-lock-constant-face 312 `(((identifier) @font-lock-constant-face
307 (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face)) 313 (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
314 ((identifier) @font-lock-constant-face
315 (:equal "document" @font-lock-constant-face))
316 ((identifier) @font-lock-constant-face
317 (:equal "console" @font-lock-constant-face))
308 [(true) (false) (null) (undefined)] @font-lock-constant-face) 318 [(true) (false) (null) (undefined)] @font-lock-constant-face)
309 319
310 :language language 320 :language language
@@ -404,7 +414,28 @@ Argument LANGUAGE is either `typescript' or `tsx'."
404 parameters: 414 parameters:
405 [(_ (identifier) @font-lock-variable-name-face) 415 [(_ (identifier) @font-lock-variable-name-face)
406 (_ (_ (identifier) @font-lock-variable-name-face)) 416 (_ (_ (identifier) @font-lock-variable-name-face))
407 (_ (_ (_ (identifier) @font-lock-variable-name-face)))])) 417 (_ (_ (_ (identifier) @font-lock-variable-name-face)))])
418
419 (template_substitution (identifier) @font-lock-variable-use-face)
420
421 (call_expression
422 arguments: (arguments (identifier) @font-lock-variable-use-face))
423
424 (pair
425 value: (identifier) @font-lock-variable-use-face)
426
427 ;; What is being called could be a static Type (convention
428 ;; CamelCase, leading caps).
429 ((member_expression
430 object: (identifier) @font-lock-type-face)
431 (:match "\\`[A-Z_][0-9A-Za-z_]*\\'" @font-lock-type-face))
432 ;; If not, assume what is being called is a instance-value
433 ;; and in that it's a variable. Properties are less used in
434 ;; javascript/typescript)
435 (member_expression
436 object: (identifier) @font-lock-variable-use-face)
437
438 (non_null_expression (identifier) @font-lock-variable-use-face))
408 439
409 :language language 440 :language language
410 :feature 'property 441 :feature 'property