use of org.eclipse.lsp4j.FormattingOptions 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.FormattingOptions 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.FormattingOptions in project xtext-core by eclipse.
the class FormattingTest method testRangeFormattingService_02.
@Test
public void testRangeFormattingService_02() {
testRangeFormatting(it -> it.setOptions(new FormattingOptions(4, true)), (RangeFormattingConfiguration it) -> {
it.setModel("type Foo{int bar} type Bar{Foo foo}");
it.setRange(new Range(new Position(0, 0), new Position(0, 17)));
String expectedText = "type Foo{\n" + " int bar\n" + "} type Bar{Foo foo}";
it.setExpectedText(expectedText);
});
}
Aggregations