use of org.eclipse.lsp4j.jsonrpc.messages.Either in project xtext-core by eclipse.
the class UnknownProjectConfigTest method checkCompletion.
protected void checkCompletion(final String uri) {
try {
TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
it.setTextDocument(_textDocumentIdentifier);
Position _position = new Position(0, 10);
it.setPosition(_position);
};
TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _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 String actualCompletionItems = this.toExpectation(items);
StringConcatenation _builder = new StringConcatenation();
_builder.append("Foo (TypeDeclaration) -> Foo [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("boolean -> boolean [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("int -> int [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("op -> op [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("string -> string [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("void -> void [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("} -> } [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("{ -> { [[0, 9] .. [0, 10]]");
_builder.newLine();
final String expectedCompletionItems = _builder.toString();
this.assertEquals(expectedCompletionItems, actualCompletionItems);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.jsonrpc.messages.Either in project xtext-core by eclipse.
the class HoverService method hover.
protected Hover hover(final HoverContext context) {
if ((context == null)) {
return IHoverService.EMPTY_HOVER;
}
final List<Either<String, MarkedString>> contents = this.getContents(context);
if ((contents == null)) {
return IHoverService.EMPTY_HOVER;
}
final Range range = this.getRange(context);
if ((range == null)) {
return IHoverService.EMPTY_HOVER;
}
return new Hover(contents, range);
}
use of org.eclipse.lsp4j.jsonrpc.messages.Either in project xtext-core by eclipse.
the class HoverService method getContents.
protected List<Either<String, MarkedString>> getContents(final HoverContext it) {
final String language = this.getLanguage(it);
final Function1<String, Either<String, MarkedString>> _function = (String value) -> {
return this.toContents(language, value);
};
return ListExtensions.<String, Either<String, MarkedString>>map(this.getContents(it.getElement()), _function);
}
use of org.eclipse.lsp4j.jsonrpc.messages.Either 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();
TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams 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);
};
TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _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