Reputation: 6693
If I have a Scala method declaration too long to fit in a single line, I would separate it in several lines, and my reformat expectations is:
protected def pruneFilterProject(
relation: LogicalRelation,
projectList: Seq[NamedExpression],
filterPredicates: Seq[Expression],
scanBuilder: (Array[String], Array[Filter]) => RDD[Row]) = {
pruneFilterProjectRaw(
relation,
projectList,
filterPredicates,
(requestedColumns, pushedFilters) => {
scanBuilder(requestedColumns.map(_.name).toArray, selectFilters(pushedFilters).toArray)
})
}
But after Reformat Code(control + alt + L
), the output is:
protected def pruneFilterProject(
relation: LogicalRelation,
projectList: Seq[NamedExpression],
filterPredicates: Seq[Expression],
scanBuilder: (Array[String], Array[Filter]) => RDD[Row]) = {
pruneFilterProjectRaw(
relation,
projectList,
filterPredicates,
(requestedColumns, pushedFilters) => {
scanBuilder(requestedColumns.map(_.name).toArray, selectFilters(pushedFilters).toArray)
})
}
What are proper code style rules in intellij idea for scala lang should I set to override the default behaviour and get my desired output style?
Edit
deselect the Align when multiline
would result in:
protected def pruneFilterProject(
relation: LogicalRelation,
projectList: Seq[NamedExpression],
filterPredicates: Seq[Expression],
scanBuilder: (Array[String], Array[Filter]) => RDD[Row]) = {
pruneFilterProjectRaw(
relation,
projectList,
filterPredicates,
(requestedColumns, pushedFilters) => {
scanBuilder(requestedColumns.map(_.name).toArray, selectFilters(pushedFilters).toArray)
})
}
Arguments and method body would have same indention(2 space), not the desired one: argument list with two indents(4 space), method list with only one indent(2 space)
Upvotes: 2
Views: 1693
Reputation: 16324
You might want to deselect the Align when multiline
option in the Method declaration parameters
section in the Wrapping and Braces
tab in the Scala
part of the Preferences
menu. You might also want to set the wrapping option in that same section to Warp if long
.
In order to then get the tabs like you want, you want to set Continuation indent
to 4 and Indent
to 2 on the Tabs and Indents
tab.
Upvotes: 2
Reputation: 11522
I recommend you to use Scalariform it is is a code formatter for Scala. It's available as a library, a stand-alone command line tool, or via integrations with various editors and build tools (listed below).
The plan is to add preferences and features as and when people ask for them, so please do raise a Github issue if it doesn't format your code the way you'd like it, and I'll see what I can do.
Scalariform is licenced under The MIT Licence.
If you use sbt, add this to your project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")
here is all the information, it is the one that use typesafe in his activator templates,
https://github.com/sbt/sbt-scalariform
Upvotes: 2