unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Damien Cassou <damien@cassou.me>, emacs-devel@gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: Re: Adding jsdoc support to js-ts-mode
Date: Sun, 9 Jun 2024 06:02:31 +0300	[thread overview]
Message-ID: <c0e23fa8-277a-4c8b-ab30-ea122012d5b8@gutov.dev> (raw)
In-Reply-To: <871q59w5jm.fsf@cassou.me>

Hi Damien,

On 07/06/2024 10:55, Damien Cassou wrote:
> 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).

I guess you're using the jsdoc tree-sitter grammar in addition to Lisp 
code. The alternative would be pure-regexp matching, but this might be 
easier indeed.

> 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?

You could try adding a custom rule which applies highlights to specific 
ranges. The function to call is treesit-fontify-with-override.

See its usage examples in the tree - most of them still deal with nodes, 
but you just need to pass the character positions, which can be 
calculated in different ways.

> 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)))))

Nice.

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

Seems like this needs ' after #.



  reply	other threads:[~2024-06-09  3:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07  7:55 Adding jsdoc support to js-ts-mode Damien Cassou
2024-06-09  3:02 ` Dmitry Gutov [this message]
2024-06-14 12:39   ` Damien Cassou
2024-06-14 22:48     ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0e23fa8-277a-4c8b-ab30-ea122012d5b8@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=casouri@gmail.com \
    --cc=damien@cassou.me \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).