Search in sources :

Example 1 with RangeFormattingConfiguration

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

the class AbstractLanguageServerTest method testRangeFormatting.

protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
    try {
        @Extension final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final FileInfo fileInfo = this.initializeContext(configuration);
        DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
        final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
            String _uri = fileInfo.getUri();
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
            it.setTextDocument(_textDocumentIdentifier);
            it.setRange(configuration.getRange());
            if ((paramsConfigurator != null)) {
                paramsConfigurator.apply(it);
            }
        };
        DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
        final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_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) RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) FileInfo(org.eclipse.xtext.testing.FileInfo) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) TextEdit(org.eclipse.lsp4j.TextEdit) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) Document(org.eclipse.xtext.ide.server.Document)

Example 2 with RangeFormattingConfiguration

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

the class FormattingTest method testRangeFormattingService.

@Test
public void testRangeFormattingService() {
    final Procedure1<RangeFormattingConfiguration> _function = (RangeFormattingConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo{int bar} type Bar{Foo foo}");
        it.setModel(_builder.toString());
        Range _range = new Range();
        final Procedure1<Range> _function_1 = (Range it_1) -> {
            Position _position = new Position(0, 0);
            it_1.setStart(_position);
            Position _position_1 = new Position(0, 17);
            it_1.setEnd(_position_1);
        };
        Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
        it.setRange(_doubleArrow);
        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("} type Bar{Foo foo}");
        it.setExpectedText(_builder_1.toString());
    };
    this.testRangeFormatting(_function);
}
Also used : RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) Position(org.eclipse.lsp4j.Position) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Range(org.eclipse.lsp4j.Range) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest) Test(org.junit.Test)

Example 3 with RangeFormattingConfiguration

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

the class FormattingTest method testRangeFormattingService_02.

@Test
public void testRangeFormattingService_02() {
    final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
        FormattingOptions _formattingOptions = new FormattingOptions(4, true);
        it.setOptions(_formattingOptions);
    };
    final Procedure1<RangeFormattingConfiguration> _function_1 = (RangeFormattingConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo{int bar} type Bar{Foo foo}");
        it.setModel(_builder.toString());
        Range _range = new Range();
        final Procedure1<Range> _function_2 = (Range it_1) -> {
            Position _position = new Position(0, 0);
            it_1.setStart(_position);
            Position _position_1 = new Position(0, 17);
            it_1.setEnd(_position_1);
        };
        Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_2);
        it.setRange(_doubleArrow);
        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("} type Bar{Foo foo}");
        it.setExpectedText(_builder_1.toString());
    };
    this.testRangeFormatting(_function, _function_1);
}
Also used : FormattingOptions(org.eclipse.lsp4j.FormattingOptions) RangeFormattingConfiguration(org.eclipse.xtext.testing.RangeFormattingConfiguration) Position(org.eclipse.lsp4j.Position) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Range(org.eclipse.lsp4j.Range) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest) Test(org.junit.Test)

Aggregations

RangeFormattingConfiguration (org.eclipse.xtext.testing.RangeFormattingConfiguration)3 DocumentRangeFormattingParams (org.eclipse.lsp4j.DocumentRangeFormattingParams)2 Position (org.eclipse.lsp4j.Position)2 Range (org.eclipse.lsp4j.Range)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 Test (org.junit.Test)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