Project
IntelliJ IDEA
Priority
Normal
Type
Feature
Fix versions
No Fix versions
State
Fixed
Assignee
Denis Zhdanov
Subsystem
Code Formatting and Code Style
Affected versions
No Affected versions
Fixed in build
96.1012  
  • Created by   Pat Niemeyer
    6 years ago (13 Jun 2005 20:25)
  • Updated by   Riyad Kalla
    20 months ago (15 Sep 2010 18:02)
  • Jira: IDEADEV-2421
    (history, comments)
 
IDEA-28895 Basic line wrapping or formatting in block comments...
6
Issue is visible to: All Users
  The issue is visible to the selected user group only
It seems that there should be some, at least minimal, ability to wrap long lines in block comments to the page width.

I believe that the AutoFormat plugin is supposed to do this, however it is broken with the EAP builds and this seems like something that is really fundamental and perhaps should be part of the core.


thanks,

Pat Niemeyer
Author of Learning Java, O'Reilly & Associates and the BeanShell Java Scripting Language
Comments (12)
 
History
 
Linked Issues (?)
 
Ken Arnold
  Ken Arnold
01 Mar 2006 20:36
6 years ago
I really want this added. Formatting a block comment by hand is really painful, and javadoc comments are formatted. They aren't the same, but they're similar enough that it feels frustrating. I've been known to change a block comment into a javadoc comment, reformat, then undo that. Of course to do that I have to have an identifier declared at the same indentation level as the block comment because javadoc comments do not reformat unless they are actually above an identifier. So I only do this rarely.

Obviously these are not identical to javadoc comment text, mostly noting the absence of HTML directives. But otherwise the same formatting would apply – just take blank lines to mean blank lines, not new "<p>" directives. Just preserve my comment leader and that's fine.

I would think that if this is done, also formatting blocks (or selected sets of) standalone block comments would be easy to include. It's just a different comment leader at some level. Lots of folks use successive lines of "//" comments instead of "/*...*/" comments.
Riyad Kalla
  Riyad Kalla
10 Feb 2010 03:06
2 years ago
+1 from me as well. I write a lot of code documentation and not having it formatted automatically for me is such a waste of time, especially given that IntelliJ is formatting all the other forms of comments for me already. It seems more like an oversight than it does an actual issue – like just taking the code that formats the javadoc blocks and adding 1 more condition to it to include block comments.
Riyad Kalla
  Riyad Kalla
26 May 2010 19:40
23 months ago
Denis,

Soft line-wrapping is not the same thing as this feature request. Soft line-wrapping is a visual-only enhancement to the editor to display long content in a more easy-to-read manner. What I (and Ken) are requesting here is to have IntelliJ actually apply the Javadoc formatter to:

/* This is a comment */
// This is also a comment

styles of comments correctly. Eclipse has actually does this since the 2.0 release and it's incredibley helpful for folks that do a lot of commenting in their code to have really long comment blocks wrap and fit within the margins.

We actually want line breaks inserted as well as any necessary comment line prefixes inserted to nicely format our in-code documentation.
Denis Zhdanov
  Denis Zhdanov
26 May 2010 19:59
23 months ago
Got the point, thanks
Related Changes
Resolved Date
2 years ago (26 May 2010 14:35) None
State
DuplicateOpen
Riyad Kalla
  Riyad Kalla
06 Aug 2010 20:45
21 months ago
Denis, I'll drop-ship you guys a case of beer if we can get this into 9.0.4 :)

I'm hoping it's not actually that hard to impl (since the formatter already does the right behavior with /** blah / comments, just not / blah */ or // blah – comments.
Denis Zhdanov
  Denis Zhdanov
09 Aug 2010 09:27
21 months ago
I am going to implement that as a part of IDEA 10 release.
Riyad Kalla
  Riyad Kalla
09 Aug 2010 20:14
21 months ago
Denis, you are our new favorite person ;)
Denis Zhdanov
  Denis Zhdanov
10 Aug 2010 09:22
21 months ago
:)
Denis Zhdanov
  Denis Zhdanov
15 Sep 2010 17:44
20 months ago
There is a dedicated option now - 'Project Settings -> Code Style -> Wrapping and Braces -> Long lines remained after formatting'.

Corresponding tests are added:
  • com.intellij.psi.formatter.java.JavaFormatterWrapTest.testWrapLongLine();
  • com.intellij.psi.formatter.java.JavaFormatterWrapTest.testWrapLongLineWithTabs();
  • com.intellij.psi.formatter.java.JavaFormatterWrapTest.testWrapLongLineWithSelection();
Related Changes
Resolved Date
20 months ago (15 Sep 2010 17:44)
Type
ExceptionFeature
State
OpenFixed
Assignee
Denis Zhdanov (denis.zhdanov)Denis Zhdanov
Subsystem
<lost change>Code Formatting and Code Style
Fixed In build
<lost change>96.1012
Riyad Kalla
  Riyad Kalla
15 Sep 2010 17:51
20 months ago
Denis,

From the option name, I couldn't tell if this addressed the original bug which was the Javadoc formatting rules being applied to slash-dot (/*) and slash-slash (//) comments with regards to:
  • line wrapping
  • correct indentation of text characters (by 1 or 2 spaces to align them nicely) in the case of a slash-dot (/*) comment that ends up being wrapped to multiple lines.

I'm not request you change scope or anything drastic (as much as I would love to see this done) I just wanted to manage my expectations for the upcoming release so I'm not suicidal when 9.1 comes out :)
Denis Zhdanov
  Denis Zhdanov
15 Sep 2010 17:57
20 months ago
Well, the problem was that formatter sometimes left long lines (lines that exceed right margin) as is (true at least for javadoc comments, single- and multi-line comments and string literals).
Mentioned feature targets all such lines (regardless their semantic like comment, javadoc, string etc). I.e. it makes formatter break long lines, insert necessary symbols as necessary and adjust new lines indentation as well.
You can wait for the next IJ X EAP and try it yourself.
Riyad Kalla
  Riyad Kalla
15 Sep 2010 18:02
20 months ago
Denis that sounds spot on actually. I'll give it a try as soon as EAP is ready. Thanks!