IntelliJ Scala Plugin的case类缩进很荒谬
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26880677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ Scala Plugin's case class indentation is absurd
提问by lyomi
When a case class has many fields and their names are long, it is often a good idea to write each field in each line like:
当一个 case 类有很多字段并且它们的名字很长时,将每个字段写在每一行中通常是个好主意,例如:
case class Person (
name: String,
age: Int
)
This resembles C/C++ structdefinition and totally readable even when the case class becomes bigger. But IntelliJ IDEA's default Scala plugin automatically changes its indentation:
这类似于 C/C++struct定义并且即使在 case 类变大时也完全可读。但是 IntelliJ IDEA 的默认 Scala 插件会自动更改其缩进:
case class Person (
name: String,
age: Int
)
which looks weird to me, but the Scala Style Guidedoesn't mention anything about case class indentation.
这对我来说看起来很奇怪,但Scala 风格指南没有提到任何关于案例类缩进的内容。
I couldn't find anything in the IDE settings that can change this behaviour. Is there an option to make the auto-indentation work like the way I described above or disable auto-indentation for case classes?
我在 IDE 设置中找不到任何可以改变这种行为的东西。是否可以选择使自动缩进像我上面描述的那样工作或禁用案例类的自动缩进?
回答by Micho
Try File -> Settings... -> Code Style -> Scala
尝试文件 -> 设置... -> 代码样式 -> Scala
There are lots of settings to customize your code formatting in there.
有很多设置可以自定义您的代码格式。
In the "Wrapping and Braces" tab, under "Method declaration parameters":
在“环绕和大括号”选项卡中的“方法声明参数”下:
- check "use normal indent for parameters"
- uncheck "Align when multiline"
- 勾选“对参数使用正常缩进”
- 取消选中“多行时对齐”
This will change it to the example you provided.
这会将其更改为您提供的示例。
If you want it to use the indenting in "Continuation indent" under "Tabs and Indent" you have to have both of the option above unchecked.
如果您希望它在“制表符和缩进”下的“连续缩进”中使用缩进,则必须取消选中上述两个选项。

