Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Jul 11, 2025

Updated the formatter to correctly set line-break flags for "WHEN", "ELSE", and "END" within a "CASE" expression.


Formatting Behavior

  • The first "WHEN" clause remains inline with "CASE".

  • The second and subsequent branches ("WHEN", "ELSE") are:

    • Line-broken
    • Indented to align with the first "WHEN".
  • The "END" keyword is right-aligned with the initial "CASE" keyword.


Example (Formatted Output)

SELECT CASE WHEN div = 'A' THEN 'AAA'
            WHEN div = 'B' THEN 'BBB'
            ELSE 'CCC'
        END AS divName
  FROM users

@xterao xterao self-assigned this Jul 11, 2025
@xterao xterao changed the base branch from main to feature/sql-format-official-version July 11, 2025 07:59
@xterao xterao requested a review from Copilot July 11, 2025 07:59
@xterao xterao linked an issue Jul 11, 2025 that may be closed by this pull request

This comment was marked as outdated.

@xterao xterao force-pushed the feature/sql-format-support-case-end branch from 0979977 to 3c4aa79 Compare July 11, 2025 08:03
@xterao xterao requested a review from Copilot July 11, 2025 08:11
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 the SQL formatter to correctly break and indent WHEN/ELSE branches and right-align the END in a CASE expression.

  • Adds a new test case and expected formatted SQL for CASE … END expressions.
  • Introduces INLINE and INLINE_SECOND indent types and refactors formatter blocks to use them.
  • Updates related processor logic, imports, and indentation calculations for inline keyword groups.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/testData/sql/formatter/SelectCaseEnd_format.sql Expected formatted output for CASE…END test
src/test/testData/sql/formatter/SelectCaseEnd.sql Raw SQL input for CASE…END formatting test
src/test/kotlin/org/domaframework/doma/intellij/formatter/SqlFormatterTest.kt Added testSelectCaseEndFormatter
src/main/kotlin/org/domaframework/doma/intellij/formatter/util/SqlKeywordUtil.kt Added INLINE & INLINE_SECOND indent types
src/main/kotlin/org/domaframework/doma/intellij/formatter/util/SqlBlockUtil.kt Aligned multiline parameter formatting
src/main/kotlin/org/domaframework/doma/intellij/formatter/processor/SqlSetParentGroupProcessor.kt Simplified updateInlineSecondGroupBlockParentAndAddGroup signature
src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/inline/SqlInlineSecondGroupBlock.kt Refined indent logic and isEndCase detection
src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/inline/SqlInlineGroupBlock.kt Refactored indent calculations and added inlineConditions list
src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlCommaBlock.kt Extracted expectedTypes and adjusted isSaveSpace logic
src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlBlock.kt Updated imports and inline-second group processor invocation

@xterao xterao merged commit 8fe2ce5 into feature/sql-format-official-version Jul 11, 2025
5 checks passed
@xterao xterao deleted the feature/sql-format-support-case-end branch July 11, 2025 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix CASE ... END Formatting

2 participants