[英]intellij code formatting does not indent correctly after a method parameter return (kotlin & Java)
We have some trouble with how the code formatting works when returning after a method parameters call that is not correctly aligned with the above )
. 在与上述错误对齐的方法参数调用后返回时,代码格式化的工作方式会有一些问题(
)
。 In AndroidStudio 3.2.1 currently but it was doing that for as far I can remember. 目前在AndroidStudio 3.2.1中,但据我所知它一直在这样做。 The problem is happening in Kotlin and Java.
问题在Kotlin和Java中发生。
What the AutoFormat does that we don't like. 我们不喜欢自动套用格式的功能。
fun behaviourExample() {
this.methodCall(
lambda1 = { /*something*/ },
lambda2 = { /*somethingElse*/ }
)
.map { "Line incorrectly indented" }
.map { "I'd like the lines to be correctly indented" }
}
fun methodCall(lambda1: () -> Unit, lambda2: () -> Unit): String {
return "otherThing"
}
We would like to find the parameters to change the AutoFormat like this: map{}
correctly aligned with the closing )
我们想找到这样的参数来更改自动套用格式:
map{}
与map{}
正确对齐)
fun behaviourExample() {
this.methodCall(
lambda1 = { /*something*/ },
lambda2 = { /*somethingElse*/ }
)
.map { "Line correctly indented" }
.map { "I'd like the lines to be correctly indented" }
}
What we are doing in the meanwhile is to return before the methodCall
, that's not pretty but that works. 同时,我们正在做的是在
methodCall
之前返回,虽然不是很漂亮,但是可以正常工作。
fun behaviourExample() {
this
.methodCall(
lambda1 = { /*something*/ },
lambda2 = { /*somethingElse*/ }
)
.map { "Line correctly indented but I don't like to be forced to add methodCall() in a new line" }
.map { "I'd like the lines to be correctly indented" }
}
We suspect that it should be somewhere in the preferences -> Code Style -> Kotlin but we played with a bunch of parameters and didn't found it 我们怀疑它应该在首选项中->代码样式-> Kotlin中,但是我们使用了很多参数,却没有找到它
Above is an example of how the autoformat behaves but our problem is with calls like Single.zip()
, Observable.concat()
etc... The indentation misleads where in the chain you can be. 上面是自动格式化行为的示例,但我们的问题出在诸如
Single.zip()
, Observable.concat()
等调用上。缩进会误导您在链中的位置。 So we use it like this. 所以我们这样使用它。
Single
.zip (
/* parameters */
)
.map { /* something */ }
Instead of 代替
Single.zip (
/* parameters */
)
.map { /* something */ }
Thanks for any help or leads. 感谢您的帮助或线索。
The formatting you're using now is actually how such code is supposed to be formatted according to the coding conventions . 您现在使用的格式化实际上就是应该按照编码约定对这种代码进行格式化的方式 。 If the closing parenthesis of a method call is wrapped to a new line, it's aligned with the beginning of the method call.
如果方法调用的右括号被换行换行,则它与方法调用的开始对齐。 There is no option to indent it by 4 spaces.
没有缩进4个空格的选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.