branch: scratch/typescript-mode
commit 769c1f932c6fa7ac32d319d627d01f0c009ba7b8
Author: Stefan Monnier <monn...@iro.umontreal.ca>
Commit: Stefan Monnier <monn...@iro.umontreal.ca>

    Use `font-lock-function-call-face` for calls
    
    * typescript-mode.el (typescript--function-face): New function.
    (typescript--font-lock-keywords-4): Use `font-lock-function-name-face`
    only for definitions, not calls and not decorators.
    
    * typescript-mode-general-tests.el (font-lock/level-four)
    (font-lock/method-call-with-keyword-name): Adjust to new faces.
    (font-lock/funargs--method--single-line--with-type): Also test
    the face of the method definition.
---
 typescript-mode-general-tests.el | 15 ++++++++-------
 typescript-mode.el               | 22 +++++++++++++++++++---
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el
index eac9ed1d02..13775c7bfd 100644
--- a/typescript-mode-general-tests.el
+++ b/typescript-mode-general-tests.el
@@ -391,15 +391,15 @@ private async innerExecuteAsync<TResponse extends 
Response, TValue>(endpoint: st
 innerExecuteAsync(x: string, y: boolean, z: number, j?: any): 
Promise<FResponse> {\n
 console.log(this.methodCall());\n
 snake_cased_function(1, 2, 3)"
-    '(("@decorator" . font-lock-function-name-face)
+    '(("@decorator" . font-lock-function-call-face)
       ("Foo" . font-lock-type-face)
       ("private" . typescript-access-modifier-face)
       ("innerExecuteAsync" . font-lock-function-name-face)
       (("TResponse" "FResponse" "Response" "TValue") . font-lock-type-face)
       ("console" . font-lock-type-face)
       ("this" . typescript-this-face)
-      ("methodCall" . font-lock-function-name-face)
-      ("snake_cased_function" . font-lock-function-name-face)
+      ("methodCall" . font-lock-function-call-face)
+      ("snake_cased_function" . font-lock-function-call-face)
       (("string" "boolean" "number" "any") . typescript-primitive-face)
       (("endpoint" "data") . font-lock-variable-name-face)
       (("<" ">" ",") . nil))))
@@ -413,9 +413,9 @@ app.post()
 app.delete()
 if (true) {}
 // for (abc) {}"
-    (should (eq (get-face-at "get") 'font-lock-function-name-face))
-    (should (eq (get-face-at "post") 'font-lock-function-name-face))
-    (should (eq (get-face-at "delete") 'font-lock-function-name-face))
+    (should (eq (get-face-at "get") 'font-lock-function-call-face))
+    (should (eq (get-face-at "post") 'font-lock-function-call-face))
+    (should (eq (get-face-at "delete") 'font-lock-function-call-face))
     (should (eq (get-face-at "if") 'font-lock-keyword-face))
     (should (eq (get-face-at "for") 'font-lock-comment-face))))
 
@@ -861,7 +861,8 @@ bbb: Bar,
 
 (ert-deftest font-lock/funargs--method--single-line--with-type ()
   (test-with-fontified-buffer
-      "class Foo { foo(aaa: Foo,bbb: Bar,): void {}"
+      "class Foo { foom(aaa: Foo,bbb: Bar,): void {}"
+    (should (eq (get-face-at "foom") 'font-lock-function-name-face))
     (should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
     (should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
     (should (eq (get-face-at "Foo") 'font-lock-type-face))
diff --git a/typescript-mode.el b/typescript-mode.el
index 1c070701c8..1b2ae11bfd 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -2176,10 +2176,10 @@ This performs fontification according to 
`typescript--class-styles'."
     ;;
     ,@typescript--font-lock-keywords-3
 
-    (,typescript--decorator-re (1 font-lock-function-name-face))
-    (,typescript--function-call-re (1 font-lock-function-name-face))
+    (,typescript--decorator-re (1 'font-lock-function-call-face))
+    (,typescript--function-call-re (1 (typescript--function-face)))
     (,(concat "\\(?:\\.\\s-*\\)" typescript--function-call-re)
-     (1 font-lock-function-name-face t))
+     (1 font-lock-function-call-face t))
     (,typescript--builtin-re (1 font-lock-type-face))
 
     ;; arrow function
@@ -2192,6 +2192,22 @@ This performs fontification according to 
`typescript--class-styles'."
      (3 'font-lock-keyword-face t)))
   "Level four font lock for `typescript-mode'.")
 
+(defun typescript--function-face ()
+  "Return the face to use depending if it's a definition or a call.
+Point is assumed to be right after the open paren."
+  (save-excursion
+    (forward-char -1)
+    (if (condition-case nil
+            (progn
+              (forward-sexp 1)
+              (forward-comment (point-max))
+              (memq (char-after) '(?: ?\{)))
+          (scan-error nil))
+        ;; Looks like a declaration/definition.
+        'font-lock-function-name-face
+      ;; Probably just a call.
+      'font-lock-function-call-face)))
+
 (defconst typescript--font-lock-keywords
   '(typescript--font-lock-keywords-4 typescript--font-lock-keywords-1
                                    typescript--font-lock-keywords-2

Reply via email to