当前位置: 首页>>代码示例>>Java>>正文


Java DocumentFormattingParams类代码示例

本文整理汇总了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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:FormatterHandlerTest.java

示例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);
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:23,代码来源:AbstractLanguageServerTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:LanguageServerImpl.java

示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:29,代码来源:FormatterHandlerTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:FormatterHandlerTest.java

示例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);

}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:FormatterHandlerTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:9,代码来源:FormattingService.java

示例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());
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:TextDocumentService.java

示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:LanguageServerFormatter.java

示例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());
}
 
开发者ID:lhein,项目名称:camel-language-server,代码行数:6,代码来源:CamelTextDocumentService.java

示例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;
}
 
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:7,代码来源:SomLanguageServer.java

示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:4,代码来源:FormatterHandler.java

示例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)));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:7,代码来源:JDTLanguageServer.java

示例14: formatting

import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
	throw new UnsupportedOperationException();
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:5,代码来源:MockLanguageServer.java

示例15: formatting

import org.eclipse.lsp4j.DocumentFormattingParams; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:5,代码来源:MavenTextDocumentService.java


注:本文中的org.eclipse.lsp4j.DocumentFormattingParams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。