Details
-
Type:
Bug
-
Status:
Reopened
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 2.0.2Release
-
Fix Version/s: None
-
Component/s: Formatting
-
Labels:None
-
Environment:Version: 2.0.2.20100706-2000-e35
-
Number of attachments :
Description
typing...
def test(i) {
if(i == 0)
return
}
hitting return at the end of the if line does not indent the next line you have to manually indent it, unlike if there is a { at the end of the line the next line indents correctly.
Java does indent correctly when there is no { at the end of the line, I think Groovy should do the same.
Hi Jim. This is a known issue. The implementation of auto indentation on newline presses is trying to strike a balance between something that is
1) relatively straightforward to implement
2) robust when code is not completely syntactically correct
3) works in the most common cases so it is not annoying
Unfortunately, number 2 means that I decided explicitly not to use the Groovy parser, but mostly use some heuristics based on braces. This will work, as you noticed, ok when braces are there but not so well when they are not.
I figured that having to press "tab" to fix indent in these (I hope uncommon) cases is a fair price to pay for having the newline indentation logic work, even when the file has syntax / parse errors in it.
I do agree with you though. Ideally, this sort of case should be handled somehow.
We'll keep this issue open, it's something I'm keeping in the back of my mind, maybe when I get a good idea sometime how to handle this without doing a full parse, this can be fixed.
Thanks for submitting your report. Even though this was a "known issue", having user submitted issues/comments helps us gauge the importance of an issue.