zed icon indicating copy to clipboard operation
zed copied to clipboard

Support dart doc comment highlight

Open d1y opened this issue 1 year ago • 1 comments

Check for existing issues

  • [X] Completed

Describe the feature

Docs: https://dart.dev/effective-dart/documentation#doc-comments

It seems a markdown: https://dart.dev/effective-dart/documentation#markdown

Zed:

image

VScode:

image

If applicable, add mockups / screenshots to help present your vision of the feature

No response

d1y avatar May 03 '24 08:05 d1y

Upstream It looks like there are two externals export:

  • _block_comment
  • _documentation_block_comment

https://github.com/UserNobody14/tree-sitter-dart/blob/ac0bb849ccd1a923963af47573b5e396736ff582/grammar.js#L2817-L2832

(((documentation_comment) @_documentation_block_comment
  (#match? @_documentation_block_comment "^///\\s*\\S+")) @content
  (#set! "language" "markdown"))

(((documentation_comment) @_block_comment
  (#match? @_block_comment "^/\\*\\*\\s*\\S+\\s*\\*/")) @content
  (#set! "language" "markdown"))

Work?

image

This will hand over all the text to Markdown

- xx
* xxx
/// - xxx <!-- prefix /// need remove? -->
/// [xxxx]
image

~~So. let's expose these two upstream?~~

  • https://github.com/UserNobody14/tree-sitter-dart/blob/ac0bb849ccd1a923963af47573b5e396736ff582/grammar.js#L2822
  • https://github.com/UserNobody14/tree-sitter-dart/blob/ac0bb849ccd1a923963af47573b5e396736ff582/grammar.js#L2830

~~I am really not familiar with tree sitter, and I would like to know if it is possible to use regex in injections.scm?@maxbrunsfeld~~

Like this:

; TODO: impl this?
(((documentation_comment) @_documentation_block_comment
  (#match? @_documentation_block_comment "^///\\s*(\\S+)\\s*$")) #group(1) @content ; get match group in `\\S+`
  (#set! "language" "markdown"))

Note: I know Neovim seems to have a #offset directive

https://github.com/tree-sitter/tree-sitter/issues/1944#issuecomment-1302459754

d1y avatar May 03 '24 09:05 d1y