Indentation for C-style block comments

已回答

Given a comment with messed up indentation that looks like this:

/**
* This is a function
   * @param one The first param
     * @param two The second param
 */

I would very much like to be able to highlight this text, and then press “Ctrl+I”  (or “Ctrl+Alt+L”) and have it transform into this:

/**
 * This is a function
 * @param one The first param
 * @param two The second param
 */

Doing this is kinda out-of-the-box behavior in some other IDEs I regularly use, but CLion doesn't do it.

(CLion seems to only fix indentation for C++ style comments, where the line starts with “//”.)

 

Is there any setting to configure this behavior, or is it simply an oversight in the CLion formatter that'll need to be addressed?

0

Hello!

I would very much like to be able to highlight this text, and then press “Ctrl+I”  (or “Ctrl+Alt+L”) and have it transform into this

Selecting this block and executing Code | Reformat Code works correctly on my side in a default "Hello, World!" project (File | New Project > C++ Executable > Create). Does it work for you in the default project?

0

No, it does not.

Clicking “Reformat Code" with this block selected does nothing.

(I've now reproduced this in my real projects on Linux, and this Hello World project on macOS.)

0

Please do Help | Collect Logs and Diagnostic Data and send the resulting archive to clion-support at jetbrains.com together with the link to this thread. Note that logs might contain private user information (like file paths and names).

0

Reproduced from a test project on Linux, and sent logs to the address as requested.

0

For the record:

The related request in our tracker - CPP-25972. ClangFormat can be used as a workaround - https://www.jetbrains.com/help/clion/clangformat-as-alternative-formatter.html.

0

I'm not actually sure that describes the same issue.

CPP-25972 seems to be about general purpose comment formatting, and makes absolutely no mention of specific comment styles.

The issue I'm reporting is just about indentation, and if I change from a C-style comment ("/** … */") to a C++ style comment ("// foo // bar") then CLion has no problems fixing indentation.

 

0

On my side, both Doxygen /** … */ comments and general /* .. */ multiline comments are not reformatted when Code | Reformat Code is executed. CPP-25972 is about formatting such comments when Code | Reformat Code is executed.

0

Here's a before/after screenshot showing explicitly what I'm talking about:

Note how one comment style gets its indentation fixed, and the other is completely untouched.

0

I've reopened CPP-22744 When formatting a block comment, align lines. It's specifically about alignment and /* .. */ multiline comments. Feel free to follow it if you find it more suitable.

0

Thanks.  That issue looks like a much better description of what I'm actually encountering.

0

请先登录再写评论。