Skip to content

Commit 08ff1fe

Browse files
committed
Fix indent calculation logic for combined IN clause and subquery
1 parent ab0a522 commit 08ff1fe

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/option/SqlInGroupBlock.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ class SqlInGroupBlock(
4040

4141
override fun createBlockIndentLen(): Int {
4242
parentBlock?.let { parent ->
43-
if (parent is SqlElConditionLoopCommentBlock) return parent.indent.groupIndentLen
43+
if (parent is SqlElConditionLoopCommentBlock &&
44+
parent.checkConditionLoopDirectiveParentBlock(this)
45+
) {
46+
return parent.indent.indentLen
47+
}
4448
val prevChildren = this.prevBlocks
4549
val children = prevChildren.filter { it !is SqlDefaultCommentBlock }
4650
val firstChild = children.firstOrNull()
@@ -52,13 +56,16 @@ class SqlInGroupBlock(
5256
}
5357

5458
val dotCount = sumChildren.count { it.node.elementType == SqlTypes.DOT }
59+
val parentText = (parent as? SqlElConditionLoopCommentBlock)?.parentBlock?.getNodeText()?.length ?: 0
60+
5561
return sumChildren
5662
.sumOf { prev ->
5763
prev
5864
.getChildrenTextLen()
5965
.plus(prev.getNodeText().length.plus(1))
6066
}.minus(dotCount * 2)
6167
.plus(parent.indent.groupIndentLen)
68+
.plus(parentText)
6269
.plus(1)
6370
}
6471
return 0

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.domaframework.doma.intellij.formatter.block.SqlBlock
2121
import org.domaframework.doma.intellij.formatter.block.comment.SqlDefaultCommentBlock
2222
import org.domaframework.doma.intellij.formatter.block.comment.SqlElConditionLoopCommentBlock
2323
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlJoinGroupBlock
24+
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
2425
import org.domaframework.doma.intellij.formatter.block.group.keyword.condition.SqlConditionalExpressionGroupBlock
2526
import org.domaframework.doma.intellij.formatter.block.group.keyword.top.SqlJoinQueriesGroupBlock
2627
import org.domaframework.doma.intellij.formatter.block.group.keyword.with.SqlWithCommonTableGroupBlock
@@ -65,7 +66,11 @@ open class SqlSubQueryGroupBlock(
6566
is SqlJoinQueriesGroupBlock -> return parent.indent.indentLen
6667
is SqlJoinGroupBlock -> return parent.indent.groupIndentLen.plus(1)
6768
else -> {
68-
val children = prevChildren?.filter { it !is SqlDefaultCommentBlock }
69+
val children =
70+
prevChildren?.filter {
71+
it !is SqlDefaultCommentBlock &&
72+
(parent as? SqlKeywordGroupBlock)?.topKeywordBlocks?.contains(it) == false
73+
}
6974
// Retrieve the list of child blocks excluding the conditional directive that appears immediately before this block,
7075
// as it is already included as a child block.
7176
val sumChildren =

0 commit comments

Comments
 (0)