Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 1, 2025

Description

This PR addresses issue #353 by improving SQL formatting behavior for multiple CASE expressions and enhancing overall SQL formatting consistency.

Related Issues

Fixes #353

Changes

  1. Enhanced spacing rules within field blocks - Improved the implementation of spacing rules to ensure consistent formatting within SQL field blocks
  2. Improved line-breaking and indentation behavior - Enhanced line-breaking logic and indentation to provide better readability for complex SQL statements
  3. Added parent-child relationship validation - Implemented a method to validate parent-child relationships to determine appropriate
    line-breaking behavior
  4. Block comment handling - Ensured that line breaks are always inserted before block comments for better code organization
  5. Refactored block relationship management - Changed the class responsible for setting block parent-child relationships to a builder pattern for better maintainability

@xterao xterao self-assigned this Aug 1, 2025
@xterao xterao added bug Something isn't working formatter labels Aug 1, 2025
@xterao xterao requested a review from Copilot August 1, 2025 07:34
@github-actions github-actions bot added the fix Bug fixes label Aug 1, 2025
@xterao xterao linked an issue Aug 1, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances SQL formatting behavior to improve support for multiple CASE expressions and overall SQL formatting consistency. The changes focus on upgrading the formatter's handling of spacing, line-breaking, indentation, and block relationships.

  • Improved SQL formatting for multiple CASE expressions and various SQL directive patterns
  • Enhanced block relationship management using a builder pattern
  • Better handling of conditional directives and comment block formatting

Reviewed Changes

Copilot reviewed 53 out of 55 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test files (various *_format.sql) Updated expected formatting output for various SQL patterns including bind variables, directives, and query structures
SqlFormatterTest.kt Added comprehensive test cases for new SQL formatting scenarios
SqlBlockGenerator.kt Enhanced block generation logic for handling conditional loops and query groups
SqlFormatPreProcessor.kt Simplified SQL preprocessing by removing CREATE query type handling and improving comment formatting
NotQueryGroupHandler.kt Streamlined group handling by removing dependency on group lists
SqlBlockRelationBuilder.kt Refactored from SqlSetParentGroupProcessor to use builder pattern for managing block relationships
Various block classes Enhanced indentation and spacing logic for conditional directives and sub-groups
Comments suppressed due to low confidence (4)

src/main/kotlin/org/domaframework/doma/intellij/formatter/processor/SqlFormatPreProcessor.kt:33

  • This import statement references CreateQueryType which is no longer used in the file. The import should be removed as the related functionality has been eliminated.
import org.domaframework.doma.intellij.formatter.util.SqlKeywordUtil

src/main/kotlin/org/domaframework/doma/intellij/formatter/handler/NotQueryGroupHandler.kt:21

  • This import is no longer used since the SqlElConditionLoopCommentBlock reference was removed from the lastGroupParentConditionKeywordGroup function. The import should be removed.
import org.domaframework.doma.intellij.formatter.block.conflict.SqlConflictClauseBlock

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/top/SqlJoinQueriesGroupBlock.kt:21

  • This import is unused since SqlJoinQueriesGroupBlock now extends SqlTopQueryGroupBlock instead of SqlKeywordGroupBlock. The import should be removed.
import org.domaframework.doma.intellij.formatter.block.group.keyword.with.SqlWithQuerySubGroupBlock

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/top/SqlJoinQueriesGroupBlock.kt:22

  • This import is unused since IndentType is no longer referenced in this file after the class hierarchy change. The import should be removed.
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext

@xterao xterao added this to the ver2.0.0 Release milestone Aug 1, 2025
@xterao xterao merged commit e4f0c80 into feature/sql-format-official-version Aug 1, 2025
5 checks passed
@xterao xterao deleted the fix/sql-format-multiple-case-support branch August 1, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fixes formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect SQL Formatting with Directives

2 participants