diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el index eac9ed1..13775c7 100644 --- a/typescript-mode-general-tests.el +++ b/typescript-mode-general-tests.el @@ -391,15 +391,15 @@ private async innerExecuteAsync(endpoint: st innerExecuteAsync(x: string, y: boolean, z: number, j?: any): Promise {\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 1c07070..1b2ae11 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