'Correct Indentation' incorrect (after val/var)
Using the 'Correct Indentation' command in Eclipse (ctrl+i OR 'right-click on code' -> Source => 'Correct Indentation') the code gets incorrectly indented.
After every val/var declaration the following code lines get shifted one indentation to the right.
Before 'Correct Indentation':
After 'Correct Indentation':
This is unrelated to having code straight in the body of the class, the same problem happened when rewriting it to use the classic main method:
Workaround: end each val/var declaration with a semicolon.
===== Software used
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110218-0911
Scala IDE for Eclipse 2.0.0.201105131126-beta4-92f1b27 org.scala-ide.sdt.feature.feature.group
Scala 2.9.0.final (included with plugin)
After every val/var declaration the following code lines get shifted one indentation to the right.
Before 'Correct Indentation':
object HelloWorld extends App{
val toWho = "world"
print("Hello ")
print(toWho)
val toWhoElse = "universe"
System.out.print(" and the ")
print(toWhoElse)
}
After 'Correct Indentation':
object HelloWorld extends App{
val toWho = "world"
print("Hello ")
print(toWho)
val toWhoElse = "universe"
System.out.print(" and the ")
print(toWhoElse)
}
This is unrelated to having code straight in the body of the class, the same problem happened when rewriting it to use the classic main method:
object HelloWorldMain{
def main(args: Array[String]) {
var toWho = "world"
print("Hello ")
print(toWho)
var toWhoElse = "universe"
System.out.print(" and the ")
print(toWhoElse)
}
}
Workaround: end each val/var declaration with a semicolon.
===== Software used
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110218-0911
Scala IDE for Eclipse 2.0.0.201105131126-beta4-92f1b27 org.scala-ide.sdt.feature.feature.group
Scala 2.9.0.final (included with plugin)
Leave a comment
on 2011-08-09 12:04 *
By Mirco Dotta
Auto indentation is wrong after a val/var declaration
Type the following in any scala file:
object Test {
val foo = "foo"
println() // wrong auto-indentation
}
This only occurs if the right hand side of the assignement is a String or a Char and no comma (`;`) is appended fter the expression. So the `JavaHeuristicScanner` will think that the expression is a multiline statement and therefore indent twice the following line. Oddly enough, this only happens if the rhs is a String or a char (written using `"` or `'`). Any other value seems to work.
Since `ScalaAutoIndentStrategy` is using `JavaHeuristicScanner`, gere is where we need to look to fix this, IMO.
Type the following in any scala file:
object Test {
val foo = "foo"
println() // wrong auto-indentation
}
This only occurs if the right hand side of the assignement is a String or a Char and no comma (`;`) is appended fter the expression. So the `JavaHeuristicScanner` will think that the expression is a multiline statement and therefore indent twice the following line. Oddly enough, this only happens if the rhs is a String or a char (written using `"` or `'`). Any other value seems to work.
Since `ScalaAutoIndentStrategy` is using `JavaHeuristicScanner`, gere is where we need to look to fix this, IMO.
on 2011-08-15 11:51 *
By Iulian Dragos
Version changed from 2.0.0-beta4 to 2.0.0-beta09-29
Eclipse version changed from Helios to All
Assigned to changed from login to Mirco Dotta
Mirco spent some time on this and there's no easy fix for now. We'll tackle this for 2.1, by rewriting the heuristic scanner to something Scala specific.
on 2012-01-30 10:30 *
By skyluc
Version changed from 2.0.0-beta09-29 to 2.0.0-final-29
Assigned to changed from Mirco Dotta to -none-
Milestone changed from Helium to Backlog
Permission type changed from None to Public
on 2014-02-27 17:34 *
By Simon Schäfer
Component changed from Eclipse to Editor
Version changed from 2.0.0-final-29 to 3.0.2-210
on 2014-03-19 17:43 *
By Iulian Dragos
Assigned to set to Iulian Dragos
Status changed from Accepted to Fixed
Small improvements in indentation
Correct indentation for:
I needed to improve the testing infrastructure a bit:
suite, but failed in a real editor)
Fixed #1001306
Fixed #1000415
Branch: master
Commit: scala-ide:82c70919a7
Correct indentation for:
- assignments of string and char literals (val x = "abc")
- `else` alignment in brace-less if-else expressions
I needed to improve the testing infrastructure a bit:
- set a document partitioner (the results of indentation
suite, but failed in a real editor)
- correct the new caret position, and allow for tests where
Fixed #1001306
Fixed #1000415
Branch: master
Commit: scala-ide:82c70919a7