33

My team often puts the word TODO in unfinished sections of code. Is there a way to add user-specified keywords to Visual Studio so that these are highlighted in some way? For example, in vim the word TODO is automatically highlighted.

For example, I'd want to see something like this:

//This is a stub -TODO:move this to another project

Flip
  • 6,233
  • 7
  • 46
  • 75
Beep beep
  • 18,873
  • 12
  • 63
  • 78

9 Answers9

20

In the Tools menu go to Options -> Environment -> Task List. Here you can enter Tokens.

These tokens will be added to the task list, but will not be highlighted. That can be achieved with one of the available TODO highlighters.

Lukas Kolletzki
  • 2,126
  • 3
  • 22
  • 30
scott
  • 748
  • 6
  • 10
  • 2
    I have TODO as a token, but it is not highlighting it in the editor window ... do I need to change something else? Thanks! – Beep beep Mar 11 '09 at 03:49
  • 14
    This won't highlight the words in source. It will only add them to the task list – JaredPar Mar 11 '09 at 03:51
7

As others have said, you need a plugin for VS (as of VS 2015 anyway) to highlight text. For those that are using Resharper:

From the menu go to ReSharper->Options->Tools->To-Do-Items.

Add your new comment and pattern. You can copy an existing one by editing it. I used the same settings as Todo for my new comment:

Title: AnythingYouWant

Regular Expression: `(?<=\W|^)(?<TAG>AnythingYouWant)(\W|$)(.*)`

Put a check "In comments"

Color: Web->Blue

Icon: Normal

And use it like this in your code:

// AnythingYouWant this comment is highlighted blue

goku_da_master
  • 4,257
  • 1
  • 41
  • 43
5

I think you're looking for custom-defined keyword highlighting: http://msdn.microsoft.com/en-us/library/zy61y8b8%28VS.80%29.aspx

Chris M
  • 59
  • 1
  • 1
5

Visual Studio supports custom syntax highlighting through the Managed Package Framework.

David Wilson
  • 4,369
  • 3
  • 18
  • 31
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
3

Highlighting of task tokens is possible only via extensions.

If you have ReSharper (commercial), it would highlight all tasks using the same color: Fonts and Colors > ReSharper Todo Item. ReSharper also marks tasks on the vertical error stripe.

Remarker (free) for VS 2015: https://visualstudiogallery.msdn.microsoft.com/32af9cb5-bb6e-4f02-97c6-a172c3ac5445 or for VS 2013: https://visualstudiogallery.msdn.microsoft.com/87813da0-8f1c-48a4-b1c4-85dfb7a269a9 can highlight different task tokens using different styles.

Same goes for VS10x Comments Extender (free) for VS 2010-2013, private beta for 2015: https://visualstudiogallery.msdn.microsoft.com/17c68951-7743-40bd-ad35-608706f54a92

Dima Korobskiy
  • 1,479
  • 16
  • 26
  • Remarker is now supported for VS 2015 too and works very well, at least for the way I use it. I would highly recommend it! Looks like VS10x Comments Extender is also available for VS 2015 via a private beta as of the time of writing this comment. More details can be found at https://visualstudiogallery.msdn.microsoft.com/17c68951-7743-40bd-ad35-608706f54a92. – Rockin4Life33 Jan 21 '16 at 16:50
  • Thanks a bunch. I've updated the answer. I've also included ReShaper for people who already purchased ReSharper. – Dima Korobskiy Jan 21 '16 at 19:14
  • Finally. The answer I've been looking for - though not complete enough for me. – goku_da_master Aug 05 '16 at 16:55
3

In Visual Studio:

Go to Tools > Options > Environment > Task list

There you can add any user=specified words, and it will appear in your task list any time you make a build and view the task list, in the same manner that //TODO: appears.

Ash M
  • 1,399
  • 2
  • 10
  • 23
1

I found and am using this customizable comment highlighting extension for VS 2010-2015.

From its description: "... you can format task comments (TODO, HACK, UNDONE) in terms of foreground color."

josliber
  • 43,891
  • 12
  • 98
  • 133
Fnord
  • 11
  • 1
0

There's a lot of them around, but the best and simplest one I've found is wayou.vscode-todo-highlight. However, it seem that the maintenance of this extension have been abandoned.

The settings is simple and clear to use, but unfortunately the example out-of-the-box settings (and documentation) sucks, so to make life simpler, just copy/paste this into your (User) setting JSON file.

On Win-10, the user settings is located here:
C:\Users\<username>\AppData\Roaming\Code\User\settings.json.

//------------------------------------------
// wayou.vscode-todo-highlight
//------------------------------------------
// For colors, see: 
// https://stackoverflow.com/questions/20541456/list-of-all-colors-available-for-powershell
"todohighlight.isEnable": true,
"todohighlight.isCaseSensitive": true,
"todohighlight.keywords": [
    "ToDo",
    "DEBUG:",
    "REVIEW:",
    {
        "text": "NOTE:",                                                // 
        "color": "yellow",                                              // 
        "backgroundColor": "#006400",                                   // DarkGreen #FF006400 (argb)
        "overviewRulerColor": "grey",                                   // 
        "fontWeight": "bold",                                           // 
    },
    {
        "text": "HACK:",                                                // 
        "color": "#000",                                                // 
        "isWholeLine": false,                                           // 
        "fontWeight": "bold",                                           // 
        //"margin":  "5px",                                             // [padding, border, margin] Not working!
    },
    {
        "text": "TODO:",                                                // 
        "color": "red",                                                 // 
        //"border": "1px solid red",                                    // 
        "borderRadius": "1px",                                          //NOTE: using borderRadius along with `border` or you will see nothing change
        "backgroundColor": "rgba(4,4,4,.2)",                            // "rgba(0,0,0,.2)"
        "isCaseSensitive": false,                                       // 
        // Add other styling properties here. 
    }
],
//"todohighlight.keywordsPattern": "TODO:|FIXME:|\\(([^)]+)\\)",        //highlight `TODO:`,`FIXME:` or content between parentheses
"todohighlight.defaultStyle": {
    "color": "red",                                                     // 
    "backgroundColor": "#ffab00",                                       // 
    "overviewRulerColor": "#ffab00",                                    // 
    "cursor": "pointer",                                                // 
    "border": "1px solid #666",                                         // 
    "borderRadius": "2px",                                              // 
    "isWholeLine": false,                                               // 
    // Add other default styling properties here. 
},
"todohighlight.include": [
    "**/*.js",
    "**/*.jsx",
    "**/*.ts",
    "**/*.tsx",
    "**/*.html",
    "**/*.php",
    "**/*.css",
    "**/*.scss",
    "**/*.ps1"
],
"todohighlight.exclude": [
    "**/node_modules/**",
    "**/bower_components/**",
    "**/dist/**",
    "**/build/**",
    "**/.vscode/**",
    "**/.github/**",
    "**/_output/**",
    "**/*.min.*",
    "**/*.map",
    "**/.next/**"
],
"todohighlight.maxFilesForSearch": 5120,
"todohighlight.toggleURI": false
//------------------------------------------

NOTE: I didn't enclose the outer {}s.

not2qubit
  • 14,531
  • 8
  • 95
  • 135
0

As others have answered, for those using ReSharper their tags should automatically be highlighted, but the place in the options to set tags is called "To-do Explorer". Unsure if it changed since the other answer but wanted to add that for any using ReSharper as of 2023.