IntelliJ Scala Plugin's case class indentation is absurd

梦想的初衷 提交于 2019-11-27 09:04:55

问题


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 class Person (
  name: String,
  age: Int
)

This resembles C/C++ struct definition and totally readable even when the case class becomes bigger. But IntelliJ IDEA's default Scala plugin automatically changes its indentation:

case class Person (
                    name: String,
                    age: Int
                    )

which looks weird to me, but the Scala Style Guide doesn't mention anything about case class indentation.

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?


回答1:


Try File -> Settings... -> Code Style -> 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.



来源:https://stackoverflow.com/questions/26880677/intellij-scala-plugins-case-class-indentation-is-absurd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!