use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_noPackage.
@Test
public void testCompletion_noPackage() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/NoPackage.java", "public class NoPackage {\n" + " NoP" + "}\n");
int[] loc = findCompletionLocation(unit, " NoP");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertFalse("No proposals were found", list.getItems().isEmpty());
assertEquals("NoPackage", list.getItems().get(0).getLabel());
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_AnonymousType.
@Test
public void testCompletion_AnonymousType() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " public static void main(String[] args) {\n" + " IFoo foo = new \n" + " } \n" + " interface IFoo {\n" + " String getName();\n" + " }\n" + "}\n");
waitForBackgroundJobs();
int[] loc = findCompletionLocation(unit, "new ");
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.IFoo() Anonymous Inner Type")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("Foo.IFoo", ci.getInsertText());
assertEquals(CompletionItemKind.Constructor, ci.getKind());
assertEquals("999998684", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
assertTextEdit(2, 23, 23, "IFoo(){\n" + "\n" + " @Override\n" + " public String getName() {\n" + " ${0:return null;}\n" + " }\n" + "};", resolvedItem.getTextEdit());
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testStaticImports1.
@Test
public void testStaticImports1() throws Exception {
List<String> favorites = new ArrayList<>();
favorites.add("test1.A.foo");
PreferenceManager.getPrefs(null).setJavaCompletionFavoriteMembers(favorites);
try {
ICompilationUnit unit = getWorkingCopy("src/test1/B.java", // @formatter:off
"package test1;\n" + "\n" + "public class B {\n" + " public void bar() {\n" + " fo\n" + " }\n" + "}\n");
// @formatter:on
int[] loc = findCompletionLocation(unit, "fo");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertTrue(list.getItems().size() > 0);
assertTrue("no proposal for foo()", "foo() : void".equals(list.getItems().get(0).getLabel()));
} finally {
PreferenceManager.getPrefs(null).setJavaCompletionFavoriteMembers(Collections.emptyList());
}
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_javadoc.
@Test
public void testCompletion_javadoc() throws Exception {
IJavaProject javaProject = JavaCore.create(project);
ICompilationUnit unit = (ICompilationUnit) javaProject.findElement(new Path("org/sample/TestJavadoc.java"));
unit.becomeWorkingCopy(null);
String joinOnCompletion = System.getProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
try {
System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, "true");
int[] loc = findCompletionLocation(unit, "inner.");
TextDocumentPositionParams position = JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]));
String source = unit.getSource();
changeDocument(unit, source, 3);
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
changeDocument(unit, source, 4);
CompletionList list = server.completion(position).join().getRight();
for (CompletionItem item : list.getItems()) {
server.resolveCompletionItem(item);
}
CompletionItem resolved = list.getItems().get(0);
assertEquals("Test ", resolved.getDocumentation());
} finally {
unit.discardWorkingCopy();
if (joinOnCompletion == null) {
System.clearProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
} else {
System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, joinOnCompletion);
}
}
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_import_static.
@Test
public void testCompletion_import_static() throws JavaModelException {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "import static java.util.concurrent.TimeUnit. \n" + "public class Foo {\n" + " void foo() {\n" + " }\n" + "}\n");
int[] loc = findCompletionLocation(unit, "java.util.concurrent.TimeUnit.");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertEquals(9, list.getItems().size());
// // .SECONDS - enum value
CompletionItem secondsFieldItem = list.getItems().get(0);
// Check completion item
assertEquals("SECONDS", secondsFieldItem.getInsertText());
assertEquals("SECONDS : TimeUnit", secondsFieldItem.getLabel());
assertEquals(CompletionItemKind.Field, secondsFieldItem.getKind());
assertEquals("999999210", secondsFieldItem.getSortText());
assertNull(secondsFieldItem.getTextEdit());
assertNotNull(server.resolveCompletionItem(secondsFieldItem).join());
TextEdit teSeconds = secondsFieldItem.getTextEdit();
assertNotNull(teSeconds);
assertEquals("SECONDS;", teSeconds.getNewText());
assertNotNull(teSeconds.getRange());
Range secondsRange = teSeconds.getRange();
assertEquals(0, secondsRange.getStart().getLine());
assertEquals(44, secondsRange.getStart().getCharacter());
assertEquals(0, secondsRange.getEnd().getLine());
// // .values() - static method
CompletionItem valuesMethodItem = list.getItems().get(7);
// Check completion item
assertEquals("values", valuesMethodItem.getInsertText());
assertEquals("values() : TimeUnit[]", valuesMethodItem.getLabel());
assertEquals(CompletionItemKind.Module, valuesMethodItem.getKind());
assertEquals("999999211", valuesMethodItem.getSortText());
assertNull(valuesMethodItem.getTextEdit());
assertNotNull(server.resolveCompletionItem(valuesMethodItem).join());
TextEdit teValues = valuesMethodItem.getTextEdit();
assertNotNull(teValues);
assertEquals("values;", teValues.getNewText());
assertNotNull(teValues.getRange());
Range valuesRange = teValues.getRange();
assertEquals(0, valuesRange.getStart().getLine());
assertEquals(44, valuesRange.getStart().getCharacter());
assertEquals(0, valuesRange.getEnd().getLine());
}
Aggregations