-
Notifications
You must be signed in to change notification settings - Fork 0
Indentation Adjustment for Nested Conditional / Loop Directives #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indentation Adjustment for Nested Conditional / Loop Directives #323
Conversation
…d indentation handling
…ndling for various SQL constructs
… loops and improve spacing for various SQL constructs
de21613 to
514d571
Compare
There was a problem hiding this 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 implements enhanced formatting rules for SQL conditional and loop directives, adding proper indentation and spacing handling for nested directive blocks. The changes improve code readability by managing hierarchical block structures and ensuring consistent formatting across complex SQL templates.
- Enhanced indentation adjustment for nested conditional/loop directives with proper parent-child block hierarchy management
- Added space insertion after embedded variable directives and improved line-break rules for conditional/loop directives
- Refactored block processing architecture to properly handle directive comment blocks within the formatting pipeline
Reviewed Changes
Copilot reviewed 43 out of 44 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/testData/sql/formatter/*.sql | Test data files demonstrating expected formatting output for nested directives and conditional blocks |
| src/test/kotlin/.../SqlFormatterTest.kt | Added test methods for nested directives and conditional case formatting |
| src/main/kotlin/.../util/SqlKeywordUtil.kt | Added "select" keyword with "if exists" clause support |
| src/main/kotlin/.../util/SqlBlockUtil.kt | Refactored comma block creation logic and moved comment block imports |
| src/main/kotlin/.../util/CommaRawUtil.kt | New utility class to handle comma block creation with conditional directive support |
| src/main/kotlin/.../processor/SqlSetParentGroupProcessor.kt | Major refactoring of parent group processing with enhanced conditional directive handling |
| src/main/kotlin/.../processor/SqlPostProcessor.kt | Improved code organization with extracted helper methods for document processing |
| src/main/kotlin/.../builder/SqlCustomSpacingBuilder.kt | Added spacing logic for directive comments and simplified right pattern handling |
| src/main/kotlin/.../builder/SqlBlockBuilder.kt | Enhanced comment and conditional directive block management with improved indentation logic |
| src/main/kotlin/.../block/comment/*.kt | Moved and refactored comment block classes with new conditional directive support |
| src/main/kotlin/.../block/*.kt | Updated various block classes to support conditional directive indentation |
src/main/kotlin/org/domaframework/doma/intellij/formatter/util/CommaRawUtil.kt
Outdated
Show resolved
Hide resolved
...ain/kotlin/org/domaframework/doma/intellij/formatter/processor/SqlSetParentGroupProcessor.kt
Show resolved
Hide resolved
...in/org/domaframework/doma/intellij/formatter/block/comment/SqlElConditionLoopCommentBlock.kt
Show resolved
Hide resolved
src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlFileBlock.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlBlock.kt
Outdated
Show resolved
Hide resolved
514d571 to
3821fe7
Compare
28c32fd
into
feature/sql-format-official-version
When conditional or loop directives (e.g., if, for) are nested, the formatter increases the indentation level for each nested directive.
If a directive is placed within a different group block, the indentation is not based on the outer directive's indentation, but rather:
It aligns with the nearest enclosing group block's indentation.
Additional Formatting Rules Implemented
Insert 1 space after embedded variable directives
Ensure there is a space between an embedded variable directive (e.g., /*# variable */) and the following element.
Standard comment blocks are not managed in parent-child block hierarchy
When comments are line-broken, align them to the indentation level of the immediate next line rather than treating them as part of any structural group.
Conditional / Loop directives line-break rule
If a conditional or loop directive is not the first element in a sub-group, insert a line break before the directive to enhance readability.