Scala Formatter
Hi all,
Scala plugin formatter is very poor, and I want to improve it (mostly according Scala Code Style). If anybody has suggestions or problems with formatter, you can write it to me now, I'll try to fix it.
Best regards,
Alexander Podkhalyuzin.
Please sign in to leave a comment.
It would be really nice to support aligning '=' in a group of neighbouring vals, and => in cases.
This style is used in scalac:
http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_0_final/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala#L275
http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_0_final/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala#L201
I expect it would be tricky to get this right, it would need some heuristics -- only trigger this mode if one alignnment is done by hand, don't insert more than N blank spaces to align things. But I think it really enhances readability.
Maybe the UI for this would be:
1. add an option to preserve blank spaces before => and =
2. add a new keyboard shortcut to format a selected area with this alignment.
It really doesn't work for all matches, so I think it makes sense to trigger this manually in the places it is desired.
I pushed changes about column alignment.
Look at appropriate settings in Wrapping and Braces settings page.
I didn't add any possibility to disable this alignment in some cases as you asked, but I'm not sure it's necessary.
If some alignment is ugly then you can separate few groups by additional blank line:
Best regards,
Alexander Podkhalyuzin.
Great! I'll try it out and see how it goes...
The new formatter format method define append two new line after = , how to disable this feature or it's a bug?
to
This is bug. It's fixed in the newest builds. See nightly http://confluence.jetbrains.net/display/SCA/Scala+Plugin+Nightly+Builds+for+IDEA+X
Best regards,
Alexander Podkhalyuzin.
There's one thing that is not being formatted correctly: when you call a method that accepts a by-name parameter and pass a block of code it will incorrectly align it. For instance, this is how this snippet of code should be formatted:
def someMethod(body : => scala.Any) = { /* some code*/}
someMethod {
println("foo")
bar()
}
But this is how it's formatted right now (IntelliJ Idea IU-138.1283.4):
someMethod {
println("foo")
bar()
}
Is there a way to completely disable formating in the meantime?
I created a ticket here: http://youtrack.jetbrains.com/issue/SCL-7376
Best regards,
Alexander Podkhalyuzin.
Can we get the sbt DSL symbols like % to also line up as below?
Thanks,
Jon
That's reasonable, probably it would be great implement it for SBT
Best regards,
Alexander Podkhalyuzin.
Hi Alexander,
> probably it would be great implement it for SBT
Is there a separate SBT effort or issue category?
Would you like me to create an issue for it?
Thanks,
Jon
It's Formatter issue. Yes, if you create issue, it will be great, thank you!
Best regards,
Alexander Pokhlyuzin.
Issue created, Alexander.
Enhance for SBT: Wrapping and Braces > Field groups > Align in columns
http://youtrack.jetbrains.com/issue/SCL-7497
Cheers,
Jon