Search in sources :

Example 1 with TestCompletionConfiguration

use of org.eclipse.xtext.testing.TestCompletionConfiguration in project xtext-core by eclipse.

the class CompletionTest method testCompletion_02.

@Test
public void testCompletion_02() {
    final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
        it.setModel("type ");
        it.setColumn(5);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("name (ID) -> name [[0, 5] .. [0, 5]]");
        _builder.newLine();
        it.setExpectedCompletionItems(_builder.toString());
    };
    this.testCompletion(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TestCompletionConfiguration(org.eclipse.xtext.testing.TestCompletionConfiguration) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 2 with TestCompletionConfiguration

use of org.eclipse.xtext.testing.TestCompletionConfiguration 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)

Example 3 with TestCompletionConfiguration

use of org.eclipse.xtext.testing.TestCompletionConfiguration in project xtext-core by eclipse.

the class CompletionTest method testCompletion_01.

@Test
public void testCompletion_01() {
    final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
        it.setModel("");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type -> type [[0, 0] .. [0, 0]]");
        _builder.newLine();
        it.setExpectedCompletionItems(_builder.toString());
    };
    this.testCompletion(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TestCompletionConfiguration(org.eclipse.xtext.testing.TestCompletionConfiguration) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 4 with TestCompletionConfiguration

use of org.eclipse.xtext.testing.TestCompletionConfiguration in project xtext-core by eclipse.

the class CompletionTest method testCompletion_03.

@Test
public void testCompletion_03() {
    final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo {}");
        _builder.newLine();
        _builder.append("type Bar {}");
        _builder.newLine();
        it.setModel(_builder.toString());
        it.setLine(1);
        it.setColumn("type Bar {".length());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("Bar (TypeDeclaration) -> Bar [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("boolean -> boolean [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("int -> int [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("op -> op [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("string -> string [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("void -> void [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("} -> } [[1, 10] .. [1, 10]]");
        _builder_1.newLine();
        _builder_1.append("{ -> { [[1, 9] .. [1, 10]]");
        _builder_1.newLine();
        it.setExpectedCompletionItems(_builder_1.toString());
    };
    this.testCompletion(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TestCompletionConfiguration(org.eclipse.xtext.testing.TestCompletionConfiguration) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 5 with TestCompletionConfiguration

use of org.eclipse.xtext.testing.TestCompletionConfiguration in project xtext-core by eclipse.

the class CompletionTest method testCompletion_04.

@Test
public void testCompletion_04() {
    final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo {");
        _builder.newLine();
        _builder.append("    ");
        _builder.append("Foo foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setModel(_builder.toString());
        it.setLine(1);
        it.setColumn("    Fo".length());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("Foo (TypeDeclaration) -> Foo [[1, 4] .. [1, 6]]");
        _builder_1.newLine();
        _builder_1.append("[ -> [ [[1, 6] .. [1, 6]]");
        _builder_1.newLine();
        it.setExpectedCompletionItems(_builder_1.toString());
    };
    this.testCompletion(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TestCompletionConfiguration(org.eclipse.xtext.testing.TestCompletionConfiguration) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Aggregations

TestCompletionConfiguration (org.eclipse.xtext.testing.TestCompletionConfiguration)6 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)5 Test (org.junit.Test)5 List (java.util.List)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 Position (org.eclipse.lsp4j.Position)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1