Search in sources :

Example 1 with Either

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);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Example 2 with Either

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);
}
Also used : Hover(org.eclipse.lsp4j.Hover) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range)

Example 3 with Either

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);
}
Also used : Either(org.eclipse.lsp4j.jsonrpc.messages.Either) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 4 with Either

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);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TestCompletionConfiguration(org.eclipse.xtext.testing.TestCompletionConfiguration) Extension(org.eclipse.xtext.xbase.lib.Extension) CompletionItem(org.eclipse.lsp4j.CompletionItem) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Aggregations

Either (org.eclipse.lsp4j.jsonrpc.messages.Either)4 List (java.util.List)2 CompletionItem (org.eclipse.lsp4j.CompletionItem)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 Position (org.eclipse.lsp4j.Position)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)2 Hover (org.eclipse.lsp4j.Hover)1 MarkedString (org.eclipse.lsp4j.MarkedString)1 Range (org.eclipse.lsp4j.Range)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 TestCompletionConfiguration (org.eclipse.xtext.testing.TestCompletionConfiguration)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1