类org.eclipse.lsp4j.DocumentRangeFormattingParams源码实例Demo

下面列出了怎么用org.eclipse.lsp4j.DocumentRangeFormattingParams的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netbeans   文件: Formatter.java
private void rangeFormat(FileObject fo, LSPBindings bindings) throws BadLocationException {
    DocumentRangeFormattingParams drfp = new DocumentRangeFormattingParams();
    drfp.setTextDocument(new TextDocumentIdentifier(Utils.toURI(fo)));
    drfp.setOptions(new FormattingOptions(
        IndentUtils.indentLevelSize(ctx.document()),
        IndentUtils.isExpandTabs(ctx.document())));
    drfp.setRange(new Range(
        Utils.createPosition(ctx.document(), ctx.startOffset()),
        Utils.createPosition(ctx.document(), ctx.endOffset())));
    List<TextEdit> edits = new ArrayList<>();
    try {
        edits = new ArrayList<>(bindings.getTextDocumentService().rangeFormatting(drfp).get());
    } catch (InterruptedException | ExecutionException ex) {
        LOG.log(Level.INFO,
            String.format("LSP document rangeFormat failed for {0}", fo),
            ex);
    }

    applyTextEdits(edits);
}
 
源代码2 项目: xtext-core   文件: AbstractLanguageServerTest.java
protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
  try {
    @Extension
    final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
    final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
      it.setRange(configuration.getRange());
      if ((paramsConfigurator != null)) {
        paramsConfigurator.apply(it);
      }
    };
    DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_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);
  }
}
 
源代码3 项目: lsp4intellij   文件: EditorEventManager.java
/**
 * Reformat the text currently selected in the editor
 */
public void reformatSelection() {
    pool(() -> {
        if (editor.isDisposed()) {
            return;
        }
        DocumentRangeFormattingParams params = new DocumentRangeFormattingParams();
        params.setTextDocument(identifier);
        SelectionModel selectionModel = editor.getSelectionModel();
        int start = computableReadAction(selectionModel::getSelectionStart);
        int end = computableReadAction(selectionModel::getSelectionEnd);
        Position startingPos = DocumentUtils.offsetToLSPPos(editor, start);
        Position endPos = DocumentUtils.offsetToLSPPos(editor, end);
        params.setRange(new Range(startingPos, endPos));
        // Todo - Make Formatting Options configurable
        FormattingOptions options = new FormattingOptions();
        params.setOptions(options);

        CompletableFuture<List<? extends TextEdit>> request = requestManager.rangeFormatting(params);
        if (request == null) {
            return;
        }
        request.thenAccept(formatting -> {
            if (formatting == null) {
                return;
            }
            invokeLater(() -> {
                if (!editor.isDisposed()) {
                    applyEdit((List<TextEdit>) formatting, "Reformat selection", false);
                }
            });
        });
    });
}
 
源代码4 项目: lemminx   文件: XMLTextDocumentService.java
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
	return computeAsync((cancelChecker) -> {
		String uri = params.getTextDocument().getUri();
		TextDocument document = getDocument(uri);
		CompositeSettings settings = new CompositeSettings(getSharedSettings(), params.getOptions());
		return getXMLLanguageService().format(document, params.getRange(), settings);
	});
}
 
源代码5 项目: n4js   文件: XLanguageServerImpl.java
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
	URI uri = getURI(params.getTextDocument());
	return openFilesManager.runInOpenFileContext(uri, "rangeFormatting", (ofc, ci) -> {
		return rangeFormatting(ofc, params, ci);
	});
}
 
源代码6 项目: n4js   文件: XLanguageServerImpl.java
/**
 * Create the text edits for the formatter. Executed in a read request.
 */
protected List<? extends TextEdit> rangeFormatting(OpenFileContext ofc, DocumentRangeFormattingParams params,
		CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	FormattingService formatterService = getService(uri, FormattingService.class);
	if ((formatterService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	return formatterService.format(doc, res, params, cancelIndicator);
}
 
源代码7 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test
public void testRangeFormatting() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		"package org.sample;\n" +
		"      public class Baz {\n"+
		"\tvoid foo(){\n" +
		"    }\n"+
		"	}\n"
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);

	Range range = new Range(new Position(2, 0), new Position(3, 5));// range around foo()
	DocumentRangeFormattingParams params = new DocumentRangeFormattingParams(range);
	params.setTextDocument(textDocument);
	params.setOptions(new FormattingOptions(3, true));// ident == 3 spaces

	List<? extends TextEdit> edits = server.rangeFormatting(params).get();
	//@formatter:off
	String expectedText =
		"package org.sample;\n" +
		"      public class Baz {\n"+
		"         void foo() {\n" +
		"         }\n"+
		"	}\n";
	//@formatter:on
	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(expectedText, newText);
}
 
源代码8 项目: xtext-core   文件: LanguageServerImpl.java
/**
 * Create the text edits for the formatter. Executed in a read request.
 * @since 2.20
 */
protected List<? extends TextEdit> rangeFormatting(DocumentRangeFormattingParams params,
		CancelIndicator cancelIndicator) {
	URI uri = getURI(params.getTextDocument());
	FormattingService formatterService = getService(uri, FormattingService.class);
	if (formatterService == null) {
		return Collections.emptyList();
	}
	return workspaceManager.doRead(uri,
			(document, resource) -> formatterService.format(document, resource, params, cancelIndicator));
}
 
源代码9 项目: xtext-core   文件: FormattingService.java
public List<? extends TextEdit> format(Document document, XtextResource resource,
		DocumentRangeFormattingParams params, CancelIndicator cancelIndicator) {
	int startOffset = document.getOffSet(params.getRange().getStart());
	int endOffset = document.getOffSet(params.getRange().getEnd());
	int length = endOffset - startOffset;
	return format(resource, document, startOffset, length, params.getOptions());
}
 
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
	LOGGER.info("rangeFormatting: {}", params.getTextDocument());
	return CompletableFuture.completedFuture(Collections.emptyList());
}
 
源代码11 项目: netbeans   文件: TextDocumentServiceImpl.java
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams arg0) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
源代码12 项目: syndesis   文件: TeiidDdlTextDocumentService.java
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
    LOGGER.debug("rangeFormatting: {}", params.getTextDocument());
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
源代码13 项目: eclipse.jdt.ls   文件: FormatterHandler.java
List<? extends org.eclipse.lsp4j.TextEdit> rangeFormatting(DocumentRangeFormattingParams params, IProgressMonitor monitor) {
	return format(params.getTextDocument().getUri(), params.getOptions(), params.getRange(), monitor);
}
 
源代码14 项目: eclipse.jdt.ls   文件: JDTLanguageServer.java
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
	logInfo(">> document/rangeFormatting");
	FormatterHandler handler = new FormatterHandler(preferenceManager);
	return computeAsync((monitor) -> handler.rangeFormatting(params, monitor));
}
 
源代码15 项目: vscode-as3mxml   文件: ActionScriptServices.java
/**
 * This feature is not implemented at this time.
 */
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params)
{
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
源代码16 项目: xtext-core   文件: LanguageServerImpl.java
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
	return requestManager.runRead((cancelIndicator) -> rangeFormatting(params, cancelIndicator));
}
 
源代码17 项目: lsp4j   文件: TextDocumentService.java
/**
 * The document range formatting request is sent from the client to the
 * server to format a given range in a document.
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonRequest
default CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
	throw new UnsupportedOperationException();
}
 
 类所在包
 类方法
 同包方法