Reputation: 620
This has been bothering me for a while, but I can't seem to figure out how to change this formatting. Let's take a case class as an example:
I prefer two tabs after a line-continuation; however, IntelliJ seems to force this style:
This behavior seems to be controlled by Preferences -> Editor -> Code Style -> Scala -> Other -> Alternate indentation for constructor args and parameter declarations
, which specifies a minimum of 0 spaces, and that simply brings the arg list inline with the opening parentheses. This isn't a big deal by itself, but whenever I copy/paste blocks of code, it reformats everything and I have to go back and shift-tab ad nauseam. Is there a style field that I'm missing somewhere?
Upvotes: 6
Views: 2374
Reputation: 8410
IntelliJ-only, tested in IntelliJ IDEA 2024.3.3 (Ultimate Edition)
In Settings > Editor > Code Style > Scala
...
What worked: Wrapping and Braces > Method declaration parameters > Indent first parameter if on new line
set to false
(unchecked) [default = true
]
What didn't work: Wrapping and Braces > Method declaration parameters > Use normal indent for parameters
set to true
(checked) [default = false
]
Upvotes: 0
Reputation: 545
I just fought this beast and discovered turning this off provided better results:
Upvotes: 0
Reputation: 453
There's an Intellij only solution:
Under Wrapping and Braces
, disable Method declaration parameters > Use normal indent for parameters
.
Then, under Other
, enable Alternate indentation for constructor args and parameter declarations
and set to the number of spaces you want to indent from the declaration level (in your case 4).
Upvotes: 10
Reputation: 852
You can also look into scalari-form plugin. It gives you much more and IDE independent. You are particuliary interested in alignArguments=true and if I remember correctly defaults should make the indentation as you want.
*Note, that it formats code after some sbt task, for instance sbt test
, not when you press Ctrl+Alt+L
or similiar in IntelliJ
Upvotes: 1