[英]Intellij IDEA reformat scala code
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: 如果我的Scala方法声明太长而无法放在一行中,我会将其分成几行,我的格式期望是:
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: 但是在重新格式化代码(
control + alt + L
)之后,输出为:
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? 应该设置为覆盖默认行为并获得所需的输出样式的intellij idea中适合于scala lang的正确代码样式规则是什么?
Edit 编辑
deselect the Align when multiline
would result in: 取消选择
Align when multiline
将导致:
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) 参数和方法主体将具有相同的缩进(2个空格),而不是所需的缩进:具有两个缩进(4个空格)的参数列表,仅具有一个缩进(2个空格)的方法列表
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. 您可能要取消选择“
Preferences
菜单的Scala
部分“ Wrapping and Braces
选项卡中“ Method declaration parameters
部分中的“ Align when multiline
Preferences
选项。 You might also want to set the wrapping option in that same section to Warp if long
. Warp if long
,您可能还希望将同一部分中的包装选项设置为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. 为了获得所需的选项卡,您需要在“
Tabs and Indents
选项卡上将“ Continuation indent
设置为4,并将“ Indent
为2。
I recommend you to use Scalariform it is is a code formatter for Scala. 我建议您使用Scalariform,它是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. 计划是在人们要求时添加首选项和功能,因此,如果它没有按照您希望的方式格式化代码,请提出Github问题,我将拭目以待。
Scalariform is licenced under The MIT Licence. Scalariform已根据MIT许可证获得许可。
If you use sbt, add this to your project/plugins.sbt 如果您使用sbt,请将其添加到您的project / plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0") 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, 这是所有信息,这是在他的激活器模板中使用类型安全的信息,
scalriform github scalriform github
https://github.com/sbt/sbt-scalariform https://github.com/sbt/sbt-scalariform
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.