-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds missing tree-sitter-comment injection for js/ts #2763
adds missing tree-sitter-comment injection for js/ts #2763
Conversation
@the-mikedavis you are right, it is unstable and flip flops around while changing the document. i do consistently get the correct highlighting on first load tough. 😟 it seems to work as expected in neovim. i'll have a closer look. |
You probably want to inject the comment grammar into the jsdoc grammar? |
I am not sure how. The jsdoc injection is already attached to the (comment) node. How would i capture the root node of jsdoc then, to inject the comment parser there? Doing this for javascript ((comment) @injection.content (#set! injection.language "comment"))
((comment) @injection.content (#set! injection.language "jsdoc")) ... actually works and is how the queries are defined in neovim. The ordering here is actually important. If it is, there seems to be a small issue here: helix/helix-core/src/syntax.rs Line 625 in ad15e7b
When updating tree-sitter, the language layers for the injections are added in order as they are discovered in the document. In our case of comment fighting with jsdoc at the same node, it only produces the correct highlighting if the language layer for comment comes before jsdoc. So is it technically and implemenation-wise valid to have two parsers capture the same node? And if so, shouldn't the ordering of layers for the injections be stable as it is defined in the queries? Feedback much appreciated on this. I would really like to get a better grasp of the implementation here. |
The root node for jsdoc is ; runtime/queries/jsdoc/injections.scm
((description) @injection.content
(#set! injection.language "comment")) |
sadly the javascript parser does not differentiate between single and multiline comments, as far as i can tell. |
You can tell them apart using ; runtime/queries/javascript/injections.scm
; block comment:
((comment) @injection.content
(#set! injection.language "jsdoc")
(#match? @injection.content "^/\\*.*\\*/$"))
; line comment:
((comment) @injection.content
(#set! injection.language "comment")
(#match? @injection.content "^//")) |
280226e
to
f545c11
Compare
This works now in all kind of comment scenarios. @the-mikedavis thanks for the support! fyi, i am using /**
* some description
* FIXME: this is not (description)
* @param {number} this counts as (description)
* @returns
*/ |
Ah yeah good catch, let's use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave it a spin and this looks good. Thanks!
this adds the injection for tree-sitter-comment to javascript. i am not sure if there is a reason for this missing. maybe it was supposed to interfere with the injection for "jsdoc" comments?
anyhow, it does seem to work to with both injections on "comment".