IntelliJ Scala Plugin的case类缩进很荒谬 [英] IntelliJ Scala Plugin's case class indentation is absurd

查看:34
本文介绍了IntelliJ Scala Plugin的case类缩进很荒谬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个 case 类有很多字段并且它们的名字很长时,将每个字段写在每一行中通常是一个好主意:

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
)

这类似于 C/C++ struct 定义并且即使在 case 类变大时也完全可读.但是 IntelliJ IDEA 的默认 Scala 插件会自动更改其缩进:

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
                    )

这对我来说看起来很奇怪,但 Scala 风格指南没有提及有关案例类缩进的任何内容.

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

我在 IDE 设置中找不到任何可以改变这种行为的东西.是否可以选择使自动缩进像我上面描述的那样工作或禁用案例类的自动缩进?

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?

推荐答案

Try File -> Settings... -> Code Style -> Scala

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":

  • 勾选对参数使用正常缩进"
  • 取消选中多行时对齐"

这会将其更改为您提供的示例.

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.

这篇关于IntelliJ Scala Plugin的case类缩进很荒谬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆