Search in sources :

Example 1 with FileInfo

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

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

Aggregations

List (java.util.List)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 TextEdit (org.eclipse.lsp4j.TextEdit)2 Document (org.eclipse.xtext.ide.server.Document)2 FileInfo (org.eclipse.xtext.testing.FileInfo)2 RangeFormattingConfiguration (org.eclipse.xtext.testing.RangeFormattingConfiguration)2 Extension (org.eclipse.xtext.xbase.lib.Extension)2 DocumentFormattingParams (org.eclipse.lsp4j.DocumentFormattingParams)1 DocumentRangeFormattingParams (org.eclipse.lsp4j.DocumentRangeFormattingParams)1 FormattingConfiguration (org.eclipse.xtext.testing.FormattingConfiguration)1