Formatter: fix indent after trailing comma in calls
#KT-36917 Fixed
This commit is contained in:
@@ -277,7 +277,7 @@ abstract class KotlinCommonBlock(
|
|||||||
|
|
||||||
if (parentType === VALUE_PARAMETER_LIST || parentType === VALUE_ARGUMENT_LIST) {
|
if (parentType === VALUE_PARAMETER_LIST || parentType === VALUE_ARGUMENT_LIST) {
|
||||||
val prev = getPrevWithoutWhitespace(child)
|
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()
|
return Indent.getNoneIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,10 @@
|
|||||||
package org.jetbrains.kotlin.idea.editor
|
package org.jetbrains.kotlin.idea.editor
|
||||||
|
|
||||||
import com.intellij.application.options.CodeStyle
|
import com.intellij.application.options.CodeStyle
|
||||||
|
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||||
import com.intellij.testFramework.EditorTestUtil
|
import com.intellij.testFramework.EditorTestUtil
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
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.KotlinStyleGuideCodeStyle
|
||||||
import org.jetbrains.kotlin.idea.formatter.ktCodeStyleSettings
|
import org.jetbrains.kotlin.idea.formatter.ktCodeStyleSettings
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase
|
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() {
|
fun testAutoIndentInWhenClause() {
|
||||||
doTypeTest(
|
doTypeTest(
|
||||||
'\n',
|
'\n',
|
||||||
|
|||||||
Reference in New Issue
Block a user