116

If yes, how ?

If not, is there a workaround to get similar functionality ?

EDIT:

What I mean is something like this :

// TODO line1
// line2
// line3

and line1, line2, line3 belong to the same TODO and get highlighted with blue.

Ilya Serbis
  • 21,149
  • 6
  • 87
  • 74
jhegedus
  • 20,244
  • 16
  • 99
  • 167

7 Answers7

107

This is supported since 2018.3.

Multiline TODO comments

Multiline TODO comments

IntelliJ IDEA 2018.3 now supports multiline TODO comments, now the first and all subsequent TODO comment lines are highlighted in the editor and listed in the TODO Tool Window. Simply add an indent starting from the second line of your multiline TODO comment, and the IDE will differentiate it from an ordinary comment.

Community
  • 1
  • 1
congusbongus
  • 13,359
  • 7
  • 71
  • 99
  • 2
    Thank you! Very useful. The only problem is when I click Ctrl-Alt-L to format my file the indentation is removed. Any idea how to prevent this? – Gep Jun 01 '20 at 15:00
  • @Gep I have the 2021.2.3 version of WebStorm and they appear to have fixed it. – Thor Lancaster Nov 28 '21 at 05:19
  • 2
    When working on a Flutter app in Android Studio Electric Eel (2022.1.1 Patch 1), multiline TODO does not work with multiple single line comments which use `//`, but does work with the block comment `/* your comment here */`. I'm not sure if this problem is isolated to Flutter and/or Dart, or if it extends to other Android Studio supported languages or other IntelliJ IDEs. – ubiquibacon Feb 08 '23 at 21:21
  • it's tracked here for Dart https://youtrack.jetbrains.com/issue/WEB-34694 – Gazihan Alankus Apr 14 '23 at 07:25
  • Even in Android Studio Flamingo 2022.2.1 multiline TODO works only with multiline comments. `\*` `TODO foo` `bar` `*/` – krishh Jul 03 '23 at 13:22
56

No, not for now.

This feature has been discussed, but not yet implemented.

EDIT/UPDATE:

It is implemented in 2018.3 version.

Kamil
  • 13,363
  • 24
  • 88
  • 183
Gallal
  • 4,267
  • 6
  • 38
  • 61
  • 12
    Please take a moment to follow that link and vote on the issue to get this ticket prioritized. There's a thumbsup icon next to "voters" on the right side. – adamdport Jan 13 '17 at 20:07
  • 3
    This is now implemented in IDEA 2018.3, currently in EAP. https://blog.jetbrains.com/idea/2018/09/intellij-idea-2018-3-early-access-program-is-open/ – David Sep 25 '18 at 14:22
  • And now available for Android with Android Studio 3.4 release as it's based on IDEA 2018.3 – shaktiman_droid Apr 18 '19 at 17:28
  • 1
    how to: https://stackoverflow.com/a/53472479/6114088 – Louis Dec 03 '20 at 17:30
29

In my settings I'm using such a regex for multiline TODO:

\/(\/|\*)[ ]*\btodo\b(.|\n)*(\*\/|)

The only problem is that it doesn't highlight last */ symbols of multiline comment. If anyone can solve that, it would be great!

NonGrate
  • 862
  • 9
  • 22
  • 2
    Found two potential bugs (or likely errors on my part) with this for Android Studios at least. One, for some reason, it throws off my repo indexing for a single class in my project. The same class every time too. Remove this from the TODO list and it is appropriately reindexed. Second, it creates a StackOverflow issue when the IDE loads, but the IDE doesn't post a warning or force close or anything so I am not sure of the severity. I will keep looking into it, but something worth mentioning if anyone else runs into it. That being said, it does appear to do as it should outside of that. – zgc7009 Apr 08 '16 at 13:15
  • Hi zgc7009! Could you please post here your TODO comment? More people see it - faster we will find the problem :-) – NonGrate Apr 08 '16 at 16:06
11

You can use FIXME and TODO using tabs as follows

//FIXME: first line
//<tab> second line
//<tab> third line

For more information please refer to the documentation

Baimyrza Shamyr
  • 449
  • 1
  • 6
  • 17
6

Do you mean this? using-todo-lists

/**
 * todo multi-line
 *  
 */
Juan Cortés
  • 20,634
  • 8
  • 68
  • 91
yanyu
  • 219
  • 2
  • 11
  • 2
    Thank you for the answer. That would be good if all the lines in the block would belong to the todo and would be highlighted with blue. But it's the closest thing that we have at the moment. – jhegedus May 30 '14 at 17:55
3

Building on NonGrate's answer:

Go to settings, search for TODO settings, and replace the existing todo entry "\btodo\b.*" with:

(\btodo\b.*)|(\/\*(\*(?!\/)|[^*])*\btodo\b(\*(?!\/)|[^*])*\*\/)

Result:

enter image description here

You must use */ to close the highlight.

It uses 2 patterns:

  1. (\btodo\b.) captures any line with the word todo
  2. (/\*(\*(?!/)|[^*])*\btodo\b(\*(?!/)|[^*]*\*/) captures multi line comments starting with /* and ending with */

Any other combinations may not work.

Note: You have to replace the existing regex to avoid having multiple instances of the same todo item appearing in the todo list.

chaser
  • 3,107
  • 4
  • 29
  • 34
  • Just used this in IntelliJ 2017.1.3 on Mac and it worked great. Thanks! – yokeho Jun 02 '17 at 15:58
  • 2
    In the current Android Studio, this does not work like @Jeremy said above... but it does work with using /** testing before TODO testing after */ – Codeversed Aug 03 '17 at 00:58
  • 3
    WARNING: This simply breaks IntelliJ and Android Studio into a billion pieces. It has RegEx recursion which is considered almost a sin in Java development due to how RegEx expressions are compiled and how easily you can cause a SO (which indeed this causes). – mradzinski Oct 04 '17 at 01:42
-1

This regex works for me:

(?:(?:todo|TODO)(?:\[[A-Z,a-z]+\-\d+\])?\s(\s*\b.*\b)*)|(?:\/\*\s*(?:todo|TODO)(?:\[[A-Z,a-z]+\-\d+\])?\s(?:(?!\*\/)[\s\S])*\*\/)

It basically looks for the following:

  • A todo or TODO keyword optionally suffixed by a ticket/issue id in brackets and any amount of characters after a single white space character.
  • A java multi line comment starting with /* followed by any amount of white space and then the conditions outlined in the single line todo description above. It terminates once it finds */ in any of the following lines.

Single-line examples:

todo some very important stuff
TODO[SAOY-1376] An urgent bug fix described in the SAOY-1376
// todo some very important stuff
// TODO[SAOY-1376] An urgent bug fix described in the SAOY-1376

Multi-line examples:

/* todo assignee or something
    a very important message
    another thing
*/

/* TODO[SAO-13]
 * a very important message
 * another thing
*/