Java 类org.eclipse.lsp4j.DocumentFormattingParams 实例源码

项目:eclipse.jdt.ls    文件:FormatterHandlerTest.java   
@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);
}
项目:xtext-core    文件:AbstractLanguageServerTest.java   
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);
  }
}
项目:xtext-core    文件:LanguageServerImpl.java   
@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);
}
项目:eclipse.jdt.ls    文件:FormatterHandlerTest.java   
@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);
}
项目:eclipse.jdt.ls    文件:FormatterHandlerTest.java   
@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);
}
项目:eclipse.jdt.ls    文件:FormatterHandlerTest.java   
@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);

}
项目:xtext-core    文件:FormattingService.java   
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);
}
项目:che    文件:TextDocumentService.java   
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());
  }
}
项目:che    文件:LanguageServerFormatter.java   
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);
}
项目:camel-language-server    文件:CamelTextDocumentService.java   
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
    LOGGER.info("formatting: " + params.getTextDocument());
    return CompletableFuture.completedFuture(Collections.emptyList());
}
项目:SOMns-vscode    文件:SomLanguageServer.java   
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(
    final DocumentFormattingParams params) {
  // TODO Auto-generated method stub
  return null;
}
项目:eclipse.jdt.ls    文件:FormatterHandler.java   
List<? extends org.eclipse.lsp4j.TextEdit> formatting(DocumentFormattingParams params, IProgressMonitor monitor) {
    return format(params.getTextDocument().getUri(), params.getOptions(), null, monitor);
}
项目:eclipse.jdt.ls    文件:JDTLanguageServer.java   
@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)));
}
项目:lsp4j    文件:MockLanguageServer.java   
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
    throw new UnsupportedOperationException();
}
项目:che    文件:MavenTextDocumentService.java   
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
  return null;
}
项目:che    文件:TextDocumentService.java   
@PostConstruct
public void configureMethods() {
  dtoToDtoList(
      "definition", TextDocumentPositionParams.class, LocationDto.class, this::definition);
  dtoToDtoList("codeAction", CodeActionParams.class, CommandDto.class, this::codeAction);
  dtoToDtoList(
      "documentSymbol",
      DocumentSymbolParams.class,
      SymbolInformationDto.class,
      this::documentSymbol);
  dtoToDtoList("formatting", DocumentFormattingParams.class, TextEditDto.class, this::formatting);
  dtoToDtoList(
      "rangeFormatting",
      DocumentRangeFormattingParams.class,
      TextEditDto.class,
      this::rangeFormatting);
  dtoToDtoList("references", ReferenceParams.class, LocationDto.class, this::references);
  dtoToDtoList(
      "onTypeFormatting",
      DocumentOnTypeFormattingParams.class,
      TextEditDto.class,
      this::onTypeFormatting);

  dtoToDto(
      "completionItem/resolve",
      ExtendedCompletionItem.class,
      ExtendedCompletionItemDto.class,
      this::completionItemResolve);
  dtoToDto(
      "documentHighlight",
      TextDocumentPositionParams.class,
      DocumentHighlight.class,
      this::documentHighlight);
  dtoToDto(
      "completion",
      TextDocumentPositionParams.class,
      ExtendedCompletionListDto.class,
      this::completion);
  dtoToDto("hover", TextDocumentPositionParams.class, HoverDto.class, this::hover);
  dtoToDto(
      "signatureHelp",
      TextDocumentPositionParams.class,
      SignatureHelpDto.class,
      this::signatureHelp);

  dtoToDto("rename", RenameParams.class, RenameResultDto.class, this::rename);

  dtoToNothing("didChange", DidChangeTextDocumentParams.class, this::didChange);
  dtoToNothing("didClose", DidCloseTextDocumentParams.class, this::didClose);
  dtoToNothing("didOpen", DidOpenTextDocumentParams.class, this::didOpen);
  dtoToNothing("didSave", DidSaveTextDocumentParams.class, this::didSave);
}
项目:SOMns-vscode    文件:TextDocumentService.java   
/**
 * The document formatting request is sent from the client to the server to
 * format a whole document.
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonRequest
CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params);
项目:lsp4j    文件:TextDocumentService.java   
/**
 * The document formatting request is sent from the client to the server to
 * format a whole document.
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonRequest
CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params);
项目:che    文件:TextDocumentServiceClient.java   
/**
 * GWT client implementation of {@link TextDocumentService#formatting(DocumentFormattingParams)}
 *
 * @param params
 * @return
 */
public Promise<List<TextEdit>> formatting(DocumentFormattingParams params) {
  return transmitDtoAndReceiveDtoList(params, "textDocument/formatting", TextEdit.class);
}