Skip to content

Commit e91eb26

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

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,14 @@ 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+
firstConditionBlock?.conditionEnd
142+
?: (
143+
firstConditionBlock?.childBlocks?.lastOrNull {
144+
it is SqlElConditionLoopCommentBlock
145+
} as? SqlElConditionLoopCommentBlock
146+
)?.conditionEnd
141147
if (endBlock == null) return false
142148
val lastBlock = prevBlocks.lastOrNull()
143149

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)