Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 22, 2025

Overview

This PR fixes formatting issues that occurred when combining function names (treated as keyword elements) and other keyword elements within SQL function parameters. Previously, line breaks and indentation were not handled correctly in such cases.

Changes

  • When determining a FUNCTION_NAME element as a function name block, the logic now checks if the next non-whitespace element is a LEFT_PAREN. If not, it is treated as a regular keyword block.
  • Fixed the indentation calculation logic when a conditional loop directive exists immediately before a function name block.
    In the PreProcessor, the condition to prevent line breaks after a function name is now applied only to LEFT_PAREN, not to other elements.

These changes improve the formatting of SQL code involving function parameters and keyword elements, ensuring correct line breaks and indentation.

@xterao xterao self-assigned this Aug 22, 2025
@github-actions github-actions bot added the fix Bug fixes label Aug 22, 2025
@xterao xterao requested a review from Copilot August 22, 2025 02:11
@xterao xterao linked an issue Aug 22, 2025 that may be closed by this pull request
@xterao xterao added this to the 2.1.2 Release milestone Aug 22, 2025
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 fixes SQL formatting issues when combining function names (treated as keyword elements) with other keyword elements within SQL function parameters. The changes ensure proper line breaks and indentation are maintained in such scenarios.

  • Improved function name detection by checking if a FUNCTION_NAME element is followed by a LEFT_PAREN
  • Fixed indentation calculation for function parameters, especially when conditional loop directives are present
  • Enhanced the preprocessing logic to handle line breaks after function names more precisely

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
SqlKeywordUtil.kt Added "year" to the SET_LINE_KEYWORDS mapping for "from" keyword
SqlBlockGenerator.kt Added logic to handle "from" keyword within subgroup blocks
SqlFormatPreProcessor.kt Separated LEFT_PAREN handling logic to prevent unwanted line breaks after function names
SqlFileBlock.kt Enhanced FUNCTION_NAME detection to check for following LEFT_PAREN
SqlFunctionGroupBlock.kt Refactored indentation calculation methods
SqlFunctionParamBlock.kt Improved group indentation calculation with better spacing logic
SqlCommaBlock.kt Moved to comma package and enhanced indentation handling
SqlArrayCommaBlock.kt Updated import after SqlCommaBlock package move
Test files Added comprehensive test cases for the new formatting behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@xterao xterao merged commit 6a26654 into fix/sql-formatter Aug 22, 2025
5 checks passed
@xterao xterao deleted the fix/sql-formatter-incorrect-formatting-function-in-condition-directive branch August 22, 2025 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【SQL Format】Incorrect Formatting for Year From

2 participants