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

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

[nongnu] elpa/typescript-mode 0f41709e15 074/222: Fontify @type properly


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 0f41709e15 074/222: Fontify @type properly and allow jsdoc one-liners.
Date: Sun, 6 Feb 2022 16:59:19 -0500 (EST)

branch: elpa/typescript-mode
commit 0f41709e1525403767bd4889cb913900c68448dd
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>

    Fontify @type properly and allow jsdoc one-liners.
    
    @type was improperly classified as a tag that takes a value rather
    than a type.
    
    Moreover, the regexes for jsdoc fontification did not allow one-liners
    like /** @... */. This is fixed.
---
 typescript-mode-tests.el | 20 ++++++++++++++++++++
 typescript-mode.el       | 23 +++++++++++++++++------
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index 9a4725afc5..9c57a9a098 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -236,6 +236,26 @@ fontified as documentation."
      (should (eq (text-property-not-all loc (point-max) 'face 
font-lock-string-face)
                  (1- (point-max)))))))
 
+(ert-deftest font-lock/immediate-doc ()
+  "Tests that it is not necessary to have the documentation tag on a
+new line after the start of '/**'."
+  (font-lock-test
+   ;; We have 4 comments here because we need to cover the multiple
+   ;; regexes that deal with the different types of jsdoc tags.
+   "/** @type {foo} */\n
+/** @alias bar */\n
+/** @author me */\n
+/** @param meow */"
+   '((1 . font-lock-comment-delimiter-face)
+     ("@type" . typescript-jsdoc-tag)
+     ("{foo}" . typescript-jsdoc-type)
+     ("@alias" . typescript-jsdoc-tag)
+     ("bar" . typescript-jsdoc-value)
+     ("@author" . typescript-jsdoc-tag)
+     ("me" . font-lock-comment-face)
+     ("@param" . typescript-jsdoc-tag)
+     ("meow" . typescript-jsdoc-value))))
+
 (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 ed49358fe8..a2150a7a4c 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -414,6 +414,9 @@ Match group 1 is the name of the macro.")
    :paren-depth most-negative-fixnum
    :type 'toplevel))
 
+;; When we say "jsdoc" here, we mean "jsdoc 3". There exist multiple dialects 
of
+;; "jsdoc documentation".
+
 ;; Note that all typedoc/jsdoc regexp by themselves would match occurrences 
that appear outside
 ;; documentation comments. The logic that uses these regexps must guard 
against it.
 (defconst typescript-typedoc-link-tag-regexp
@@ -424,9 +427,14 @@ Match group 1 is the name of the macro.")
   "\\(`+\\).*?\\1"
   "Matches a typedoc keyword markup.")
 
+(defconst typescript-jsdoc-before-tag-regexp
+  "\\(?:^\\s-*\\*+\\|/\\*\\*\\)\\s-*"
+  "Matches everything we allow before the @ of a jsdoc tag.")
+
 ;; This was taken from js2-mode.
 (defconst typescript-jsdoc-param-tag-regexp
-  (concat "\\(?:^\\s-*\\*+\\|/\\*\\*\\)\\s-*\\(@"
+  (concat typescript-jsdoc-before-tag-regexp
+          "\\(@"
           "\\(?:param\\|arg\\(?:ument\\)?\\|prop\\(?:erty\\)?\\)"
           "\\)"
           "\\s-*\\({[^}]+}\\)?"         ; optional type
@@ -436,7 +444,8 @@ Match group 1 is the name of the macro.")
 
 ;; This was taken from js2-mode.
 (defconst typescript-jsdoc-typed-tag-regexp
-  (concat "^\\s-*\\*+\\s-*\\(@\\(?:"
+  (concat typescript-jsdoc-before-tag-regexp
+          "\\(@\\(?:"
           (regexp-opt
            '("enum"
              "extends"
@@ -449,13 +458,15 @@ Match group 1 is the name of the macro.")
              "return"
              "returns"
              "throw"
-             "throws"))
+             "throws"
+             "type"))
           "\\)\\)\\s-*\\({[^}]+}\\)?")
   "Matches jsdoc tags with optional type.")
 
 ;; This was taken from js2-mode.
 (defconst typescript-jsdoc-arg-tag-regexp
-  (concat "^\\s-*\\*+\\s-*\\(@\\(?:"
+  (concat typescript-jsdoc-before-tag-regexp
+          "\\(@\\(?:"
           (regexp-opt
            '("alias"
              "augments"
@@ -480,14 +491,14 @@ Match group 1 is the name of the macro.")
              "suppress"
              "this"
              "throws"
-             "type"
              "version"))
           "\\)\\)\\s-+\\([^ \t]+\\)")
   "Matches jsdoc tags with a single argument.")
 
 ;; This was taken from js2-mode.
 (defconst typescript-jsdoc-empty-tag-regexp
-  (concat "^\\s-*\\*+\\s-*\\(@\\(?:"
+  (concat typescript-jsdoc-before-tag-regexp
+          "\\(@\\(?:"
           (regexp-opt
            '("addon"
              "author"



reply via email to

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