stsewd / tree-sitter-comment

Tree-sitter grammar for comment tags like TODO, FIXME(user).
https://stsewd.dev/tree-sitter-comment/
MIT License
134 stars 9 forks source link

`marker` as node for the comment marker #16

Open yochem opened 1 year ago

yochem commented 1 year ago

Dear @stsewd,

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

I was working on providing text objects for V (https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/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 (https://github.com/nvim-treesitter/nvim-treesitter-textobjects/issues/102#issuecomment-1086661385), 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.

stsewd commented 1 year ago

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.