emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/typescript-mode 218a5462c7 1/2: fix(fontlock): fontify par


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 218a5462c7 1/2: fix(fontlock): fontify parameters in multiline arglist
Date: Tue, 5 Jul 2022 17:59:02 -0400 (EDT)

branch: elpa/typescript-mode
commit 218a5462c7b2a871d16ad94901676465bfc27892
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>

    fix(fontlock): fontify parameters in multiline arglist
---
 typescript-mode-general-tests.el | 64 ++++++++++++++++++++++++++++++++++++++++
 typescript-mode.el               | 24 +++++----------
 2 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el
index 62c4847205..9c1102b915 100644
--- a/typescript-mode-general-tests.el
+++ b/typescript-mode-general-tests.el
@@ -593,6 +593,70 @@ should be fontified as variable, keyword and type."
     (should (eq (get-face-at "Namespaced") 'font-lock-type-face))
     (should (eq (get-face-at "ClassName") 'font-lock-type-face))))
 
+(ert-deftest font-lock/variables-in-declaration-multiline-with-types ()
+  "Variables should be highlighted in multiline declarations with types."
+  (test-with-fontified-buffer
+      "function test(
+var1: Type1,
+var2: Type2,
+): RetType {\n}"
+    (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+    (should (eq (get-face-at "var2") 'font-lock-variable-name-face))
+    (should (eq (get-face-at "Type1") 'font-lock-type-face))
+    (should (eq (get-face-at "Type2") 'font-lock-type-face))))
+
+(ert-deftest font-lock/variables-in-declaration-multiline-without-types ()
+  "Variables should be highlighted in multiline declarations without types."
+  (test-with-fontified-buffer
+      "function test(
+var1,
+var2,
+): RetType {\n}"
+    (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+    (should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
+
+(ert-deftest font-lock/variables-in-declaration-multiline-no-hanging-paren ()
+  "Variables should be highlighted in multiline declarations with no hanging 
paren."
+  (test-with-fontified-buffer
+   "function test(
+var1,
+var2): RetType {\n}"
+   (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+   (should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
+
+(ert-deftest 
font-lock/variables-in-declaration-multiline-ending-comma-no-hanging-paren ()
+  "Variables should be highlighted in multiline declarations with no hanging 
paren and trailing comma."
+  (test-with-fontified-buffer
+   "function test(
+var1,
+var2,): RetType {\n}"
+   (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+   (should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
+
+(ert-deftest 
font-lock/variables-in-declaration-singleline-ending-comma-hanging-paren ()
+  "Variables should be highlighted in singleline declarations with hanging 
paren and trailing comma."
+  (test-with-fontified-buffer
+      "function test(var1,var2,
+): RetType {\n}"
+   (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+   (should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
+
+(ert-deftest font-lock/variables-in-declaration-singleline-with-types ()
+  "Variables should be highlighted in singleline declarations with types."
+  (test-with-fontified-buffer
+      "function test(var1: Foo, var2: Bar,): RetType {\n}"
+   (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+   (should (eq (get-face-at "var2") 'font-lock-variable-name-face))
+   (should (eq (get-face-at "Foo") 'font-lock-type-face))
+   (should (eq (get-face-at "Bar") 'font-lock-type-face))))
+
+(ert-deftest 
font-lock/variables-in-declaration-singleline-ending-comma-no-hanging-paren ()
+  "Variables should be highlighted in singleline declarations with no hanging 
paren and trailing comma."
+  (test-with-fontified-buffer
+   "function test(var1,var2,): RetType {\n}"
+   (should (eq (get-face-at "var1") 'font-lock-variable-name-face))
+   (should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
+
 (defun flyspell-predicate-test (search-for)
   "This function runs a test on
 `typescript--flyspell-mode-predicate'.  `SEARCH-FOR' is a string
diff --git a/typescript-mode.el b/typescript-mode.el
index 2037bfd9bb..268df97395 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1859,23 +1859,12 @@ and searches for the next token to be highlighted."
     ,(list
       (concat
        "\\_<function\\_>\\(\\s-+" typescript--name-re 
"\\)?\\s-*\\(<.*>\\)?\\s-*(\\s-*"
-       typescript--name-start-re)
-      (list (concat "\\(" typescript--name-re "\\)\\(\\s-*).*\\)?")
-            '(backward-char)
-            '(end-of-line)
-            '(1 font-lock-variable-name-face)))
-
-    ;; continued formal parameter list
-    ,(list
-      (concat
-       "^\\s-*" typescript--name-re "\\s-*[,)]")
-      (list typescript--name-re
-            '(if (save-excursion (backward-char)
-                                 (typescript--inside-param-list-p))
-                 (forward-symbol -1)
-               (end-of-line))
-            '(end-of-line)
-            '(0 font-lock-variable-name-face))))
+       "\\(?:$\\|" typescript--name-start-re "\\)")
+      `(,(concat "\\(" typescript--name-re "\\)\\(?:\\s-*?\\([,:)]\\|$\\)\\)")
+        (prog1 (save-excursion (re-search-forward ")" nil t))
+          (backward-char))
+        nil
+        (1 font-lock-variable-name-face))))
   "Level three font lock for `typescript-mode'.")
 
 (defun typescript--flyspell-mode-predicate ()
@@ -2929,6 +2918,7 @@ Key bindings:
   (setq-local end-of-defun-function 'typescript-end-of-defun)
   (setq-local open-paren-in-column-0-is-defun-start nil)
   (setq-local font-lock-defaults (list typescript--font-lock-keywords))
+  (setq-local font-lock-multiline t)
   (setq-local syntax-propertize-function #'typescript-syntax-propertize)
   (setq-local parse-sexp-ignore-comments t)
   (setq-local parse-sexp-lookup-properties t)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]