Skip to content

Commit 3eec403

Browse files
authored
Merge pull request #168 from Fuco1/fix/multiline-param-list
fix(fontlock): fontify parameters in multiline arglist
2 parents b80ae97 + 218a546 commit 3eec403

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

typescript-mode-general-tests.el

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,70 @@ should be fontified as variable, keyword and type."
593593
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
594594
(should (eq (get-face-at "ClassName") 'font-lock-type-face))))
595595

596+
(ert-deftest font-lock/variables-in-declaration-multiline-with-types ()
597+
"Variables should be highlighted in multiline declarations with types."
598+
(test-with-fontified-buffer
599+
"function test(
600+
var1: Type1,
601+
var2: Type2,
602+
): RetType {\n}"
603+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
604+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))
605+
(should (eq (get-face-at "Type1") 'font-lock-type-face))
606+
(should (eq (get-face-at "Type2") 'font-lock-type-face))))
607+
608+
(ert-deftest font-lock/variables-in-declaration-multiline-without-types ()
609+
"Variables should be highlighted in multiline declarations without types."
610+
(test-with-fontified-buffer
611+
"function test(
612+
var1,
613+
var2,
614+
): RetType {\n}"
615+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
616+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
617+
618+
(ert-deftest font-lock/variables-in-declaration-multiline-no-hanging-paren ()
619+
"Variables should be highlighted in multiline declarations with no hanging paren."
620+
(test-with-fontified-buffer
621+
"function test(
622+
var1,
623+
var2): RetType {\n}"
624+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
625+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
626+
627+
(ert-deftest font-lock/variables-in-declaration-multiline-ending-comma-no-hanging-paren ()
628+
"Variables should be highlighted in multiline declarations with no hanging paren and trailing comma."
629+
(test-with-fontified-buffer
630+
"function test(
631+
var1,
632+
var2,): RetType {\n}"
633+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
634+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
635+
636+
(ert-deftest font-lock/variables-in-declaration-singleline-ending-comma-hanging-paren ()
637+
"Variables should be highlighted in singleline declarations with hanging paren and trailing comma."
638+
(test-with-fontified-buffer
639+
"function test(var1,var2,
640+
): RetType {\n}"
641+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
642+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
643+
644+
(ert-deftest font-lock/variables-in-declaration-singleline-with-types ()
645+
"Variables should be highlighted in singleline declarations with types."
646+
(test-with-fontified-buffer
647+
"function test(var1: Foo, var2: Bar,): RetType {\n}"
648+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
649+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))
650+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
651+
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
652+
653+
(ert-deftest font-lock/variables-in-declaration-singleline-ending-comma-no-hanging-paren ()
654+
"Variables should be highlighted in singleline declarations with no hanging paren and trailing comma."
655+
(test-with-fontified-buffer
656+
"function test(var1,var2,): RetType {\n}"
657+
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
658+
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
659+
596660
(defun flyspell-predicate-test (search-for)
597661
"This function runs a test on
598662
`typescript--flyspell-mode-predicate'. `SEARCH-FOR' is a string

typescript-mode.el

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,23 +1859,12 @@ and searches for the next token to be highlighted."
18591859
,(list
18601860
(concat
18611861
"\\_<function\\_>\\(\\s-+" typescript--name-re "\\)?\\s-*\\(<.*>\\)?\\s-*(\\s-*"
1862-
typescript--name-start-re)
1863-
(list (concat "\\(" typescript--name-re "\\)\\(\\s-*).*\\)?")
1864-
'(backward-char)
1865-
'(end-of-line)
1866-
'(1 font-lock-variable-name-face)))
1867-
1868-
;; continued formal parameter list
1869-
,(list
1870-
(concat
1871-
"^\\s-*" typescript--name-re "\\s-*[,)]")
1872-
(list typescript--name-re
1873-
'(if (save-excursion (backward-char)
1874-
(typescript--inside-param-list-p))
1875-
(forward-symbol -1)
1876-
(end-of-line))
1877-
'(end-of-line)
1878-
'(0 font-lock-variable-name-face))))
1862+
"\\(?:$\\|" typescript--name-start-re "\\)")
1863+
`(,(concat "\\(" typescript--name-re "\\)\\(?:\\s-*?\\([,:)]\\|$\\)\\)")
1864+
(prog1 (save-excursion (re-search-forward ")" nil t))
1865+
(backward-char))
1866+
nil
1867+
(1 font-lock-variable-name-face))))
18791868
"Level three font lock for `typescript-mode'.")
18801869

18811870
(defun typescript--flyspell-mode-predicate ()
@@ -2929,6 +2918,7 @@ Key bindings:
29292918
(setq-local end-of-defun-function 'typescript-end-of-defun)
29302919
(setq-local open-paren-in-column-0-is-defun-start nil)
29312920
(setq-local font-lock-defaults (list typescript--font-lock-keywords))
2921+
(setq-local font-lock-multiline t)
29322922
(setq-local syntax-propertize-function #'typescript-syntax-propertize)
29332923
(setq-local parse-sexp-ignore-comments t)
29342924
(setq-local parse-sexp-lookup-properties t)

0 commit comments

Comments
 (0)