本文整理汇总了Java中org.eclipse.lsp4j.DocumentFormattingParams类的典型用法代码示例。如果您正苦于以下问题:Java DocumentFormattingParams类的具体用法?Java DocumentFormattingParams怎么用?Java DocumentFormattingParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentFormattingParams类属于org.eclipse.lsp4j包,在下文中一共展示了DocumentFormattingParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJavaFormatEnable
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@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);
FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces
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);
}
示例2: testFormatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
protected void testFormatting(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);
};
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.assertEquals(configuration.getExpectedText(), result.getContents());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例3: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(final DocumentFormattingParams params) {
final Function1<CancelIndicator, List<? extends TextEdit>> _function = (CancelIndicator cancelIndicator) -> {
final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
FormattingService _get = null;
if (resourceServiceProvider!=null) {
_get=resourceServiceProvider.<FormattingService>get(FormattingService.class);
}
final FormattingService formatterService = _get;
if ((formatterService == null)) {
return CollectionLiterals.<TextEdit>emptyList();
}
final Function2<Document, XtextResource, List<? extends TextEdit>> _function_1 = (Document document, XtextResource resource) -> {
return formatterService.format(document, resource, params, cancelIndicator);
};
return this.workspaceManager.<List<? extends TextEdit>>doRead(uri, _function_1);
};
return this.requestManager.<List<? extends TextEdit>>runRead(_function);
}
示例4: testDocumentFormatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@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"
//@formatter:on
);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces
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);
}
示例5: testDocumentFormattingWithTabs
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Test
public void testDocumentFormattingWithTabs() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
//@formatter:off
"package org.sample;\n\n" +
"public class Baz {\n"+
" void foo(){\n"+
"}\n"+
"}\n"
//@formatter:on
);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
FormattingOptions options = new FormattingOptions(2, false);// ident == tab
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"+
"\tvoid foo() {\n"+
"\t}\n"+
"}\n";
//@formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
示例6: testFormatting_onOffTags
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Test
public void testFormatting_onOffTags() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
//@formatter:off
"package org.sample;\n\n" +
" public class Baz {\n"+
"// @formatter:off\n"+
"\tvoid foo(){\n"+
" }\n"+
"// @formatter:on\n"+
"}\n"
//@formatter:off
);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
FormattingOptions options = new FormattingOptions(4, false);// ident == tab
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"+
"// @formatter:off\n"+
"\tvoid foo(){\n"+
" }\n"+
"// @formatter:on\n"+
"}\n";
//@formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
示例7: format
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
public List<? extends TextEdit> format(final Document document, final XtextResource resource, final DocumentFormattingParams params, final CancelIndicator cancelIndicator) {
final int offset = 0;
final int length = document.getContents().length();
if (((length == 0) || resource.getContents().isEmpty())) {
return CollectionLiterals.<TextEdit>emptyList();
}
return this.format(resource, document, offset, length);
}
示例8: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
private List<TextEditDto> formatting(DocumentFormattingParams documentFormattingParams) {
try {
String uri = prefixURI(documentFormattingParams.getTextDocument().getUri());
documentFormattingParams.getTextDocument().setUri(uri);
InitializedLanguageServer server =
languageServerRegistry
.getApplicableLanguageServers(uri)
.stream()
.flatMap(Collection::stream)
.filter(
s ->
truish(
s.getInitializeResult()
.getCapabilities()
.getDocumentFormattingProvider()))
.findFirst()
.get();
return server == null
? Collections.emptyList()
: server
.getServer()
.getTextDocumentService()
.formatting(documentFormattingParams)
.get(5000, TimeUnit.MILLISECONDS)
.stream()
.map(TextEditDto::new)
.collect(Collectors.toList());
} catch (InterruptedException
| ExecutionException
| LanguageServerException
| TimeoutException e) {
throw new JsonRpcException(-27000, e.getMessage());
}
}
示例9: formatFullDocument
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
private void formatFullDocument(Document document) {
DocumentFormattingParams params = dtoFactory.createDto(DocumentFormattingParams.class);
TextDocumentIdentifier identifier = dtoFactory.createDto(TextDocumentIdentifier.class);
identifier.setUri(document.getFile().getLocation().toString());
params.setTextDocument(identifier);
params.setOptions(getFormattingOptions());
Promise<List<TextEdit>> promise = client.formatting(params);
handleFormatting(promise, document);
}
示例10: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
LOGGER.info("formatting: " + params.getTextDocument());
return CompletableFuture.completedFuture(Collections.emptyList());
}
示例11: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(
final DocumentFormattingParams params) {
// TODO Auto-generated method stub
return null;
}
示例12: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
List<? extends org.eclipse.lsp4j.TextEdit> formatting(DocumentFormattingParams params, IProgressMonitor monitor) {
return format(params.getTextDocument().getUri(), params.getOptions(), null, monitor);
}
示例13: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
logInfo(">> document/formatting");
FormatterHandler handler = new FormatterHandler(preferenceManager);
return computeAsync((cc) -> handler.formatting(params, toMonitor(cc)));
}
示例14: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
throw new UnsupportedOperationException();
}
示例15: formatting
import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
return null;
}