简体   繁体   中英

IntelliJ Idea: Align on Colon for Scala Case Class Members?

Is there a way to prevent Idea from reformatting multiline case class members?

Intended result
(position of the colon is not so important, but the alignment of the type annotations would be great)

case class ApiError(
  timestamp : LocalDateTime,
  status    : Int,
  code      : Option[String],
  message   : String
)

I've spent some time in the Code Styling settings for Scala and am stuck with code styling like this:

case class ApiError(
  timestamp: LocalDateTime,
  status: Int,
  code: Option[String],
  message: String
)

I am okay with cluttering the code with @formatter:off , but it would be awesome if there was a better way.

Just like Madoc commented, those kind of formats may lead to huge changes when adding a new line. Also, while pretty in small cases, it doesn't scale, and it seems we are programming in tables...

my IntelliJ IDEA version is ultimate 2019.3

step 1. Prefrences -> Editor -> Code Style -> Scala

斯卡拉斯

step 2. Wrapping and Braces -> Method declaration parameters, then check "Align paramenter types in multiline declarations"

宣言

I tried the example in question, it was

case class ApiError(
                     timestamp: LocalDateTime,
                     status   : Int,
                     code     : Option[String],
                     message  : String
                   )

if you uncheck "Align when multiline", it is consistent with intended result.

多行时对齐

case class ApiError(
  timestamp: LocalDateTime,
  status   : Int,
  code     : Option[String],
  message  : String
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM