From be4839fd84af09a4961fe66ac27d54bcbdffa3ef Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Fri, 16 May 2025 12:31:32 +0200 Subject: [PATCH] GH-1545: use specific prompt for explaining mongodb queries --- .../java/handlers/CopilotCodeLensProvider.java | 15 +++++++++++++-- .../ide/vscode/boot/java/handlers/QueryType.java | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/CopilotCodeLensProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/CopilotCodeLensProvider.java index 117556ae8..f247e027a 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/CopilotCodeLensProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/CopilotCodeLensProvider.java @@ -221,11 +221,22 @@ public class CopilotCodeLensProvider implements CodeLensProvider { private QueryType determineQueryType(TextDocument document) { Optional optProject = projectFinder.find(document.getId()); + if (optProject.isPresent()) { IJavaProject jp = optProject.get(); - return SpringProjectUtil.hasDependencyStartingWith(jp, "hibernate-core", null) ? QueryType.HQL - : QueryType.JPQL; + + if (SpringProjectUtil.hasDependencyStartingWith(jp, "hibernate-core", null)) { + return QueryType.HQL; + } + else if (SpringProjectUtil.hasDependencyStartingWith(jp, "spring-data-mongodb", null)) { + return QueryType.MONGODB; + } + else { + return QueryType.JPQL; + + } } + return QueryType.DEFAULT; } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/QueryType.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/QueryType.java index 31a20bb6c..0014e8010 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/QueryType.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/QueryType.java @@ -4,6 +4,7 @@ public enum QueryType { SPEL("Explain SpEL Expression with Copilot", "Explain the following SpEL Expression with a clear summary first, followed by a breakdown of the expression with details: \n\n"), JPQL("Explain Query with Copilot", "Explain the following JPQL query with a clear summary first, followed by a detailed explanation. If the query contains any SpEL expressions, explain those parts as well: \n\n"), HQL("Explain Query with Copilot", "Explain the following HQL query with a clear summary first, followed by a detailed explanation. If the query contains any SpEL expressions, explain those parts as well: \n\n"), + MONGODB("Explain Query with Copilot", "Explain the following MongoDB query with a clear summary first, followed by a detailed explanation. If the query contains any SpEL expressions, explain those parts as well: \n\n"), AOP("Explain AOP annotation with Copilot", "Explain the following AOP annotation with a clear summary first, followed by a detailed contextual explanation of annotation and its purpose: \n\n"), DEFAULT("Explain Query with Copilot", "Explain the following query with a clear summary first, followed by a detailed explanation: \n\n");