stsewd / tree-sitter-comment

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

Avoid highlighting in certain situations #14

Closed MatthewP-Prosper closed 1 year ago

MatthewP-Prosper commented 1 year ago

Hey there, I often use print statement debugging/logging which I comment out, for example something like

# print('method ARN: {}'.format(methodArn))

This highlights ARN: unintentionally and distracts me a bit haha. It would be awesome if there was some way to avoid this, but I am not sure the best way as I'm sure many people have their own style of using these comments. Here are some thoughts on a couple ways this could be achieved.

  1. It only matches if the first word after the comment ends with a colon.
  2. It doesn't match words nested inside quotes.
  3. Have an optional file to define a words whitelist and only highlight those words.

Thoughts?

stsewd commented 1 year ago

Hi, I encountered a similar case myself p:

I think we could make the default highlight queries more strict, and by default just match the specified keywords, instead of everything (this is from the nvim-treesitter side).

The first option could also be interesting to apply in the grammar itself too, but that will depend on the other language grammars how they capture the comment, for example, some grammars mix the "comment character" with the comment itself.

Not sure about the third option, we will need an option at compile time, making it a little harder to add a new keyword, but maybe isn't that bad to have just a subset of keywords supported by the grammar itself, and not many users have the need for custom keywords.

stsewd commented 1 year ago

https://github.com/nvim-treesitter/nvim-treesitter/pull/4298

stsewd commented 1 year ago

I think we could make the default highlight queries more strict, and by default just match the specified keywords, instead of everything (this is from the nvim-treesitter side).

I think this option makes sense, that change was already merged in nvim-treesitter https://github.com/nvim-treesitter/nvim-treesitter/pull/4298.