stsewd / tree-sitter-comment

Tree-sitter grammar for comment tags like TODO, FIXME(user).

Home Page:https://stsewd.dev/tree-sitter-comment/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`marker` as node for the comment marker

yochem opened this issue · comments

Dear @stsewd,

Again thanks for this TS parser, I really like it.

I was working on providing text objects for V (nvim-treesitter/nvim-treesitter-textobjects#404), and wanted to implement @comment.inner, to delete the whole line comment, except the comment marker and leading space:

// this is a comment
// |

Where | denotes the cursor. Since neovim does not support quantifiers for nodes yet (nvim-treesitter/nvim-treesitter-textobjects#102 (comment)), it did not seem possible for us to also support e.g. /// documentation, i.e. any number of comment markers.

Then I thought about this parser, and thought it would be a good thing to have a marker node for comments. This would make cic (change inner comment) very easy to implement. I would also argue that the marker is an important node in the comment syntax, and different from the actual text of the comment.

The only problem would be that every language has a different comment marker. I don't know if it would be even possible for this parser to know what the comment marker would be. Maybe there is a way to find out? Or infer?

Let me know if this is something that would be possible. It would be really cool to have a comment marker node in the tree, especially for textobjects, but also for highlighting.

Hi, sorry for the late reply (I had the feeling that I already replied to this, maybe I forgot to submit my reply :_)

As you already described, adding that will mean adding it for all languages and make it work for all. I think this can be solved by each language grammar by providing the tokens for the inner content of the comments and the symbols delimiting it.