Skip to content

Support JPQL syntax #1114

Closed
Closed

Description

@cassis163

Expected Behavior
IntelliJ has built-in support for JPQL that comes with type-safety. I would expect this feature to be included in the Spring Boot extension pack, since JPQL is used extensively in most Spring Boot projects. What I expect the extension pack to do is to add syntax highlighting, linting and intellisense (copy what IntelliJ does).

Current Behavior
JPQL queries are shown as plain strings at the moment. There is not much to be said about it.

Context
I really like coding in VSCode, but writing JPQL queries has been a pain due to lack of support compared to IntelliJ. Not being able to see type-safety related errors and overal highlighting makes writing JPQL a lot harder than it should be.

Activity

  1. BoykoAlex commented on Sep 28, 2023

    @BoykoAlex
    Contributor

    The only difficulty is creating from scratch a TextMate grammar for JPQL. Alternatively, we'd need to find one out there on the web as it is likely someone has created it. I have only managed to find the ANTLR grammar for JPQL but this serves a different purpose and doesn't look like it can be converted to TextMate grammar.
    In any case if we are to implement support for JPQL it'd be in a dedicated VSCode extension.

  2. added
    for: eclipse
    for: vscode
    and removed on Sep 29, 2023
  3. martinlippert commented on Mar 28, 2024

    @martinlippert
    Member

    Step one here would be to do syntax highlighting. Once we figured out how to do this, we should probably apply this solution to even more cases where some other "language" is embedded in annotation params, like SpEL.

  4. martinlippert commented on Mar 28, 2024

    @martinlippert
    Member

    The Spring Data JPA project itself contains parser implementations for all the various query languages: https://github.com/spring-projects/spring-data-jpa/tree/main/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query

    Probably worth to re-use parts of this if we dive into deeper "language" support here, like auto-completion, syntax checking, etc.

    For SpEL, we already use the Spring built-in SpEL parser to check syntax (but not to do syntax highlighting yet).

  5. martinlippert commented on Mar 28, 2024

    @martinlippert
    Member

    Another pointer: I saw the Java support in VSCode supports syntax highlighting for the content of text blocks in Java, e.g. highlighting the string inside a text block as YAML.

  6. self-assigned this
    on Apr 6, 2024
  7. added this to the 4.22.1.RELEASE milestone on Apr 6, 2024
  8. BoykoAlex commented on Apr 14, 2024

    @BoykoAlex
    Contributor

    Here is how sytax highlighting for JPQL looks like in VSCode

    Inside Java code:
    Screenshot 2024-04-14 at 19 31 04

    Inside jpa-named-queries.properties file:
    Screenshot 2024-04-14 at 19 31 11

    Eclipse support for Semantic Tokens from LSP is very limited and buggy... Only the jpa-named-queries.properties file syntax is supported but there are limitations bugs :-
    Screenshot 2024-04-14 at 19 32 05

    @martinlippert I'm thinking of folding in what I have at the moment. No SPEL syntax highlighting (embedded SPEL) and limitations for Eclipse.

  9. martinlippert commented on Apr 15, 2024

    @martinlippert
    Member

    @BoykoAlex Looks great and yes, let's fold that in.

  10. BoykoAlex commented on Apr 15, 2024

    @BoykoAlex
    Contributor

    JPQL part went in with: 95b8e2f

    Left:

    1. SPEL inside queries.
    2. HQL if hibernate core is on the classpath
    3. SPEL for HQL queries.
  11. BoykoAlex commented on Apr 16, 2024

    @BoykoAlex
    Contributor

    HQL support: 8b4abbc

    Only SPEL support left

  12. martinlippert commented on Apr 17, 2024

    @martinlippert
    Member

    I tried the latest Spring Boot Tools pre-release on VSCode with an older petclinic project, and I am seeing this a lot in the output view of VSCode:

    [Error - 11:24:26] Request textDocument/semanticTokens/full failed.
      Message: Internal error.
      Code: -32603 
    java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.springframework.ide.vscode.commons.util.text.TextDocument.getLanguageId()" because "doc" is null
    	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture$Completion.run(Unknown Source)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.base/java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.ide.vscode.commons.util.text.TextDocument.getLanguageId()" because "doc" is null
    	at org.springframework.ide.vscode.commons.languageserver.composable.CompositeLanguageServerComponents$7.findHandler(CompositeLanguageServerComponents.java:261)
    	at org.springframework.ide.vscode.commons.languageserver.composable.CompositeLanguageServerComponents$7.semanticTokensFull(CompositeLanguageServerComponents.java:245)
    	at org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService.lambda$semanticTokensFull$11(SimpleTextDocumentService.java:464)
    	... 5 more
    
  13. BoykoAlex commented on Apr 17, 2024

    @BoykoAlex
    Contributor

    NPE fix is included in 2543bdf

  14. martinlippert commented on Apr 18, 2024

    @martinlippert
    Member

    I can see the syntax highlighting showing up nicely after updating to the latest pre-release build of the Spring Boot Tools extension in VSCode. Great work.

    We should probably close this issue as done as soon as the syntax highlighting parts are complete and create additional issues around diagnostics, enabling the semantic token highlighting for java files in Eclipse, auto-completion, etc.

  15. BoykoAlex commented on Apr 18, 2024

    @BoykoAlex
    Contributor

    SPEL syntax highlighting moved to #1234. Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: eclipsefor: vscodetheme: code completiontheme: validationtype: enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions