Skip to content

Commit bf12380

Browse files
committed
Fixed the problem that the last column line was not broken
1 parent a6fbb54 commit bf12380

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,25 @@ open class SqlBlock(
136136
.firstOrNull()
137137
?.childBlocks
138138

139-
val firstConditionBlock = (prevChildren?.firstOrNull() as? SqlElConditionLoopCommentBlock)
140-
val endBlock = firstConditionBlock?.conditionEnd
139+
val firstConditionBlock = prevChildren?.firstOrNull { it is SqlElConditionLoopCommentBlock } as? SqlElConditionLoopCommentBlock
140+
val endBlock =
141+
findConditionEndBlock(firstConditionBlock)
141142
if (endBlock == null) return false
142143
val lastBlock = prevBlocks.lastOrNull()
143144

144145
return endBlock.node.startOffset > (lastBlock?.node?.startOffset ?: 0)
145146
}
146147

148+
private fun findConditionEndBlock(firstConditionBlock: SqlElConditionLoopCommentBlock?): SqlElConditionLoopCommentBlock? =
149+
(
150+
firstConditionBlock?.conditionEnd
151+
?: (
152+
firstConditionBlock?.childBlocks?.lastOrNull {
153+
it is SqlElConditionLoopCommentBlock
154+
} as? SqlElConditionLoopCommentBlock
155+
)?.conditionEnd
156+
)
157+
147158
protected fun isFirstChildConditionLoopDirective(): Boolean = childBlocks.firstOrNull() is SqlElConditionLoopCommentBlock
148159

149160
fun getChildBlocksDropLast(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class SqlElConditionLoopCommentBlock(
137137
}
138138

139139
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
140-
if (lastGroup is SqlElConditionLoopCommentBlock && conditionType.isEnd()) {
140+
if (lastGroup is SqlElConditionLoopCommentBlock && !conditionType.isStartDirective()) {
141141
lastGroup.conditionEnd = this
142142
}
143143
}
@@ -195,7 +195,7 @@ class SqlElConditionLoopCommentBlock(
195195
is SqlSubGroupBlock -> return calculateSubGroupBlockIndent(parent, openConditionLoopDirectiveCount)
196196

197197
is SqlElConditionLoopCommentBlock -> {
198-
if (conditionType.isEnd()) {
198+
if (!conditionType.isStartDirective()) {
199199
parent.conditionEnd = this
200200
conditionStart = parent
201201
return parent.indent.indentLen

src/test/testData/sql/formatter/CalculationDirectives.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ SELECT employee_id
33
, salary
44
, salary * /* yearBonusRate */1.2 AS yearly_bonus
55
, salary + (salary * /* @raiseRate() */0.05) AS new_salary
6+
, /*%if parent*/
7+
number1.d,
8+
/*%else*/
9+
number2.e,
10+
/*%end*/ number.x
611
FROM employee
712
WHERE department_id = /* departmentId */1
813
/*%if @minSalary() +extraAmount*/

src/test/testData/sql/formatter/CalculationDirectives_format.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ SELECT employee_id
33
, salary
44
, salary * /* yearBonusRate */1.2 AS yearly_bonus
55
, salary + (salary * /* @raiseRate() */0.05) AS new_salary
6+
, /*%if parent*/
7+
number1.d
8+
,
9+
/*%else*/
10+
number2.e
11+
,
12+
/*%end*/
13+
number.x
614
FROM employee
715
WHERE department_id = /* departmentId */1
816
/*%if @minSalary() + extraAmount*/

0 commit comments

Comments
 (0)