Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformatting code is left-aligning comments. #295

Closed
EBatTiVo opened this issue Jun 4, 2015 · 10 comments
Closed

Reformatting code is left-aligning comments. #295

EBatTiVo opened this issue Jun 4, 2015 · 10 comments

Comments

@EBatTiVo
Copy link
Contributor

EBatTiVo commented Jun 4, 2015

Highlight and reformat (Code->Reformat Code) any code containing a comment will place the single-line comments against the left-most column (removes indenting) or will left-align the first line of a block comment. Copy and paste will left align comments in the pasted block as well.

TIR: STB-10533

@wiggin77
Copy link

wiggin77 commented Jun 4, 2015

This also happens for me when I type "/**" then hit enter to auto generate a comment block. First line is always at column 0. (IntelliJ 14.1.3, plugin 0.9.4) Btw, same operation works fine for Java.

@EBatTiVo
Copy link
Contributor Author

EBatTiVo commented Jun 4, 2015

The code that does reformatting is IDEA's DefaultCodeFormatter (IIRC). The PSI for comments is likely not what the formatter is expecting. I suspect, but I haven't yet confirmed, that the change for #209 is causing the issue.

Incidentally, the unit tests do contain this scenario and are NOT failing. Therefore, I'm half-expecting some secondary processing step to be re-aligning incorrectly. Stepping (debugging) through unit test code did not reveal anything unusual.

@as3boyan
Copy link
Contributor

as3boyan commented Jun 4, 2015

If I got it right, then I think that it works in a proper way, single line comments in IDEA added from line start, so no problem with that, but if it's added in some other IDE, then this may happen.

@as3boyan
Copy link
Contributor

as3boyan commented Jun 4, 2015

@wiggin77 /** indeed works wierd, but /* works just fine

@EBatTiVo
Copy link
Contributor Author

EBatTiVo commented Jun 5, 2015

If I got it right, then I think that it works in a proper way, single line comments in IDEA added from line start, so no problem with that, but if it's added in some other IDE, then this may happen.

I don't understand. Are you saying that single line comments should be aligned on the left-most column (column 1) when the code is reformatted? If so, then I disagree.

Right now, this:

class Test {
    // a comment
    public function new() {}
}

is reformatted to this:

class Test {
// a comment
    public function new() {}
}

If the comment started in the left-most column (column 1), then it should stay there. If the comment has any indentation, then it should be indented to match the code.

@soywiz
Copy link
Contributor

soywiz commented Jun 5, 2015

+1 I had that problem. All my comments were moved to the left-most column and it was a bit annoying.

@as3boyan
Copy link
Contributor

as3boyan commented Jun 5, 2015

@EBatTiVo Sorry, I was wrong
I checked how it works in Java indeed it works differently

Java:
Imgur

Notice where it inserts comment (// part)
Always indents code on enter

Haxe:
Imgur
If I hit enter after method body - indentation is wrong here
Also on comment (//) gets inserted at the beginning of line

@EBatTiVo
Copy link
Contributor Author

Fix is in #372. Awaiting review.

@EBatTiVo
Copy link
Contributor Author

Fixed with #372 and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants