use of org.eclipse.lsp4j.DocumentFormattingParams in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testJavaFormatEnable.
@Test
public void testJavaFormatEnable() throws Exception {
String text = // @formatter:off
"package org.sample ;\n\n" + " public class Baz { String name;}\n";
// @formatter:on"
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", text);
preferenceManager.getPreferences().setJavaFormatEnabled(false);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// ident == 4 spaces
FormattingOptions options = new FormattingOptions(4, true);
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
String newText = TextEditUtil.apply(unit, edits);
assertEquals(text, newText);
}
use of org.eclipse.lsp4j.DocumentFormattingParams in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testDocumentFormatting.
@Test
public void testDocumentFormatting() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"package org.sample ;\n\n" + " public class Baz { String name;}\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// ident == 4 spaces
FormattingOptions options = new FormattingOptions(4, true);
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
// @formatter:off
String expectedText = "package org.sample;\n" + "\n" + "public class Baz {\n" + " String name;\n" + "}\n";
// @formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
use of org.eclipse.lsp4j.DocumentFormattingParams 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(Integer.valueOf(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);
}
}
Aggregations