unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Adding jsdoc support to js-ts-mode
@ 2024-06-07  7:55 Damien Cassou
  2024-06-09  3:02 ` Dmitry Gutov
  0 siblings, 1 reply; 4+ messages in thread
From: Damien Cassou @ 2024-06-07  7:55 UTC (permalink / raw)
  To: emacs-devel; +Cc: Dmitry Gutov, Yuan Fu

[-- Attachment #1: Type: text/plain, Size: 2335 bytes --]

Hi,

Currently, jsdoc comments are not recognized in js-ts-mode (see
before.png screenshot attached). I'm trying to fix that (see current
status in after.png).

As you can see in the after.png screenshot, there is no face applied to
the comment markup "/*" and "*". I would like to see
`font-lock-comment-face` applied. I haven't written any code to do that
because I don't know how to apply a face to characters that are not
treesit nodes. Can someone please help?

The code to get after.png is below. If you have any feedback, that would
be greatly appreciated. When everything is fine, I will submit a patch.

Please make sure I'm on CC when replying as I'm not subscribed to the
mailing list.

  (defun js-ts-language-at-point (point)
        "Return the language at POINT."
        (let ((node (treesit-node-at point 'javascript)))
          (if (and (treesit-ready-p 'jsdoc)
                   (equal (treesit-node-type node) "comment")
                   (string-match-p
                    (rx bos "/**")
                    (treesit-node-text node)))
              'jsdoc
            'javascript)))


To be added to js-ts-mode body:

  (setq treesit-range-settings
        (treesit-range-rules
         :embed 'jsdoc
         :host 'javascript
         `(((comment) @capture (:match ,(rx bos "/**") @capture)))))

  (setq-local treesit-language-at-point-function #js-ts-language-at-point)

Some new rules for `treesit-font-lock-settings':

  (treesit-font-lock-rules
              :language 'jsdoc
              :override t
              :feature 'keyword
              '((tag_name) @font-lock-keyword-face)

              :language 'jsdoc
              :override t
              :feature 'bracket
              '((["{" "}"]) @font-lock-bracket-face)

              :language 'jsdoc
              :override t
              :feature 'property
              '((type) @font-lock-variable-use-face)

              :language 'jsdoc
              :override t
              :feature 'definition
              '((identifier) @font-lock-variable-name-face)

              :language 'jsdoc
              :override t
              :feature 'comment
              '((description) @font-lock-comment-face))

Best

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill

[-- Attachment #2: after.png --]
[-- Type: image/png, Size: 23654 bytes --]

[-- Attachment #3: before.png --]
[-- Type: image/png, Size: 22739 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-14 22:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-07  7:55 Adding jsdoc support to js-ts-mode Damien Cassou
2024-06-09  3:02 ` Dmitry Gutov
2024-06-14 12:39   ` Damien Cassou
2024-06-14 22:48     ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).