enable the snippets again and make the tests work even if there are snippets showing up in the results
This commit is contained in:
@@ -276,36 +276,36 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
providers.put(Annotations.REPOSITORY, new DataRepositoryCompletionProcessor());
|
||||
|
||||
JavaSnippetManager snippetManager = new JavaSnippetManager(server::createSnippetBuilder);
|
||||
// snippetManager.add(
|
||||
// new JavaSnippet("RequestMapping method", JavaSnippetContext.BOOT_MEMBERS, CompletionItemKind.Method,
|
||||
// ImmutableList.of("org.springframework.web.bind.annotation.RequestMapping",
|
||||
// "org.springframework.web.bind.annotation.RequestMethod",
|
||||
// "org.springframework.web.bind.annotation.RequestParam"),
|
||||
// "@RequestMapping(value=\"${path}\", method=RequestMethod.${GET})\n"
|
||||
// + "public ${SomeData} ${requestMethodName}(@RequestParam ${String} ${param}) {\n"
|
||||
// + " return new ${SomeData}(${cursor});\n" + "}\n"));
|
||||
// snippetManager
|
||||
// .add(new JavaSnippet("GetMapping method", JavaSnippetContext.BOOT_MEMBERS, CompletionItemKind.Method,
|
||||
// ImmutableList.of("org.springframework.web.bind.annotation.GetMapping",
|
||||
// "org.springframework.web.bind.annotation.RequestParam"),
|
||||
// "@GetMapping(value=\"${path}\")\n"
|
||||
// + "public ${SomeData} ${getMethodName}(@RequestParam ${String} ${param}) {\n"
|
||||
// + " return new ${SomeData}(${cursor});\n" + "}\n"));
|
||||
// snippetManager.add(new JavaSnippet("PostMapping method", JavaSnippetContext.BOOT_MEMBERS,
|
||||
// CompletionItemKind.Method,
|
||||
// ImmutableList.of("org.springframework.web.bind.annotation.PostMapping",
|
||||
// "org.springframework.web.bind.annotation.RequestBody"),
|
||||
// "@PostMapping(value=\"${path}\")\n"
|
||||
// + "public ${SomeEnityData} ${postMethodName}(@RequestBody ${SomeEnityData} ${entity}) {\n"
|
||||
// + " //TODO: process POST request\n" + " ${cursor}\n" + " return ${entity};\n" + "}\n"));
|
||||
// snippetManager.add(new JavaSnippet("PutMapping method", JavaSnippetContext.BOOT_MEMBERS,
|
||||
// CompletionItemKind.Method,
|
||||
// ImmutableList.of("org.springframework.web.bind.annotation.PutMapping",
|
||||
// "org.springframework.web.bind.annotation.RequestBody",
|
||||
// "org.springframework.web.bind.annotation.PathVariable"),
|
||||
// "@PutMapping(value=\"${path}/{${id}}\")\n"
|
||||
// + "public ${SomeEnityData} ${putMethodName}(@PathVariable ${pvt:String} ${id}, @RequestBody ${SomeEnityData} ${entity}) {\n"
|
||||
// + " //TODO: process PUT request\n" + " ${cursor}\n" + " return ${entity};\n" + "}"));
|
||||
snippetManager.add(
|
||||
new JavaSnippet("RequestMapping method", JavaSnippetContext.BOOT_MEMBERS, CompletionItemKind.Method,
|
||||
ImmutableList.of("org.springframework.web.bind.annotation.RequestMapping",
|
||||
"org.springframework.web.bind.annotation.RequestMethod",
|
||||
"org.springframework.web.bind.annotation.RequestParam"),
|
||||
"@RequestMapping(value=\"${path}\", method=RequestMethod.${GET})\n"
|
||||
+ "public ${SomeData} ${requestMethodName}(@RequestParam ${String} ${param}) {\n"
|
||||
+ " return new ${SomeData}(${cursor});\n" + "}\n"));
|
||||
snippetManager
|
||||
.add(new JavaSnippet("GetMapping method", JavaSnippetContext.BOOT_MEMBERS, CompletionItemKind.Method,
|
||||
ImmutableList.of("org.springframework.web.bind.annotation.GetMapping",
|
||||
"org.springframework.web.bind.annotation.RequestParam"),
|
||||
"@GetMapping(value=\"${path}\")\n"
|
||||
+ "public ${SomeData} ${getMethodName}(@RequestParam ${String} ${param}) {\n"
|
||||
+ " return new ${SomeData}(${cursor});\n" + "}\n"));
|
||||
snippetManager.add(new JavaSnippet("PostMapping method", JavaSnippetContext.BOOT_MEMBERS,
|
||||
CompletionItemKind.Method,
|
||||
ImmutableList.of("org.springframework.web.bind.annotation.PostMapping",
|
||||
"org.springframework.web.bind.annotation.RequestBody"),
|
||||
"@PostMapping(value=\"${path}\")\n"
|
||||
+ "public ${SomeEnityData} ${postMethodName}(@RequestBody ${SomeEnityData} ${entity}) {\n"
|
||||
+ " //TODO: process POST request\n" + " ${cursor}\n" + " return ${entity};\n" + "}\n"));
|
||||
snippetManager.add(new JavaSnippet("PutMapping method", JavaSnippetContext.BOOT_MEMBERS,
|
||||
CompletionItemKind.Method,
|
||||
ImmutableList.of("org.springframework.web.bind.annotation.PutMapping",
|
||||
"org.springframework.web.bind.annotation.RequestBody",
|
||||
"org.springframework.web.bind.annotation.PathVariable"),
|
||||
"@PutMapping(value=\"${path}/{${id}}\")\n"
|
||||
+ "public ${SomeEnityData} ${putMethodName}(@PathVariable ${pvt:String} ${id}, @RequestBody ${SomeEnityData} ${entity}) {\n"
|
||||
+ " //TODO: process PUT request\n" + " ${cursor}\n" + " return ${entity};\n" + "}"));
|
||||
return new BootJavaCompletionEngine(this, providers, snippetManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ public class DataRepositoryCompletionProcessorTest {
|
||||
@Test
|
||||
public void testStandardFindByCompletions() throws Exception {
|
||||
prepareCase("{", "{<*>");
|
||||
assertAnnotationCompletions(
|
||||
"findByLastName<*>(String lastName);");
|
||||
assertContainsAnnotationCompletions(
|
||||
"List<Customer> findByLastName${1|(String lastName);,And,Or|}");
|
||||
}
|
||||
|
||||
private void prepareCase(String selectedAnnotation, String annotationStatementBeforeTest) throws Exception {
|
||||
@@ -65,16 +65,20 @@ public class DataRepositoryCompletionProcessorTest {
|
||||
editor = new Editor(harness, content, LanguageId.JAVA);
|
||||
}
|
||||
|
||||
private void assertAnnotationCompletions(String... completedAnnotations) throws Exception {
|
||||
private void assertContainsAnnotationCompletions(String... expectedResultsFromCompletion) throws Exception {
|
||||
List<CompletionItem> completions = editor.getCompletions();
|
||||
|
||||
int i = 0;
|
||||
for (String expectedCompleted : completedAnnotations) {
|
||||
for (CompletionItem foundCompletion : completions) {
|
||||
Editor clonedEditor = editor.clone();
|
||||
clonedEditor.apply(completions.get(i++));
|
||||
TestAsserts.assertContains(expectedCompleted, clonedEditor.getText());
|
||||
clonedEditor.apply(foundCompletion);
|
||||
|
||||
if (clonedEditor.getText().contains(expectedResultsFromCompletion[i])) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(i, completions.size());
|
||||
assertEquals(expectedResultsFromCompletion.length, i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user