From 007ba15da2beefbee1550da874852d1d71e9ce4a Mon Sep 17 00:00:00 2001 From: ksankaranara Date: Mon, 19 Aug 2024 19:39:14 +0530 Subject: [PATCH] Fix missing proposal if the prefix starts with "/" for @ContextConfiguration --- .../ContextConfigurationProcessor.java | 3 +- .../ContextConfigurationCompletionTest.java | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/contextconfiguration/ContextConfigurationProcessor.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/contextconfiguration/ContextConfigurationProcessor.java index 2eeb15bbc..1266efc8e 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/contextconfiguration/ContextConfigurationProcessor.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/contextconfiguration/ContextConfigurationProcessor.java @@ -169,6 +169,7 @@ public class ContextConfigurationProcessor implements CompletionProvider { } private String[] findResources(IJavaProject project, String prefix) { + String filteredPrefix = prefix.replaceAll("^/+", ""); String[] resources = IClasspathUtil.getClasspathResources(project.getClasspath()).stream() .distinct() .sorted(new Comparator() { @@ -178,7 +179,7 @@ public class ContextConfigurationProcessor implements CompletionProvider { } }) .map(r -> r.replaceAll("\\\\", "/")) - .filter(r -> ("classpath:" + r).contains(prefix)) + .filter(r -> ("classpath:" + r).contains(filteredPrefix)) .toArray(String[]::new); return resources; diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/contextconfiguration/test/ContextConfigurationCompletionTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/contextconfiguration/test/ContextConfigurationCompletionTest.java index 089ba44c4..5fe2b8539 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/contextconfiguration/test/ContextConfigurationCompletionTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/contextconfiguration/test/ContextConfigurationCompletionTest.java @@ -222,7 +222,39 @@ public class ContextConfigurationCompletionTest { "@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")"); } + @Test + void testComplexResourceNameWithSlashPrefixAndWithLocationsAndParamNameCompletion() throws Exception { + prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(locations=\"/root.xml<*>\")"); + assertClasspathCompletions( + "@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")"); + } + + @Test + void testComplexResourceNameWithSlashPrefixAndWithValueAndParamNameCompletion() throws Exception { + prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(value=\"/root.xml<*>\")"); + + assertClasspathCompletions( + "@ContextConfiguration(value=\"/a-random-resource-root.xml<*>\")"); + } + + @Test + void testComplexResourceNameWithSlashPrefixAndParamNameCompletion() throws Exception { + prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(\"/root.xml<*>\")"); + + assertClasspathCompletions( + "@ContextConfiguration(\"/a-random-resource-root.xml<*>\")"); + } + + @Test + void testComplexResourceNameWithSlashPrefixAndDifferentParamNameCompletion() throws Exception { + prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(locations=\"/random<*>\")"); + + assertClasspathCompletions( + "@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")", + "@ContextConfiguration(locations=\"/org/random-resource-org.xml<*>\")", + "@ContextConfiguration(locations=\"/org/test/random-resource-org-test.xml<*>\")"); + } private void prepareCase(String selectedAnnotation, String annotationStatementBeforeTest) throws Exception { InputStream resource = this.getClass().getResourceAsStream("/test-projects/test-annotation-contextconfiguration/src/main/java/org/test/TestContextConfigurationCompletion.java");