use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_import_package.
@Test
public void testCompletion_import_package() throws JavaModelException {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "import java.sq \n" + "public class Foo {\n" + " void foo() {\n" + " }\n" + "}\n");
int[] loc = findCompletionLocation(unit, "java.sq");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertEquals(1, list.getItems().size());
CompletionItem item = list.getItems().get(0);
// Check completion item
assertNull(item.getInsertText());
assertEquals("java.sql", item.getLabel());
assertEquals(CompletionItemKind.Module, item.getKind());
assertEquals("999999215", item.getSortText());
assertNull(item.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(item).join();
assertNotNull(resolvedItem);
TextEdit te = item.getTextEdit();
assertNotNull(te);
assertEquals("java.sql.*;", te.getNewText());
assertNotNull(te.getRange());
Range range = te.getRange();
assertEquals(0, range.getStart().getLine());
assertEquals(7, range.getStart().getCharacter());
assertEquals(0, range.getEnd().getLine());
// Not checking the range end character
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_AnonymousDeclarationType2.
@Test
public void testCompletion_AnonymousDeclarationType2() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " public static void main(String[] args) {\n" + " new Runnable( )\n" + " }\n" + "}\n");
waitForBackgroundJobs();
int[] loc = findCompletionLocation(unit, "Runnable( ");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("Runnable() Anonymous Inner Type")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("Runnable", ci.getInsertText());
assertEquals(CompletionItemKind.Class, ci.getKind());
assertEquals("999999372", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
assertTextEdit(2, 20, 24, "(){\n" + "\n" + " @Override\n" + " public void run() {\n" + " ${0}\n" + " }\n" + "}", resolvedItem.getTextEdit());
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_method_withLSPV3.
@Test
public void testCompletion_method_withLSPV3() throws JavaModelException {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " void foo() {\n" + "System.out.print(\"Hello\");\n" + "System.out.println(\" World!\");\n" + "HashMap<String, String> map = new HashMap<>();\n" + "map.pu\n" + " }\n" + "}\n");
int[] loc = findCompletionLocation(unit, "map.pu");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().matches("put\\(String \\w+, String \\w+\\) : String")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("put", ci.getInsertText());
assertEquals(CompletionItemKind.Function, ci.getKind());
assertEquals("999999019", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
try {
assertTextEdit(5, 4, 6, "put(${1:key}, ${2:value})", resolvedItem.getTextEdit());
} catch (ComparisonFailure e) {
// In case the JDK has no sources
assertTextEdit(5, 4, 6, "put(${1:arg0}, ${2:arg1})", resolvedItem.getTextEdit());
}
assertNotNull(resolvedItem.getAdditionalTextEdits());
List<TextEdit> edits = resolvedItem.getAdditionalTextEdits();
assertEquals(3, edits.size());
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_class_name_contains_$.
@Test
public void testCompletion_class_name_contains_$() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Foo$Bar.java", "public class Foo$Bar {\n" + " public static void main(String[] args) {\n" + " new Foo\n" + " }\n" + "}\n");
waitForBackgroundJobs();
int[] loc = findCompletionLocation(unit, "new Foo");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("Foo$Bar")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("Foo$Bar", ci.getInsertText());
assertEquals(CompletionItemKind.Constructor, ci.getKind());
assertEquals("999999115", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
assertTextEdit(2, 12, 15, "Foo\\$Bar()", resolvedItem.getTextEdit());
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_plainTextDoc.
public void testCompletion_plainTextDoc() throws Exception {
ICompilationUnit unit = getWorkingCopy(// @formatter:off
"src/java/Foo.java", "import java.sq \n" + "public class Foo {\n" + " void foo() {\n" + " zz\n" + " }\n\" }\\n\"+" + "\n" + "/** This should be <bold>plain</bold>.*/\n" + " void zzz() {}\n" + "}\n");
// @formatter:off
int[] loc = findCompletionLocation(unit, " zz");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertFalse("No proposals were found", list.getItems().isEmpty());
CompletionItem item = list.getItems().get(0);
assertEquals("zzz() : void", item.getLabel());
CompletionItem resolvedItem = server.resolveCompletionItem(item).join();
assertEquals("This should be plain.", resolvedItem.getDocumentation());
}
Aggregations