@@ -24,8 +24,11 @@ import com.intellij.formatting.Spacing
2424import com.intellij.formatting.SpacingBuilder
2525import com.intellij.formatting.Wrap
2626import com.intellij.lang.ASTNode
27+ import com.intellij.psi.PsiElement
2728import com.intellij.psi.PsiWhiteSpace
2829import com.intellij.psi.formatter.common.AbstractBlock
30+ import com.intellij.psi.util.PsiTreeUtil
31+ import com.intellij.psi.util.elementType
2932import org.domaframework.doma.intellij.common.util.TypeUtil
3033import org.domaframework.doma.intellij.formatter.block.comma.SqlCommaBlock
3134import org.domaframework.doma.intellij.formatter.block.comment.SqlCommentBlock
@@ -262,15 +265,23 @@ open class SqlFileBlock(
262265 child,
263266 createBlockDirectiveCommentSpacingBuilder(),
264267 )
265- if (tempBlock !is SqlElConditionLoopCommentBlock ) {
266- if (lastGroup is SqlWithQueryGroupBlock || lastGroupFilteredDirective is SqlWithQueryGroupBlock ) {
267- return SqlWithCommonTableGroupBlock (child, defaultFormatCtx)
268+ val commentType = PsiTreeUtil .getChildrenOfType(child.psi, PsiElement ::class .java)?.get(1 )?.elementType
269+ val defaultBlockComment =
270+ commentType == SqlTypes .EL_PARSER_LEVEL_COMMENT || commentType == SqlTypes .BLOCK_COMMENT_CONTENT ||
271+ child.elementType == SqlTypes .LINE_COMMENT
272+ if (! defaultBlockComment) {
273+ if (tempBlock !is SqlElConditionLoopCommentBlock ) {
274+ if (lastGroup is SqlWithQueryGroupBlock || lastGroupFilteredDirective is SqlWithQueryGroupBlock ) {
275+ return SqlWithCommonTableGroupBlock (child, defaultFormatCtx)
276+ }
277+ }
278+ return if (lastGroup is SqlWithCommonTableGroupBlock ) {
279+ SqlWithCommonTableGroupBlock (child, defaultFormatCtx)
280+ } else {
281+ tempBlock
268282 }
269- }
270- return if (lastGroup is SqlWithCommonTableGroupBlock ) {
271- SqlWithCommonTableGroupBlock (child, defaultFormatCtx)
272283 } else {
273- tempBlock
284+ return tempBlock
274285 }
275286 }
276287
0 commit comments