File tree Expand file tree Collapse file tree 2 files changed +16
-18
lines changed
src/main/kotlin/org/domaframework/doma/intellij/formatter/block Expand file tree Collapse file tree 2 files changed +16
-18
lines changed Original file line number Diff line number Diff line change @@ -360,8 +360,19 @@ open class SqlBlock(
360360 protected fun calculatePrevBlocksLength (
361361 children : List <SqlBlock >,
362362 parent : SqlBlock ,
363- ): Int =
364- children
363+ ): Int {
364+ // Add the parent's text length to the indentation if the parent is a conditional loop directive.
365+ val directiveParentIndent =
366+ if (parent is SqlElConditionLoopCommentBlock ) {
367+ parent.parentBlock
368+ ?.getNodeText()
369+ ?.length ? : 0
370+ } else {
371+ 0
372+ }
373+
374+ return children
375+ .filter { it !is SqlDefaultCommentBlock && it !is SqlElConditionLoopCommentBlock }
365376 .sumOf { prev ->
366377 prev
367378 .getChildrenTextLen()
@@ -375,6 +386,8 @@ open class SqlBlock(
375386 },
376387 )
377388 }.plus(parent.indent.groupIndentLen)
389+ .plus(directiveParentIndent)
390+ }
378391
379392 /* *
380393 * Returns the child indentation for the block.
Original file line number Diff line number Diff line change @@ -17,12 +17,10 @@ package org.domaframework.doma.intellij.formatter.block.group.keyword.option
1717
1818import com.intellij.lang.ASTNode
1919import org.domaframework.doma.intellij.formatter.block.SqlBlock
20- import org.domaframework.doma.intellij.formatter.block.comment.SqlDefaultCommentBlock
2120import org.domaframework.doma.intellij.formatter.block.comment.SqlElConditionLoopCommentBlock
2221import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
2322import org.domaframework.doma.intellij.formatter.util.IndentType
2423import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
25- import org.domaframework.doma.intellij.psi.SqlTypes
2624
2725class SqlInGroupBlock (
2826 node : ASTNode ,
@@ -45,20 +43,7 @@ class SqlInGroupBlock(
4543 ) {
4644 return parent.indent.indentLen
4745 }
48- val prevChildren = this .prevBlocks
49- val children = prevChildren.filter { it !is SqlDefaultCommentBlock }
50- val firstChild = children.firstOrNull()
51- val sumChildren =
52- if (firstChild is SqlElConditionLoopCommentBlock ) {
53- children.drop(1 ).dropLastWhile { it == this }
54- } else {
55- children
56- }
57-
58- val dotCount = sumChildren.count { it.node.elementType == SqlTypes .DOT }
59- val parentText = prevChildren.dropLast(1 ).filter { it !is SqlDefaultCommentBlock }
60-
61- return calculatePrevBlocksLength(parentText, parent)
46+ return calculatePrevBlocksLength(prevBlocks, parent).plus(1 )
6247 }
6348 return 0
6449 }
You can’t perform that action at this time.
0 commit comments