Skip to content

Commit a09e9c7

Browse files
Wilfredlddubeau
authored andcommitted
Highlight class names.
1 parent bce2e73 commit a09e9c7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

typescript-mode-tests.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,28 @@ declare function declareFunctionDefn(x3: xty3, y3: yty3): ret3;"
398398
"=/foo\\\\/g something // comment"
399399
(should (eq (get-face-at "g something") nil))))
400400

401+
(ert-deftest font-lock/type-names ()
402+
"Type names should be highlighted in definitions."
403+
;; Typical case.
404+
(test-with-fontified-buffer
405+
"export class Foo extends Bar implements Qux {}"
406+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
407+
(should (eq (get-face-at "Bar") 'font-lock-type-face))
408+
(should (eq (get-face-at "Qux") 'font-lock-type-face)))
409+
;; Ensure we require symbol boundaries.
410+
(test-with-fontified-buffer
411+
"Notclass Foo"
412+
(should (not (eq (get-face-at "Foo") 'font-lock-type-face))))
413+
;; Other common ways of defining types.
414+
(test-with-fontified-buffer
415+
"interface Thing {}"
416+
(should (eq (get-face-at "Thing") 'font-lock-type-face)))
417+
(test-with-fontified-buffer
418+
"enum Thing {}"
419+
(should (eq (get-face-at "Thing") 'font-lock-type-face)))
420+
(test-with-fontified-buffer
421+
"type Thing = number;"
422+
(should (eq (get-face-at "Thing") 'font-lock-type-face))))
401423

402424
(defun flyspell-predicate-test (search-for)
403425
"This function runs a test on

typescript-mode.el

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
(require 'compile)
5656
(require 'cc-mode)
5757
(require 'font-lock)
58+
(require 'rx)
5859
(require 'newcomment))
5960

6061
(eval-when-compile
@@ -1777,6 +1778,24 @@ and searches for the next token to be highlighted."
17771778
("\\.\\(prototype\\)\\_>"
17781779
(1 font-lock-constant-face))
17791780

1781+
(,(rx symbol-start "class" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1782+
(1 font-lock-type-face))
1783+
1784+
(,(rx symbol-start "extends" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1785+
(1 font-lock-type-face))
1786+
1787+
(,(rx symbol-start "implements" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1788+
(1 font-lock-type-face))
1789+
1790+
(,(rx symbol-start "interface" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1791+
(1 font-lock-type-face))
1792+
1793+
(,(rx symbol-start "type" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1794+
(1 font-lock-type-face))
1795+
1796+
(,(rx symbol-start "enum" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1797+
(1 font-lock-type-face))
1798+
17801799
;; Highlights class being declared, in parts
17811800
(typescript--class-decl-matcher
17821801
,(concat "\\(" typescript--name-re "\\)\\(?:\\.\\|.*$\\)")

0 commit comments

Comments
 (0)