use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_setter.
@Test
public void testCompletion_setter() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " private String strField;\n" + " set" + "}\n");
int[] loc = findCompletionLocation(unit, "set");
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("setStrField(String strField) : void")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("setStrField", ci.getInsertText());
assertEquals(CompletionItemKind.Function, ci.getKind());
assertEquals("999999979", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
assertTextEdit(2, 4, 7, "/**\n" + " * @param strField the strField to set\n" + " */\n" + "public void setStrField(String strField) {\n" + " this.strField = strField;\n" + "}", resolvedItem.getTextEdit());
}
use of org.eclipse.lsp4j.CompletionList in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testCompletion.
protected void testCompletion(final Procedure1<? super TestCompletionConfiguration> configurator) {
try {
@Extension final TestCompletionConfiguration configuration = new TestCompletionConfiguration();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final String filePath = this.initializeContext(configuration).getUri();
CompletionParams _completionParams = new CompletionParams();
final Procedure1<CompletionParams> _function = (CompletionParams it) -> {
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
it.setTextDocument(_textDocumentIdentifier);
int _line = configuration.getLine();
int _column = configuration.getColumn();
Position _position = new Position(_line, _column);
it.setPosition(_position);
};
CompletionParams _doubleArrow = ObjectExtensions.<CompletionParams>operator_doubleArrow(_completionParams, _function);
final CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = this.languageServer.completion(_doubleArrow);
final Either<List<CompletionItem>, CompletionList> result = completionItems.get();
List<CompletionItem> _xifexpression = null;
boolean _isLeft = result.isLeft();
if (_isLeft) {
_xifexpression = result.getLeft();
} else {
_xifexpression = result.getRight().getItems();
}
final List<CompletionItem> items = _xifexpression;
final Function1<CompletionItem, String> _function_1 = (CompletionItem it) -> {
return it.getSortText();
};
Assert.assertEquals(items, IterableExtensions.<CompletionItem>toList(IterableExtensions.<CompletionItem, String>sortBy(items, _function_1)));
Procedure1<? super CompletionList> _assertCompletionList = configuration.getAssertCompletionList();
boolean _tripleNotEquals = (_assertCompletionList != null);
if (_tripleNotEquals) {
configuration.getAssertCompletionList().apply(result.getRight());
} else {
final String actualCompletionItems = this.toExpectation(items);
this.assertEquals(configuration.getExpectedCompletionItems(), actualCompletionItems);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.CompletionList in project sts4 by spring-projects.
the class Editor method getCompletions.
public List<CompletionItem> getCompletions() throws Exception {
CompletionList cl = harness.getCompletions(this.doc, this.getCursor());
ArrayList<CompletionItem> items = new ArrayList<>(cl.getItems());
Collections.sort(items, new Comparator<CompletionItem>() {
@Override
public int compare(CompletionItem o1, CompletionItem o2) {
return sortKey(o1).compareTo(sortKey(o2));
}
private String sortKey(CompletionItem item) {
String k = item.getSortText();
if (k == null) {
k = item.getLabel();
}
return k;
}
});
return items;
}
use of org.eclipse.lsp4j.CompletionList in project sts4 by spring-projects.
the class LanguageServerHarness method getCompletions.
public CompletionList getCompletions(TextDocumentInfo doc, Position cursor) throws Exception {
TextDocumentPositionParams params = new TextDocumentPositionParams();
params.setPosition(cursor);
params.setTextDocument(doc.getId());
waitForReconcile();
Either<List<CompletionItem>, CompletionList> completions = getServer().getTextDocumentService().completion(params).get();
if (completions.isLeft()) {
List<CompletionItem> list = completions.getLeft();
return new CompletionList(false, list);
} else /* sompletions.isRight() */
{
return completions.getRight();
}
}
Aggregations