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
|
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(
|
fun NodeIndentStrategy.PositionStrategy.continuationIf(
|
||||||
option: (KotlinCodeStyleSettings) -> Boolean,
|
option: (KotlinCodeStyleSettings) -> Boolean,
|
||||||
indentFirst: Boolean = false
|
indentFirst: Boolean = false
|
||||||
@@ -909,8 +915,10 @@ private fun getAlignmentForChildInParenthesis(
|
|||||||
val childNodeType = node.elementType
|
val childNodeType = node.elementType
|
||||||
|
|
||||||
val prev = getPrevWithoutWhitespace(node)
|
val prev = getPrevWithoutWhitespace(node)
|
||||||
if (prev != null && prev.elementType === TokenType.ERROR_ELEMENT || childNodeType === TokenType.ERROR_ELEMENT) {
|
val hasTrailingComma = childNodeType === closeBracket && prev?.elementType == COMMA
|
||||||
// Prefer align to parameters on incomplete code (case of line break after comma, when next parameters is absent)
|
|
||||||
|
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
|
return parameterAlignment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -783,7 +783,7 @@ class TypedHandlerTest : KotlinLightCodeInsightTestCase() {
|
|||||||
"""
|
"""
|
||||||
|class A(
|
|class A(
|
||||||
| a: Int,
|
| a: Int,
|
||||||
|<caret>
|
| <caret>
|
||||||
|)
|
|)
|
||||||
""",
|
""",
|
||||||
enableSmartEnterWithTabs()
|
enableSmartEnterWithTabs()
|
||||||
@@ -801,7 +801,56 @@ class TypedHandlerTest : KotlinLightCodeInsightTestCase() {
|
|||||||
"""
|
"""
|
||||||
|fun method(
|
|fun method(
|
||||||
| arg1: String,
|
| 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()
|
enableSmartEnterWithTabs()
|
||||||
|
|||||||
Reference in New Issue
Block a user