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.

0
13 comments
Avatar
Permanently deleted user

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.

0
Avatar
Permanently deleted user

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.

0

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:

  1 match {     case 1      => 2     case 342342 => 4     case 2342   => 5     case 23423412342342 => 1     case 1341234        => 3     case 21341          => 5   }


Best regards,
Alexander Podkhalyuzin.

0
Avatar
Permanently deleted user

Great! I'll try it out and see how it goes...

0
Avatar
Permanently deleted user

The new formatter format method define append two new line after = , how to disable this feature or it's a bug?

def ::(o: Test) = new Foo(o)


to

    def ::(o: Test) =

      new Foo(o)

0

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.

0
Avatar
Permanently deleted user

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?

0

I created a ticket here: http://youtrack.jetbrains.com/issue/SCL-7376

Best regards,
Alexander Podkhalyuzin.

0
Avatar
Permanently deleted user
Along with or as part of Scala's code style Wrapping and Braces > Field groups > Align in columns that does the following:
  
val playVersion = "2.3.3"
val playLib     
= "com.typesafe.play" %% "play" % playVersion % "compile->default" exclude("org.scala-lang", "scala-reflect") exclude("io.netty", "netty")
val playWs      = "com.typesafe.play" %% "play-ws" % playVersion % "compile->default" exclude("org.scala-lang", "scala-reflect") exclude("io.netty", "netty") exclude("com.google.guava", "guava")
val playJson    = "com.typesafe.play" %% "play-json" % playVersion % "compile->default" exclude("org.scala-lang", "scala-reflect") exclude("io.netty", "netty")
val playCache   = "com.typesafe.play" %% "play-cache" % playVersion % "compile->default"
val anorm       
= "com.typesafe.play" %% "anorm" % playVersion % "compile"


Can we get the sbt DSL symbols like % to also line up as below?

  
val playVersion = "2.3.3"
val playLib     
= "com.typesafe.play" %% "play"       % playVersion % "compile->default" exclude("org.scala-lang","scala-reflect") exclude ("io.netty","netty")
val playWs      = "com.typesafe.play" %% "play-ws"    % playVersion % "compile->default" exclude("org.scala-lang","scala-reflect") exclude ("io.netty","netty") exclude("com.google.guava", "guava")
val playJson    = "com.typesafe.play" %% "play-json"  % playVersion % "compile->default" exclude("org.scala-lang","scala-reflect") exclude ("io.netty","netty")
val playCache   = "com.typesafe.play" %% "play-cache" % playVersion % "compile->default"
val anorm       
= "com.typesafe.play" %% "anorm"      % playVersion % "compile"


Thanks,
Jon

0

That's reasonable, probably it would be great implement it for SBT

Best regards,
Alexander Podkhalyuzin.

0
Avatar
Permanently deleted user

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

0

It's Formatter issue. Yes, if you create issue, it will be great, thank you!

Best regards,
Alexander Pokhlyuzin.

0
Avatar
Permanently deleted user

Issue created, Alexander.

Enhance for SBT: Wrapping and Braces > Field groups > Align in columns
http://youtrack.jetbrains.com/issue/SCL-7497

Cheers,
Jon

0

Please sign in to leave a comment.