IntelliJ Scala插件的案例类缩进是荒谬的 [英] IntelliJ Scala Plugin's case class indentation is absurd

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

问题描述

当案例类具有许多字段并且它们的名称很长时,通常最好将每一行中的每个字段都写成这样:

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?

推荐答案

尝试文件->设置...->代码样式-> 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插件的案例类缩进是荒谬的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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