Formatting Scala code in IntelliJ


I have Scala code like this:

def myMethod(myInt: Int, myFloat: Float, myString: String): Unit = {
//method body
}
I want to format it exactly like this if the line is too long:

def myMethod(
    myInt: Int,
    myFloat: Float,
    myString: String): Unit = {
    //method body
}
So the caveat is that each parameter has to be in it's own line and needs to indented by 4 spaces. I have tried the Settings > Editor > Code Style > Java, under the "Wrapping and Braces" tab, and selected the "Wrap always" option for "Method declaration parameters". But that doesn't indent the code correctly. Anyway to do this?

评论操作 固定链接

you can use the scalafmt plugin to format scala code, it's much better then the built in code formatter.

https://olafurpg.github.io/scalafmt/

2
评论操作 固定链接

Combination of "wrap always" and "New line after '('" settings on and "align when multiline" setting off for Method declaration parameters will allow the formatting you want with built-in formatter.

0

请先登录再写评论。