Formatter: fix indent after trailing comma in calls

#KT-36917 Fixed
This commit is contained in:
Dmitry Gridin
2020-02-25 23:50:30 +07:00
parent 1f721796b8
commit ca598b6465
2 changed files with 95 additions and 1 deletions
@@ -277,7 +277,7 @@ abstract class KotlinCommonBlock(
if (parentType === VALUE_PARAMETER_LIST || parentType === VALUE_ARGUMENT_LIST) {
val prev = getPrevWithoutWhitespace(child)
if (childType === RPAR && (prev == null || prev.elementType !== TokenType.ERROR_ELEMENT)) {
if (childType === RPAR && (prev == null || prev.elementType !== COMMA || !hasDoubleLineBreakBefore(child))) {
return Indent.getNoneIndent()
}
@@ -8,8 +8,10 @@
package org.jetbrains.kotlin.idea.editor
import com.intellij.application.options.CodeStyle
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.testFramework.EditorTestUtil
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle
import org.jetbrains.kotlin.idea.formatter.ktCodeStyleSettings
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase
@@ -857,6 +859,98 @@ class TypedHandlerTest : KotlinLightCodeInsightTestCase() {
)
}
private val settingsWithInvertedAlignWhenMultiline = {
val settings = CodeStyleSettings().getCommonSettings(KotlinLanguage.INSTANCE)
settings.ALIGN_MULTILINE_PARAMETERS = !settings.ALIGN_MULTILINE_PARAMETERS
settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = !settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS
enableSmartEnterWithTabs()()
}
fun testSmartEnterWithTabsOnConstructorParametersWithInvertedAlignWhenMultiline() {
doTypeTest(
'\n',
"""
|class A(
| a: Int,<caret>
|)
""",
"""
|class A(
| a: Int,
| <caret>
|)
""",
settingsWithInvertedAlignWhenMultiline
)
}
fun testSmartEnterWithTabsInMethodParametersWithInvertedAlignWhenMultiline() {
doTypeTest(
'\n',
"""
|fun method(
| arg1: String,<caret>
|) {}
""",
"""
|fun method(
| arg1: String,
| <caret>
|) {}
""",
settingsWithInvertedAlignWhenMultiline
)
}
fun testEnterWithoutLineBreakBeforeClosingBracketInMethodParametersWithInvertedAlignWhenMultiline() {
doTypeTest(
'\n',
"""
|fun method(
| arg1: String,<caret>) {}
""",
"""
|fun method(
| arg1: String,
|<caret>) {}
""",
settingsWithInvertedAlignWhenMultiline
)
}
fun testEnterWithTrailingCommaAndWhitespaceBeforeLineBreakWithInvertedAlignWhenMultiline() {
doTypeTest(
'\n',
"""
|fun method(
| arg1: String, <caret>
|) {}
""",
"""
|fun method(
| arg1: String,
| <caret>
|) {}
""",
settingsWithInvertedAlignWhenMultiline
)
}
fun testSmartEnterBetweenOpeningAndClosingBracketsWithInvertedAlignWhenMultiline() {
doTypeTest(
'\n',
"""
|fun method(<caret>) {}
""",
"""
|fun method(
| <caret>
|) {}
""",
settingsWithInvertedAlignWhenMultiline
)
}
fun testAutoIndentInWhenClause() {
doTypeTest(
'\n',