Skip to content

Commit 007ba15

Browse files
karthiksmsmartinlippert
authored andcommitted
Fix missing proposal if the prefix starts with "/" for @ContextConfiguration
1 parent e75dd45 commit 007ba15

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/contextconfiguration/ContextConfigurationProcessor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public String identifyPropertyPrefix(String nodeContent, int offset) {
169169
}
170170

171171
private String[] findResources(IJavaProject project, String prefix) {
172+
String filteredPrefix = prefix.replaceAll("^/+", "");
172173
String[] resources = IClasspathUtil.getClasspathResources(project.getClasspath()).stream()
173174
.distinct()
174175
.sorted(new Comparator<String>() {
@@ -178,7 +179,7 @@ public int compare(String o1, String o2) {
178179
}
179180
})
180181
.map(r -> r.replaceAll("\\\\", "/"))
181-
.filter(r -> ("classpath:" + r).contains(prefix))
182+
.filter(r -> ("classpath:" + r).contains(filteredPrefix))
182183
.toArray(String[]::new);
183184

184185
return resources;

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/contextconfiguration/test/ContextConfigurationCompletionTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,39 @@ void testComplexResourceNameInPrefixWithinQuotesAndParamNameCompletion() throws
222222
"@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")");
223223
}
224224

225+
@Test
226+
void testComplexResourceNameWithSlashPrefixAndWithLocationsAndParamNameCompletion() throws Exception {
227+
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(locations=\"/root.xml<*>\")");
228+
229+
assertClasspathCompletions(
230+
"@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")");
231+
}
232+
233+
@Test
234+
void testComplexResourceNameWithSlashPrefixAndWithValueAndParamNameCompletion() throws Exception {
235+
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(value=\"/root.xml<*>\")");
236+
237+
assertClasspathCompletions(
238+
"@ContextConfiguration(value=\"/a-random-resource-root.xml<*>\")");
239+
}
225240

241+
@Test
242+
void testComplexResourceNameWithSlashPrefixAndParamNameCompletion() throws Exception {
243+
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(\"/root.xml<*>\")");
244+
245+
assertClasspathCompletions(
246+
"@ContextConfiguration(\"/a-random-resource-root.xml<*>\")");
247+
}
248+
249+
@Test
250+
void testComplexResourceNameWithSlashPrefixAndDifferentParamNameCompletion() throws Exception {
251+
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(locations=\"/random<*>\")");
252+
253+
assertClasspathCompletions(
254+
"@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")",
255+
"@ContextConfiguration(locations=\"/org/random-resource-org.xml<*>\")",
256+
"@ContextConfiguration(locations=\"/org/test/random-resource-org-test.xml<*>\")");
257+
}
226258

227259
private void prepareCase(String selectedAnnotation, String annotationStatementBeforeTest) throws Exception {
228260
InputStream resource = this.getClass().getResourceAsStream("/test-projects/test-annotation-contextconfiguration/src/main/java/org/test/TestContextConfigurationCompletion.java");

0 commit comments

Comments
 (0)