todo-tree icon indicating copy to clipboard operation
todo-tree copied to clipboard

How to highlight TODOs in `/** */` comments?

Open eduardo4jesus opened this issue 2 years ago • 6 comments

In C/C++ files, TODOs are hightlighted when present in comments like

// TODO: something

but not in comments like

/**
 * TODO: another thing.
 */

what am I missing?

eduardo4jesus avatar Jun 07 '23 13:06 eduardo4jesus

add the comment to regex setting

default is: todo-tree.regex.regex ( (//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS))

to my understanding of regex, its looking for text that starts with literals (//, # <!--, ;, /*) followed by a tag (TODO, FIXME, etc)

add the literal /** and/or * and it should find > /\*\*|\*| change regex setting to (//|#|<!--|;|/\*|/\*\*|\*|^|^[ \t]*(-|\d+.))\s*($TAGS)

See it here https://regex101.com/r/S3b75K/1

smalls89 avatar Aug 13 '23 23:08 smalls89

@Gruntfuggly could we change the default regex to support this ootb? Same comment style is also found in other languages like Java (JavaDoc) + JavaScript (JSDoc/TSDoc).

drostea avatar Apr 23 '24 11:04 drostea

Based on @smalls89's comment, I added & tested this in ~/.vscode/settings.json. This change would go into the appropriate line in package.json.

"todo-tree.regex.regex": "(//|// -|#|<!--|;|\\* -|\\/\\*\\*|\\*|/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)",

To understand better what changed, I broke down the diff from the default for todo-tree.regex.regex from https://github.com/Gruntfuggly/todo-tree/blob/master/package.json

+  "todo-tree.regex.regex": "(//|// -|#|<!--|;|\\* -|\\/\\*\\*|\\*|/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)",
-  //            "default": "(//     |#|<!--|;                    |/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)",

                                              ^^^^^^^^^^^^^^^^^^^^ added for /** */ style block comments
                                ^^^^^ added for // -[ ]

Demo of Todo Tree with 3 types of Javascript comments (single line, block no leading character, block with leading *): todo-tree-demo.js


JavaScript Source for `todo-tree-demo.js`
// BUG - bug 🐛 single-line comment
// FIXME - needed fixes 🔥 single-line comment
// HACK - hack 🔧 single-line comment
// TODO - future updates ⚠︎ single-line comment
// XXX - XXXXXX single-line comment
// -[ ] issue draft
// -[x] issue complete

/** Block Comment with no leading character

BUG - bug 🐛 Block Comment
FIXME - needed fixes 🔥 Block Comment
HACK - hack 🔧 Block Comment
TODO - future updates ⚠︎ Block Comment
XXX - XXXXXX Block Comment
-[ ] issue draft Block Comment
-[x] issue complete Block Comment

 */

/** Block comments with leading `*`
 * 
 * BUG - bug 🐛 Block Comment with *
 * FIXME - needed fixes 🔥 Block Comment with *
 * HACK - hack 🔧 Block Comment with *
 * TODO - future updates ⚠︎ Block Comment with *
 * XXX - XXXXXX Block Comment with *
 * -[ ] issue draft  Block Comment with *
 * -[x] issue complete Block Comment with *
 * 
 */

roblabs avatar May 07 '24 22:05 roblabs