Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Todo Explorer: Recognized keywords

Open AndreasMatthias opened this issue 2 years ago • 8 comments

Note is a very common word and I don't want each note to appear in the Todo Explorer. However, I don't want to dismiss this keyword altogether. Thus I changed the keyword in the Todo Settings to @Note. Unfortunately ToDo Explorer did not recognize this keyword. So I tried: #Note, %Note, !Note, ... But they didn't work either.

Which characters are allowed in keywords? How to make a Note keyword more prominent, so that only distinguished notes are displayed in Todo Explorer and not each and every occurance of Note?

AndreasMatthias avatar Feb 27 '22 15:02 AndreasMatthias

I added a new keyword REVIEW which is the kind of note I want to see a to-do for anyway.

Greedquest avatar Feb 28 '22 08:02 Greedquest

Of course you can always try to find a unique word which you are not using otherwise in your comments. But this is not always easy, in particular because keywords are case insensitive. That's why I tried to use a special character as a prefix to the keyword. But unfortunately this didn't work.

Actually I was thinking about using this todo feature to store some additional information (like mentioning papers, books, standards, ...) and use the Todo Explorer as a "reference table" or index. This way you can find parts of your code quickly, where you are using information from certain papers. And this works really nice. I like it. I just thought it might be easier to find unique keyword if you could prefix them with a special character.

AndreasMatthias avatar Mar 02 '22 22:03 AndreasMatthias

So the ToDo Explorer obtains its results by matching the configured ToDo Markers as a regular expression with word boundaries against the comment text (which does not include the comment marker itself):

https://github.com/rubberduck-vba/Rubberduck/blob/51f2d139faf7c245b96e09bcd31b4424491dc186/Rubberduck.Core/UI/ToDoItems/ToDoExplorerViewModel.cs#L296-L299

This implies in particular, that all usual prefixes should be perfectly fine, so long as they are not special characters in a regular expression, and even then we push the configured marker through Regex.Escape, so that should work...
Depending on the exact comment marker you are using, there could be some shenanigans around type hints and REM that would parse the comment in an unexpected way, but that should not interfere with the matching of @ or ! as a comment marker prefix.

On that note I am slightly unhappy with how the regular expressions are used and that the ViewModel is responsible for filtering ParserState.AllComments, but changing that is a whole new can of worms...

Vogel612 avatar Mar 03 '22 11:03 Vogel612

The marker @ does not work because it is used as marker for the Rubberduck annotations. Accordingly, the word starting with it is not considered part of a comment. If you use it, you should actually see an inspection result for an unrecognized annotation.

For the other prefixes, I am not sure about the problem though.

MDoerner avatar Mar 03 '22 11:03 MDoerner

@MDoerner It seems that the @ marker must follow the comment sign immediately:

'@aaa
' @bbb
' testing @ccc

I get a warning for @aaa but neigher for @bbb nor @ccc. Whereas

' testing todo

is recognized as a todo-item.

AndreasMatthias avatar Mar 03 '22 18:03 AndreasMatthias

True, the rule for an annotation is to start with an @ right at the start of a comment.

MDoerner avatar Mar 03 '22 18:03 MDoerner

https://github.com/rubberduck-vba/Rubberduck/blob/51f2d139faf7c245b96e09bcd31b4424491dc186/Rubberduck.Core/UI/ToDoItems/ToDoExplorerViewModel.cs#L296-L299

This implies in particular, that all usual prefixes should be perfectly fine, so long as they are not special characters in a regular expression, and even then we push the configured marker through Regex.Escape, so that should work...

But \b specifies a boundary between a word and a non-word character. Isn't this exactly the reason why non-word characters are not valid in this regex?

AndreasMatthias avatar Mar 03 '22 22:03 AndreasMatthias

@Vogel612 Well, "beginning of line" will break all kinds of framed comments, like:

' **********
' *
' * Note: foo
' *
' **********

AndreasMatthias avatar Mar 15 '22 00:03 AndreasMatthias