Skip to content

Commit 769c1f9

Browse files
committed
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.
1 parent 8818e76 commit 769c1f9

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

typescript-mode-general-tests.el

+8-7
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ private async innerExecuteAsync<TResponse extends Response, TValue>(endpoint: st
391391
innerExecuteAsync(x: string, y: boolean, z: number, j?: any): Promise<FResponse> {\n
392392
console.log(this.methodCall());\n
393393
snake_cased_function(1, 2, 3)"
394-
'(("@decorator" . font-lock-function-name-face)
394+
'(("@decorator" . font-lock-function-call-face)
395395
("Foo" . font-lock-type-face)
396396
("private" . typescript-access-modifier-face)
397397
("innerExecuteAsync" . font-lock-function-name-face)
398398
(("TResponse" "FResponse" "Response" "TValue") . font-lock-type-face)
399399
("console" . font-lock-type-face)
400400
("this" . typescript-this-face)
401-
("methodCall" . font-lock-function-name-face)
402-
("snake_cased_function" . font-lock-function-name-face)
401+
("methodCall" . font-lock-function-call-face)
402+
("snake_cased_function" . font-lock-function-call-face)
403403
(("string" "boolean" "number" "any") . typescript-primitive-face)
404404
(("endpoint" "data") . font-lock-variable-name-face)
405405
(("<" ">" ",") . nil))))
@@ -413,9 +413,9 @@ app.post()
413413
app.delete()
414414
if (true) {}
415415
// for (abc) {}"
416-
(should (eq (get-face-at "get") 'font-lock-function-name-face))
417-
(should (eq (get-face-at "post") 'font-lock-function-name-face))
418-
(should (eq (get-face-at "delete") 'font-lock-function-name-face))
416+
(should (eq (get-face-at "get") 'font-lock-function-call-face))
417+
(should (eq (get-face-at "post") 'font-lock-function-call-face))
418+
(should (eq (get-face-at "delete") 'font-lock-function-call-face))
419419
(should (eq (get-face-at "if") 'font-lock-keyword-face))
420420
(should (eq (get-face-at "for") 'font-lock-comment-face))))
421421

@@ -861,7 +861,8 @@ bbb: Bar,
861861

862862
(ert-deftest font-lock/funargs--method--single-line--with-type ()
863863
(test-with-fontified-buffer
864-
"class Foo { foo(aaa: Foo,bbb: Bar,): void {}"
864+
"class Foo { foom(aaa: Foo,bbb: Bar,): void {}"
865+
(should (eq (get-face-at "foom") 'font-lock-function-name-face))
865866
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
866867
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
867868
(should (eq (get-face-at "Foo") 'font-lock-type-face))

typescript-mode.el

+19-3
Original file line numberDiff line numberDiff line change
@@ -2176,10 +2176,10 @@ This performs fontification according to `typescript--class-styles'."
21762176
;;
21772177
,@typescript--font-lock-keywords-3
21782178

2179-
(,typescript--decorator-re (1 font-lock-function-name-face))
2180-
(,typescript--function-call-re (1 font-lock-function-name-face))
2179+
(,typescript--decorator-re (1 'font-lock-function-call-face))
2180+
(,typescript--function-call-re (1 (typescript--function-face)))
21812181
(,(concat "\\(?:\\.\\s-*\\)" typescript--function-call-re)
2182-
(1 font-lock-function-name-face t))
2182+
(1 font-lock-function-call-face t))
21832183
(,typescript--builtin-re (1 font-lock-type-face))
21842184

21852185
;; arrow function
@@ -2192,6 +2192,22 @@ This performs fontification according to `typescript--class-styles'."
21922192
(3 'font-lock-keyword-face t)))
21932193
"Level four font lock for `typescript-mode'.")
21942194

2195+
(defun typescript--function-face ()
2196+
"Return the face to use depending if it's a definition or a call.
2197+
Point is assumed to be right after the open paren."
2198+
(save-excursion
2199+
(forward-char -1)
2200+
(if (condition-case nil
2201+
(progn
2202+
(forward-sexp 1)
2203+
(forward-comment (point-max))
2204+
(memq (char-after) '(?: ?\{)))
2205+
(scan-error nil))
2206+
;; Looks like a declaration/definition.
2207+
'font-lock-function-name-face
2208+
;; Probably just a call.
2209+
'font-lock-function-call-face)))
2210+
21952211
(defconst typescript--font-lock-keywords
21962212
'(typescript--font-lock-keywords-4 typescript--font-lock-keywords-1
21972213
typescript--font-lock-keywords-2

0 commit comments

Comments
 (0)