Skip to content

Commit 691ab91

Browse files
committed
Reflect the fix for the overwritten line-break control in conditional directives.
1 parent e3084a7 commit 691ab91

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlBlock.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,16 @@ open class SqlBlock(
135135
prevBlock is SqlElConditionLoopCommentBlock &&
136136
(prevBlock.conditionType.isElse() || prevBlock.conditionType.isEnd())
137137
val hasNoChildrenExceptLast = parent.childBlocks.dropLast(1).isEmpty()
138+
if (parent.conditionType.isElse()) {
139+
return prevBlocks.isEmpty()
140+
}
141+
142+
val isConditionDirectiveParentGroup =
143+
parent.parentBlock?.let { grand ->
144+
grand is SqlNewGroupBlock
145+
} == true
138146

139-
return isPrevBlockElseOrEnd || hasNoChildrenExceptLast
147+
return isPrevBlockElseOrEnd || (hasNoChildrenExceptLast && isConditionDirectiveParentGroup)
140148
}
141149

142150
private fun shouldSaveSpaceForNewGroup(parent: SqlNewGroupBlock): Boolean {

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/condition/SqlConditionalExpressionGroupBlock.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.formatter.block.group.keyword.condition
1717

1818
import com.intellij.lang.ASTNode
1919
import org.domaframework.doma.intellij.formatter.block.SqlBlock
20+
import org.domaframework.doma.intellij.formatter.block.comment.SqlElConditionLoopCommentBlock
2021
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
2122
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlSubGroupBlock
2223
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
@@ -45,7 +46,15 @@ class SqlConditionalExpressionGroupBlock(
4546
}
4647
}
4748

48-
override fun createBlockIndentLen(): Int = parentBlock?.indent?.groupIndentLen?.plus(1) ?: 1
49+
override fun createBlockIndentLen(): Int =
50+
parentBlock?.let { parent ->
51+
if (parent is SqlElConditionLoopCommentBlock) {
52+
parent.indent.groupIndentLen
53+
} else {
54+
parent.indent.groupIndentLen.plus(1)
55+
}
56+
}
57+
?: offset
4958

5059
override fun createGroupIndentLen(): Int = indent.indentLen.plus(1)
5160
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/subgroup/SqlSubGroupBlock.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ abstract class SqlSubGroupBlock(
5050
SqlWithCommonTableGroupBlock::class,
5151
SqlWithColumnGroupBlock::class,
5252
SqlCreateViewGroupBlock::class,
53+
SqlElConditionLoopCommentBlock::class,
5354
)
5455
}
5556

0 commit comments

Comments
 (0)