use of org.eclipse.lsp4j.CompletionParams in project xtext-core by eclipse.
the class LanguageServerImpl method completion.
/**
* Compute the completion items.
*/
protected Either<List<CompletionItem>, CompletionList> completion(CancelIndicator originalCancelIndicator, CompletionParams params) {
URI uri = getURI(params);
ContentAssistService contentAssistService = getService(uri, ContentAssistService.class);
if (contentAssistService == null) {
return Either.forRight(new CompletionList());
}
BufferedCancelIndicator cancelIndicator = new BufferedCancelIndicator(originalCancelIndicator);
return Either.forRight(workspaceManager.doRead(uri, (doc, res) -> contentAssistService.createCompletionList(doc, res, params, cancelIndicator)));
}
use of org.eclipse.lsp4j.CompletionParams in project xtext-core by eclipse.
the class UnknownProjectConfigTest method checkCompletion.
protected void checkCompletion(String uri) throws Exception {
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = languageServer.completion(new CompletionParams(new TextDocumentIdentifier(uri), new Position(0, 10)));
Either<List<CompletionItem>, CompletionList> result = completionItems.get();
List<CompletionItem> items = null;
if (result.isLeft()) {
items = result.getLeft();
} else {
items = result.getRight().getItems();
}
String actualCompletionItems = Strings.toUnixLineSeparator(toExpectation(items));
String expectedCompletionItems = "Foo (TypeDeclaration) -> Foo [[0, 10] .. [0, 10]]\n" + "boolean -> boolean [[0, 10] .. [0, 10]]\n" + "int -> int [[0, 10] .. [0, 10]]\n" + "op -> op [[0, 10] .. [0, 10]]\n" + "string -> string [[0, 10] .. [0, 10]]\n" + "void -> void [[0, 10] .. [0, 10]]\n" + "} -> } [[0, 10] .. [0, 10]]\n" + "{ -> { [[0, 9] .. [0, 10]]\n" + " + } [[0, 11] .. [0, 11]]\n";
assertEquals(expectedCompletionItems, actualCompletionItems);
}
use of org.eclipse.lsp4j.CompletionParams 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);
}
}
Aggregations