HiPhish / rainbow-delimiters.nvim

Rainbow delimiters for Neovim with Tree-sitter
https://gitlab.com/HiPhish/rainbow-delimiters.nvim
Apache License 2.0
532 stars 39 forks source link

[Enhancement]: Support jsdoc types for javascript/typescript #96

Open GNRSN opened 8 months ago

GNRSN commented 8 months ago

Language affected

Javascript

Description

The jsdoc format for javascript supports adding types, including writing typescript inside the comment which can be used by the typescript compiler to typecheck js code. Since rainbow-delimiters works for both js and ts already, it would be awesome if it applied in jsdoc as well.

Example comparison with vscode:

Neovim:

Screenshot 2024-02-04 at 17 53 21

Vscode:

Screenshot 2024-02-04 at 17 57 49
HiPhish commented 7 months ago

I don't think I can do anything here because the parser does not provide any useful information. Let's take this piece of Javascript code:

/**
 * A function with delimiters in type comments
 *
 * @param {{id: string, friends: {id: string}[]}} data
 */
const greet_person = ({id, friends}) => {
    return id
}

Here is the syntax tree of the entire comment:

(comment ; [51:1 - 55:3]
  (description) ; [52:4 - 46]
  (tag ; [54:4 - 54]
    (tag_name) ; [54:4 - 9]
    "{" ; [54:11 - 11]
    (type) ; [54:12 - 48]
    "}" ; [54:49 - 49]
    (identifier))) ; [54:51 - 54]

As you can see everything inside the { and } is one single node, there is no structured information. This plugin relies on Tree-sitter to provide structure information, but I don't have anything to work with here.