IDE formatting: add indention for new line in parameters list when there is a trailing comma
This commit is contained in:
@@ -664,6 +664,12 @@ private fun hasLineBreakBefore(node: ASTNode): Boolean {
|
||||
return prevSibling?.elementType == TokenType.WHITE_SPACE && prevSibling?.textContains('\n') == true
|
||||
}
|
||||
|
||||
private fun hasDoubleLineBreakBefore(node: ASTNode): Boolean {
|
||||
val prevSibling = node.leaves(false).firstOrNull() ?: return false
|
||||
|
||||
return prevSibling.text.count { it == '\n' } >= 2
|
||||
}
|
||||
|
||||
fun NodeIndentStrategy.PositionStrategy.continuationIf(
|
||||
option: (KotlinCodeStyleSettings) -> Boolean,
|
||||
indentFirst: Boolean = false
|
||||
@@ -909,8 +915,10 @@ private fun getAlignmentForChildInParenthesis(
|
||||
val childNodeType = node.elementType
|
||||
|
||||
val prev = getPrevWithoutWhitespace(node)
|
||||
if (prev != null && prev.elementType === TokenType.ERROR_ELEMENT || childNodeType === TokenType.ERROR_ELEMENT) {
|
||||
// Prefer align to parameters on incomplete code (case of line break after comma, when next parameters is absent)
|
||||
val hasTrailingComma = childNodeType === closeBracket && prev?.elementType == COMMA
|
||||
|
||||
if (hasTrailingComma && hasDoubleLineBreakBefore(node)) {
|
||||
// Prefer align to parameters on code with trailing comma (case of line break after comma, when before closing bracket there was a line break)
|
||||
return parameterAlignment
|
||||
}
|
||||
|
||||
|
||||
@@ -783,7 +783,7 @@ class TypedHandlerTest : KotlinLightCodeInsightTestCase() {
|
||||
"""
|
||||
|class A(
|
||||
| a: Int,
|
||||
|<caret>
|
||||
| <caret>
|
||||
|)
|
||||
""",
|
||||
enableSmartEnterWithTabs()
|
||||
@@ -801,7 +801,56 @@ class TypedHandlerTest : KotlinLightCodeInsightTestCase() {
|
||||
"""
|
||||
|fun method(
|
||||
| arg1: String,
|
||||
|<caret>
|
||||
| <caret>
|
||||
|) {}
|
||||
""",
|
||||
enableSmartEnterWithTabs()
|
||||
)
|
||||
}
|
||||
|
||||
fun testEnterWithoutLineBreakBeforeClosingBracketInMethodParameters() {
|
||||
doTypeTest(
|
||||
'\n',
|
||||
"""
|
||||
|fun method(
|
||||
| arg1: String,<caret>) {}
|
||||
""",
|
||||
"""
|
||||
|fun method(
|
||||
| arg1: String,
|
||||
|<caret>) {}
|
||||
""",
|
||||
enableSmartEnterWithTabs()
|
||||
)
|
||||
}
|
||||
|
||||
fun testEnterWithTrailingCommaAndWhitespaceBeforeLineBreak() {
|
||||
doTypeTest(
|
||||
'\n',
|
||||
"""
|
||||
|fun method(
|
||||
| arg1: String, <caret>
|
||||
|) {}
|
||||
""",
|
||||
"""
|
||||
|fun method(
|
||||
| arg1: String,
|
||||
| <caret>
|
||||
|) {}
|
||||
""",
|
||||
enableSmartEnterWithTabs()
|
||||
)
|
||||
}
|
||||
|
||||
fun testSmartEnterBetweenOpeningAndClosingBrackets() {
|
||||
doTypeTest(
|
||||
'\n',
|
||||
"""
|
||||
|fun method(<caret>) {}
|
||||
""",
|
||||
"""
|
||||
|fun method(
|
||||
| <caret>
|
||||
|) {}
|
||||
""",
|
||||
enableSmartEnterWithTabs()
|
||||
|
||||
Reference in New Issue
Block a user