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

Avoid highlighting in certain situations

MatthewP-Prosper opened this issue · comments

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?

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.

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 nvim-treesitter/nvim-treesitter#4298.