Search in sources :

Example 1 with FormattingConfiguration

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

the class FormattingTest method testFormattingClosedFile.

@Test
public void testFormattingClosedFile() {
    final Procedure1<FormattingConfiguration> _function = (FormattingConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo{int bar} type Bar{Foo foo}");
        Pair<String, String> _mappedTo = Pair.<String, String>of("foo.testlang", _builder.toString());
        it.setFilesInScope(Collections.<String, CharSequence>unmodifiableMap(CollectionLiterals.<String, CharSequence>newHashMap(_mappedTo)));
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("type Foo{");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("int bar");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("type Bar{");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("Foo foo");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        it.setExpectedText(_builder_1.toString());
    };
    this.testFormatting(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) FormattingConfiguration(org.eclipse.xtext.testing.FormattingConfiguration) RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) Pair(org.eclipse.xtext.xbase.lib.Pair) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest) Test(org.junit.Test)

Example 2 with FormattingConfiguration

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

the class AbstractLanguageServerTest method testFormatting.

protected void testFormatting(final Procedure1<? super DocumentFormattingParams> paramsConfigurator, final Procedure1<? super FormattingConfiguration> configurator) {
    try {
        @Extension final FormattingConfiguration configuration = new FormattingConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final FileInfo fileInfo = this.initializeContext(configuration);
        DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
        final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
            String _uri = fileInfo.getUri();
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
            it.setTextDocument(_textDocumentIdentifier);
            if ((paramsConfigurator != null)) {
                paramsConfigurator.apply(it);
            }
        };
        DocumentFormattingParams _doubleArrow = ObjectExtensions.<DocumentFormattingParams>operator_doubleArrow(_documentFormattingParams, _function);
        final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.formatting(_doubleArrow);
        String _contents = fileInfo.getContents();
        final Document result = new Document(1, _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[]) Conversions.unwrapArray(changes.get(), TextEdit.class)))));
        this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FileInfo(org.eclipse.xtext.testing.FileInfo) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) TextEdit(org.eclipse.lsp4j.TextEdit) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) FormattingConfiguration(org.eclipse.xtext.testing.FormattingConfiguration) RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) Document(org.eclipse.xtext.ide.server.Document)

Example 3 with FormattingConfiguration

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

the class FormattingTest method testFormattingService.

@Test
public void testFormattingService() {
    final Procedure1<FormattingConfiguration> _function = (FormattingConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo{int bar} type Bar{Foo foo}");
        it.setModel(_builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("type Foo{");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("int bar");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("type Bar{");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("Foo foo");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        it.setExpectedText(_builder_1.toString());
    };
    this.testFormatting(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) FormattingConfiguration(org.eclipse.xtext.testing.FormattingConfiguration) RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest) Test(org.junit.Test)

Example 4 with FormattingConfiguration

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

the class FormattingTest method testFormattingService_02.

@Test
public void testFormattingService_02() {
    final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
        FormattingOptions _formattingOptions = new FormattingOptions(4, true);
        it.setOptions(_formattingOptions);
    };
    final Procedure1<FormattingConfiguration> _function_1 = (FormattingConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo{int bar} type Bar{Foo foo}");
        it.setModel(_builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("type Foo{");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("int bar");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("type Bar{");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("Foo foo");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        it.setExpectedText(_builder_1.toString());
    };
    this.testFormatting(_function, _function_1);
}
Also used : FormattingOptions(org.eclipse.lsp4j.FormattingOptions) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) FormattingConfiguration(org.eclipse.xtext.testing.FormattingConfiguration) RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest) Test(org.junit.Test)

Aggregations

FormattingConfiguration (org.eclipse.xtext.testing.FormattingConfiguration)4 RangeFormattingConfiguration (org.eclipse.xtext.testing.RangeFormattingConfiguration)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)3 Test (org.junit.Test)3 DocumentFormattingParams (org.eclipse.lsp4j.DocumentFormattingParams)2 List (java.util.List)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 FormattingOptions (org.eclipse.lsp4j.FormattingOptions)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 TextEdit (org.eclipse.lsp4j.TextEdit)1 Document (org.eclipse.xtext.ide.server.Document)1 FileInfo (org.eclipse.xtext.testing.FileInfo)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1