@@ -117,35 +117,8 @@ class SqlSetParentGroupProcessor(
117117 )
118118
119119 if (lastGroupBlock is SqlElConditionLoopCommentBlock ) {
120- if (lastGroupBlock.parentBlock != null ) {
121- setParentGroups(context) { history ->
122- return @setParentGroups lastGroupBlock
123- }
124- } else {
125- val history = blockBuilder.getGroupTopNodeIndexHistory()
126- val findParent =
127- history
128- .lastOrNull {
129- it.indent.indentLevel < childBlock.indent.indentLevel ||
130- (it is SqlElConditionLoopCommentBlock && it.parentBlock != null )
131- }
132- // Search for keyword groups with a level lower than or equal to the current level,
133- // or conditional directives that already have a parent assigned.
134- if (findParent is SqlElConditionLoopCommentBlock ) {
135- // Set the parent of the most recent conditional directive to the current node.
136- lastGroupBlock.setParentGroupBlock(findParent)
137- setParentGroups(context) { history ->
138- return @setParentGroups lastGroupBlock
139- }
140- }
141- if (findParent !is SqlElConditionLoopCommentBlock ) {
142- // If a keyword group with a level lower than or equal to the current level is found,
143- // set that keyword group as the parent, and set the parent of the most recent conditional directive to the current node.
144- setParentGroups(context) { history ->
145- return @setParentGroups findParent
146- }
147- lastGroupBlock.setParentGroupBlock(childBlock)
148- }
120+ updateParentGroupLastConditionLoop(lastGroupBlock, context, childBlock) {
121+ it.indent.indentLevel < childBlock.indent.indentLevel
149122 }
150123 return
151124 }
@@ -319,6 +292,15 @@ class SqlSetParentGroupProcessor(
319292 }
320293 return
321294 }
295+
296+ val lastGroupBlock = blockBuilder.getLastGroupTopNodeIndexHistory()
297+ if (lastGroupBlock is SqlElConditionLoopCommentBlock ) {
298+ updateParentGroupLastConditionLoop(lastGroupBlock, context, childBlock) {
299+ it.indent.indentLevel == IndentType .INLINE_SECOND
300+ }
301+ return
302+ }
303+
322304 val inlineSecondIndex =
323305 blockBuilder.getGroupTopNodeIndex { block ->
324306 block.indent.indentLevel == IndentType .INLINE_SECOND
@@ -331,6 +313,47 @@ class SqlSetParentGroupProcessor(
331313 )
332314 }
333315
316+ /* *
317+ * Updates the parent of the last conditional directive block and sets the parent of the current block.
318+ */
319+ private fun updateParentGroupLastConditionLoop (
320+ lastGroupBlock : SqlElConditionLoopCommentBlock ,
321+ context : SetParentContext ,
322+ childBlock : SqlBlock ,
323+ findDefaultParent : (SqlBlock ) -> Boolean ,
324+ ) {
325+ if (lastGroupBlock.parentBlock != null ) {
326+ setParentGroups(context) { history ->
327+ return @setParentGroups lastGroupBlock
328+ }
329+ } else {
330+ val history = blockBuilder.getGroupTopNodeIndexHistory()
331+ val findParent =
332+ history
333+ .lastOrNull { block ->
334+ findDefaultParent(block) ||
335+ (block is SqlElConditionLoopCommentBlock && block.parentBlock != null )
336+ }
337+ // Search for keyword groups with a level lower than or equal to the current level,
338+ // or conditional directives that already have a parent assigned.
339+ if (findParent is SqlElConditionLoopCommentBlock ) {
340+ // Set the parent of the most recent conditional directive to the current node.
341+ lastGroupBlock.setParentGroupBlock(findParent)
342+ setParentGroups(context) { history ->
343+ return @setParentGroups lastGroupBlock
344+ }
345+ }
346+ if (findParent !is SqlElConditionLoopCommentBlock ) {
347+ // If a keyword group with a level lower than or equal to the current level is found,
348+ // set that keyword group as the parent, and set the parent of the most recent conditional directive to the current node.
349+ setParentGroups(context) { history ->
350+ return @setParentGroups findParent
351+ }
352+ lastGroupBlock.setParentGroupBlock(childBlock)
353+ }
354+ }
355+ }
356+
334357 fun updateConditionLoopCommentBlockParent (
335358 lastGroupBlock : SqlBlock ,
336359 childBlock : SqlElConditionLoopCommentBlock ,
0 commit comments