[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode c1aa1b2e7d 149/222: add better generics hi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode c1aa1b2e7d 149/222: add better generics highlighting |
Date: |
Sun, 6 Feb 2022 16:59:28 -0500 (EST) |
branch: elpa/typescript-mode
commit c1aa1b2e7da0fb74803287d08b5d062e1cb66b17
Author: tam5 <arimiller92@gmail.com>
Commit: tam5 <arimiller92@gmail.com>
add better generics highlighting
---
typescript-mode-general-tests.el | 30 ++++++++++++++++++++++++++++++
typescript-mode.el | 23 ++++++++++-------------
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el
index 6bbb5609bf..7185a3643a 100644
--- a/typescript-mode-general-tests.el
+++ b/typescript-mode-general-tests.el
@@ -319,6 +319,36 @@ declare function declareFunctionDefn(x3: xty3, y3: yty3):
ret3;"
(("y0" "y1" "y2" "y3") . font-lock-variable-name-face)
(("ret0" "ret1" "ret2" "ret3") . nil))))
+(ert-deftest font-lock/level-four ()
+ "Tests the level four font lock highlights."
+ (font-lock-test
+ "@decorator\n
+class Foo<T> extends Bar {\n
+private async innerExecuteAsync<TResponse extends Response, TValue>(endpoint:
string, data?: any): Promise<TResponse> {\n
+innerExecuteAsync(x: string, y: boolean, z: number, j?: any):
Promise<FResponse> {\n
+console.log(this.methodCall())"
+ '(("@decorator" . font-lock-function-name-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)
+ (("string" "boolean" "number" "any") . typescript-primitive-face)
+ (("endpoint" "data") . nil)
+ (("<" ">" ",") . nil))))
+
+(ert-deftest font-lock/generics ()
+ "Tests that type hints within generics are highlighted properly."
+ (font-lock-test
+ "const map = new Map<string, number>()\n
+function foo<Z, Y, Z & Y, Z | Y | Z, Y<X<X, Y>>>()\n"
+ '((("string" "number") . typescript-primitive-face)
+ ("foo" . font-lock-function-name-face)
+ (("Z" "Y" "X") . font-lock-type-face)
+ (("<" ">" "," "&" "|") . nil))))
+
(ert-deftest font-lock/regexp ()
"Regular expresssions should be fontified as string constant."
(let ((content "=/foo/ (/bar/ ,/baz/ :/buzz/"))
diff --git a/typescript-mode.el b/typescript-mode.el
index 4a91d5f313..66c45bd544 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -283,14 +283,6 @@ Match group 1 is MUMBLE.")
'("private" "protected" "public" "readonly" "static" "extends"
"implements"))
"Regular expression matching access modifiers.")
-(defconst typescript--generic-type-re
- "<\\(.*\\)>"
- "Regular expression matching generic types.")
-
-(defconst typescript--generic-type-extended-re
- (concat "<\\(.*\\)extends\\(.*\\)>")
- "Regular expression matching generic types with extension.")
-
(defconst typescript--decorator-re
(concat "\\(@" typescript--name-re "\\)"))
@@ -1878,7 +1870,7 @@ and searches for the next token to be highlighted."
;; formal parameters
,(list
(concat
- "\\_<function\\_>\\(\\s-+" typescript--name-re "\\)?\\s-*(\\s-*"
+ "\\_<function\\_>\\(\\s-+" typescript--name-re
"\\)?\\s-*\\(<.*>\\)?\\s-*(\\s-*"
typescript--name-start-re)
(list (concat "\\(" typescript--name-re "\\)\\(\\s-*).*\\)?")
'(backward-char)
@@ -1982,7 +1974,7 @@ context."
(when (called-interactively-p 'interactive)
(message "Syntactic context: %s" syntactic-context))
- syntactic-context))
+ syntactic-context))
(defun typescript--class-decl-matcher (limit)
"Font lock function used by `typescript-mode'.
@@ -2016,6 +2008,14 @@ This performs fontification according to
`typescript--class-styles'."
(,typescript--access-modifier-re (1 'typescript-access-modifier-face))
(,typescript--basic-type-re (1 'typescript-primitive-face))
+ ;; generics support
+ ,(list
+ (concat "<\\s-*" typescript--name-start-re)
+ (list (concat "\\(" typescript--name-re "\\)\\(\\s-*>[^<]*\\)?")
+ '(backward-char)
+ '(end-of-line)
+ '(1 font-lock-type-face)))
+
;; highlights that append to previous levels
;;
,@typescript--font-lock-keywords-3
@@ -2024,9 +2024,6 @@ This performs fontification according to
`typescript--class-styles'."
(,typescript--function-call-re (1 font-lock-function-name-face))
(,typescript--builtin-re (1 font-lock-type-face))
- (,typescript--generic-type-re (1 font-lock-type-face))
- (,typescript--generic-type-extended-re (1 font-lock-type-face))
-
;; arrow function
("\\(=>\\)"
(1 font-lock-keyword-face))
- [nongnu] elpa/typescript-mode 1cea84486f 064/222: Merge pull request #35 from lddubeau/feature/indent-return-annotations, (continued)
- [nongnu] elpa/typescript-mode 1cea84486f 064/222: Merge pull request #35 from lddubeau/feature/indent-return-annotations, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 9ad892fb22 061/222: Add keyword 'object', ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e3d2fee6de 004/222: unnecessary for single package file, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7e8b9641ae 096/222: Mark typescript indent variables as safe for file local customizations, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 813cf4fef3 069/222: Fix endless loop (hang) in indentation-code., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode cebfe5952b 114/222: Rename the regexp matching pretty error messages., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5d5c611e2d 119/222: Add tags in js2-mode, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e608305ade 137/222: checkdoc fixes, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 85504ce34b 138/222: Update build-badge URL., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f6330f420e 144/222: Add a test for #107., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode c1aa1b2e7d 149/222: add better generics highlighting,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode 1bafd279cf 148/222: Enable more colors (#110), ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 607897d583 151/222: Update Emacs Git to Xenial-build, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 42b366e669 153/222: Merge pull request #111 from tam5/master, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2405090403 152/222: Handle CI-failures correctly., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 895cd7f425 173/222: Fix indentation infinite looping, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 9db704ec1f 185/222: Fix duplicate test name, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 4832652496 163/222: Support electric-layout-mode., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 710f5425a4 189/222: Add tests for typescript-indent-list-items option, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1fd835e7f8 205/222: Fix typos in README, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 30391a518a 079/222: Fix indentation issue with conditional operators., ELPA Syncer, 2022/02/06