branch: elpa/typescript-mode
commit a09e9c78f947fc85b243a2743da60b86a1082867
Author: Wilfred Hughes <[email protected]>
Commit: Louis-Dominique Dubeau <[email protected]>
Highlight class names.
---
typescript-mode-tests.el | 22 ++++++++++++++++++++++
typescript-mode.el | 19 +++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index d82956a7eb..656553944d 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -398,6 +398,28 @@ declare function declareFunctionDefn(x3: xty3, y3: yty3):
ret3;"
"=/foo\\\\/g something // comment"
(should (eq (get-face-at "g something") nil))))
+(ert-deftest font-lock/type-names ()
+ "Type names should be highlighted in definitions."
+ ;; Typical case.
+ (test-with-fontified-buffer
+ "export class Foo extends Bar implements Qux {}"
+ (should (eq (get-face-at "Foo") 'font-lock-type-face))
+ (should (eq (get-face-at "Bar") 'font-lock-type-face))
+ (should (eq (get-face-at "Qux") 'font-lock-type-face)))
+ ;; Ensure we require symbol boundaries.
+ (test-with-fontified-buffer
+ "Notclass Foo"
+ (should (not (eq (get-face-at "Foo") 'font-lock-type-face))))
+ ;; Other common ways of defining types.
+ (test-with-fontified-buffer
+ "interface Thing {}"
+ (should (eq (get-face-at "Thing") 'font-lock-type-face)))
+ (test-with-fontified-buffer
+ "enum Thing {}"
+ (should (eq (get-face-at "Thing") 'font-lock-type-face)))
+ (test-with-fontified-buffer
+ "type Thing = number;"
+ (should (eq (get-face-at "Thing") 'font-lock-type-face))))
(defun flyspell-predicate-test (search-for)
"This function runs a test on
diff --git a/typescript-mode.el b/typescript-mode.el
index 380301324d..3d6022dce2 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -55,6 +55,7 @@
(require 'compile)
(require 'cc-mode)
(require 'font-lock)
+ (require 'rx)
(require 'newcomment))
(eval-when-compile
@@ -1777,6 +1778,24 @@ and searches for the next token to be highlighted."
("\\.\\(prototype\\)\\_>"
(1 font-lock-constant-face))
+ (,(rx symbol-start "class" (+ space) (group (+ (or (syntax word) (syntax
symbol)))))
+ (1 font-lock-type-face))
+
+ (,(rx symbol-start "extends" (+ space) (group (+ (or (syntax word) (syntax
symbol)))))
+ (1 font-lock-type-face))
+
+ (,(rx symbol-start "implements" (+ space) (group (+ (or (syntax word)
(syntax symbol)))))
+ (1 font-lock-type-face))
+
+ (,(rx symbol-start "interface" (+ space) (group (+ (or (syntax word)
(syntax symbol)))))
+ (1 font-lock-type-face))
+
+ (,(rx symbol-start "type" (+ space) (group (+ (or (syntax word) (syntax
symbol)))))
+ (1 font-lock-type-face))
+
+ (,(rx symbol-start "enum" (+ space) (group (+ (or (syntax word) (syntax
symbol)))))
+ (1 font-lock-type-face))
+
;; Highlights class being declared, in parts
(typescript--class-decl-matcher
,(concat "\\(" typescript--name-re "\\)\\(?:\\.\\|.*$\\)")