简体   繁体   English

IntelliJ Idea:对齐 Scala 案例类成员的冒号?

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

Is there a way to prevent Idea from reformatting multiline case class members?有没有办法阻止 Idea 重新格式化多行案例类成员?

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:我花了一些时间在 Scala 的代码样式设置中,并且坚持使用这样的代码样式:

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.我可以用@formatter:off弄乱代码,但如果有更好的方法,那就太棒了。

Just like Madoc commented, those kind of formats may lead to huge changes when adding a new line.就像 Madoc 评论的那样,在添加新行时,这些格式可能会导致巨大的变化。 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我的 IntelliJ IDEA 版本是终极版 2019.3

step 1. Prefrences -> Editor -> Code Style -> Scala步骤 1. 首选项 -> 编辑器 -> 代码样式 -> Scala

斯卡拉斯

step 2. Wrapping and Braces -> Method declaration parameters, then check "Align paramenter types in multiline declarations"步骤 2. 包装和大括号 -> 方法声明参数,然后选中“在多行声明中对齐参数类型”

宣言

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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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