[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 1767de1095 180/222: Merge pull request #12
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 1767de1095 180/222: Merge pull request #129 from emacs-typescript/feature/types-in-declarations |
Date: |
Sun, 6 Feb 2022 16:59:30 -0500 (EST) |
branch: elpa/typescript-mode
commit 1767de109515a992b965d275cb5550d336d957df
Merge: bc37bc4b15 e38492f1cd
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: GitHub <noreply@github.com>
Merge pull request #129 from emacs-typescript/feature/types-in-declarations
Add syntax-highlighting for types in variable-declarations
---
typescript-mode-general-tests.el | 74 ++++++++++++++++++++++++++++++++++++++++
typescript-mode.el | 22 ++++++++++++
2 files changed, 96 insertions(+)
diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el
index 368a7d5719..6e3f098aa7 100644
--- a/typescript-mode-general-tests.el
+++ b/typescript-mode-general-tests.el
@@ -464,6 +464,80 @@ function foo<Z, Y, Z & Y, Z | Y | Z, Y<X<X, Y>>>()\n"
"type Thing = number;"
(should (eq (get-face-at "Thing") 'font-lock-type-face))))
+(ert-deftest font-lock/type-names-level4 ()
+ "Typenames should be highlighted in declarations"
+
+ (test-with-fontified-buffer
+ "function test(var1: Type1, var2: Type2): RetType {\n}"
+ (should (not (eq (get-face-at "var1") 'font-lock-type-face)))
+ (should (eq (get-face-at "Type1") 'font-lock-type-face))
+ (should (not (eq (get-face-at "var2") 'font-lock-type-face)))
+ (should (eq (get-face-at "Type2") 'font-lock-type-face))
+ (should (eq (get-face-at "RetType") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "class foo { test(var1: Type1, var2: Type2): RetType {\n} }"
+ (should (not (eq (get-face-at "var1") 'font-lock-type-face)))
+ (should (eq (get-face-at "Type1") 'font-lock-type-face))
+ (should (not (eq (get-face-at "var2") 'font-lock-type-face)))
+ (should (eq (get-face-at "Type2") 'font-lock-type-face))
+ (should (eq (get-face-at "RetType") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "let a: SomeType;"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face)))
+ (test-with-fontified-buffer
+ "private b: SomeType;"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face)))
+ (test-with-fontified-buffer
+ "private someArray: SomeType[];"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face)))
+ (test-with-fontified-buffer
+ "private generic: SomeType<Foo>;"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face))
+ (should (eq (get-face-at "Foo") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "private genericArray: SomeType<Foo>[];"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face))
+ (should (eq (get-face-at "Foo") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "private genericArray2: SomeType<Foo[]>;"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face))
+ (should (eq (get-face-at "Foo") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "private genericArray3: SomeType<Foo[]>[];"
+ (should (eq (get-face-at "SomeType") 'font-lock-type-face))
+ (should (eq (get-face-at "Foo") 'font-lock-type-face))))
+
+(ert-deftest font-lock/type-names-level4-namespaces ()
+ "Namespaced Typenames should be highlighted in declarations"
+ (test-with-fontified-buffer
+ "private b: Namespaced.ClassName;"
+ (should (eq (get-face-at "Namespaced") 'font-lock-type-face))
+ (should (eq (get-face-at "ClassName") 'font-lock-type-face)))
+ (test-with-fontified-buffer
+ "function test(var1: Namespaced.ClassName): RetType {\n}"
+ (should (eq (get-face-at "Namespaced") 'font-lock-type-face))
+ (should (eq (get-face-at "ClassName") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "class Foo { test(var1: Namespaced.ClassName): RetType {\n}"
+ (should (eq (get-face-at "Namespaced") 'font-lock-type-face))
+ (should (eq (get-face-at "ClassName") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "function test(var1: Type): Namespaced.ClassName {\n}"
+ (should (eq (get-face-at "Namespaced") 'font-lock-type-face))
+ (should (eq (get-face-at "ClassName") 'font-lock-type-face)))
+
+ (test-with-fontified-buffer
+ "class Foo { test(var1: Type): Namespaced.ClassName {\n}"
+ (should (eq (get-face-at "Namespaced") 'font-lock-type-face))
+ (should (eq (get-face-at "ClassName") 'font-lock-type-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 e0d4f841af..82ae817610 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -63,6 +63,9 @@
;;; Constants
+(defconst typescript--type-name-re
"\\(?:[A-Z][A-Za-z0-9]+\\.\\)\\{0,\\}\\(?:[A-Z][A-Za-z0-9]+\\)"
+ "Regexp matching a conventional TypeScript type-name. Must start with
upper-case letter!")
+
(defconst typescript--name-start-re "[a-zA-Z_$]"
"Regexp matching the start of a typescript identifier, without grouping.")
@@ -1997,6 +2000,25 @@ This performs fontification according to
`typescript--class-styles'."
'(end-of-line)
'(1 font-lock-type-face)))
+ ;; type-highlighting in variable/parameter declarations
+ ;; supports a small variety of common declarations:
+ ;; - let a: SomeType;
+ ;; - private b: SomeType;
+ ;; - private someFunc(var: SomeType) {
+ ;; - private array: SomeType[]
+ ;; - private generic: SomeType<Foo>
+ ;; - private genericArray: SomeType<Foo>[]
+ ;; - function testFunc(): SomeType<> {
+ ;; TODO: namespaced classes!
+ ,(list
+ (concat ":\\s-\\(" typescript--type-name-re "\\)\\(<"
typescript--type-name-re ">\\)?\\(\[\]\\)?\\([,;]\\)?\\s-*{?")
+ '(1 'font-lock-type-face))
+
+ ;; type-casts
+ ,(list
+ (concat "<\\(" typescript--type-name-re "\\)>")
+ '(1 'font-lock-type-face))
+
;; highlights that append to previous levels
;;
,@typescript--font-lock-keywords-3
- [nongnu] elpa/typescript-mode 30f8b8feb4 122/222: Merge pull request #87 from Ailrun/add-jsdoc-tags, (continued)
- [nongnu] elpa/typescript-mode 30f8b8feb4 122/222: Merge pull request #87 from Ailrun/add-jsdoc-tags, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 29282a32b7 124/222: add never type, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 8910e12525 129/222: Add autoload cookie with safe-local-var for typescript-indent-level, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode fbaad515c9 132/222: Merge pull request #89 from Ailrun/update-jsdoc-tests, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 32146510b8 147/222: Pin our dist to Trusty., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 706f938aef 155/222: force generic regex to include symbol before it (#119), ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e38492f1cd 179/222: Extend Type-name to support namespace-prefixes., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7040961735 166/222: Highlight type-names in type-casts too., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode de1a696c3c 174/222: Ignore errors from backward-list, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a7cd7a92a5 167/222: fix(font-lock): prefer fontifying constants over keywords, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1767de1095 180/222: Merge pull request #129 from emacs-typescript/feature/types-in-declarations,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode 0d5c941c4c 195/222: * typescript-mode.el: Use EOS instead of EOL for auto mode regexp., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7d80174b23 216/222: Skip past ? and ! in typescript--compute-member-expression-indent, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 6918f3f6d7 212/222: Merge pull request #154 from emacs-typescript/feature/build-tasks, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 13e6da6c57 219/222: Merge pull request #157 from rsimoes/patch-1, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a6e0eac105 029/222: Fix wrong cursor position in `typescript-indent-line`, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 0f41709e15 074/222: Fontify @type properly and allow jsdoc one-liners., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 90d9758cfb 035/222: Revert "Fix wrong cursor position in `typescript-indent-line`", ELPA Syncer, 2022/02/06
- [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