ChatGPT解决这个技术问题 Extra ChatGPT

IntelliJ Scala Plugin's case class indentation is absurd

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?

Indentation in class definitions described here: docs.scala-lang.org/style/declarations.html They say 4 spaces needed on new line.
@red1ynx Do you know how to do that?
Here is an issue addressing that youtrack.jetbrains.com/issue/SCL-4167. Go there and vote if you don't like this behaviour.

i
ingara

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.


I think you also have to disable "Align when multiline".
What if I want to 4 spaces before it?
Just change the Indent to 4
@BinWang: Uncheck "use normal indent for parameters" and "Align when multiline" and set "Continuation indent" to 4 under "Tabs and Indent"
If you want 4 spaces indent (according to Scala style guides) in 'File -> Settings... -> Code Style -> Scala -> Other' check 'Alternate indentation for constructor args and parameter declarations' with 4