Add support for multiline query formatting in Query annotations#1763
Draft
catturtle123 wants to merge 5 commits intospring-projects:mainfrom
Draft
Add support for multiline query formatting in Query annotations#1763catturtle123 wants to merge 5 commits intospring-projects:mainfrom
catturtle123 wants to merge 5 commits intospring-projects:mainfrom
Conversation
Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
- Introduce QueryFormatter interface and implementations for JPQL and MongoDB queries - Add BootJavaConfig option to select query style (compact or multiline) - Update code lens and code action providers to use configurable query formatting - Enhance tests to verify multiline and compact query styles Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
…related tests - Remove extra indentation from multiline JPQL and Mongo query formatting - Adjust test assertions to match new formatting without leading spaces - Update text block generation to align closing triple quotes without indentation - Add configuration option for data query style in package.json - Enhance code action provider to include fix data for refactorings Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
Member
|
I tried the latest version here and I do see the multiline preference working and slitting up the query statement nicely into multiple lines. But I do not see (yet) the correct formatting. Am I missing something? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses issue #1726
Summary
Default Data Query Style Change: Changed the default query generation style to
compact(single line) to ensure broader compatibility across Java versions.Architectural Refinement (Interface Separation): Decoupled the query formatting logic by introducing the
QueryFormatterinterface with dedicated implementations (JpqlQueryFormatter,MongoQueryFormatter). This allows for repository-specific formatting strategies.Robust String Escaping & Formatting:
Integrated
StringEscapeUtils.escapeJava()to safe-guard generated queries against syntax errors.Multiline Indentation: Improved Text Block generation by adding proper indentation/alignment to ensure the generated query is visually consistent with the surrounding Java code.
Configuration & Fallback: Updated logic to use
compactandmultilinekeywords fromUserSettings. Implemented a fallback mechanism that defaults tocompactand triggers alog.warnfor invalid ornullinputs.Key Changes
Refactoring & Logic:
QueryFormatter.java,JpqlQueryFormatter.java,MongoQueryFormatter.java: Separated formatting logic into an interface-based structure.BootJavaConfig.java: Updated style selection and added validation/fallback logic.DataRepositoryAotMetadataCodeLensProvider.java: Refactored to prioritize safety and proper indentation.Test Suite Updates:
QueryMethodCodeActionProviderJpaTest.java&QueryMethodCodeActionProviderMongoDbTest.java: Updated to verify the output specifically for thecompactstyle.DataRepositoryAotMetadataCodeLensProviderTest.java: Added comprehensive test cases for bothcompactandmultilinestyles, verifying correct indentation.Resolved Issues
IndexOutOfBoundsExceptionby properly escaping special characters.Discussion Points
DataRepositoryAotMetadataCodeLensProviderTestprovides full coverage for both styles. However,QueryMethodCodeActionProviderJpaTestandQueryMethodCodeActionProviderMongoDbTestare currently limited to verifying thecompactstyle. Should I expand these two classes to includemultilinetest cases as well to maintain consistency?log.warnfollowed by a fallback tocompactan acceptable approach for handling unexpected user configuration values? (Silent fallback to compact for null cases (no log.warn).)Test