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

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

源代码1 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test
public void testDisableFormattingOnType() throws Exception {
	//@formatter:off
	String text =  "package org.sample;\n"
				+ "\n"
				+ "    public      class     Baz {  \n"
				+ "String          name       ;\n"
				+ "}\n";
			//@formatter:on
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", text);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(3, 28), "\n");
	params.setTextDocument(textDocument);
	params.setOptions(options);
	//Check it's disabled by default
	List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
	assertNotNull(edits);

	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(text, newText);
}
 
源代码2 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing ; should format the current line
public void testFormattingOnTypeSemiColumn() throws Exception {
	javaProject.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);

	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n\n"
		+ "public class Baz {  \n"
		+ "String          name       ;\n"//typed ; here
		+ "}\n"
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, false);// ident == tab

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(3, 27), ";");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
	assertNotNull(edits);


	//@formatter:off
	String expectedText =
		  "package org.sample;\n"
		+ "\n"
		+ "public class Baz {  \n"
		+ "\tString name;\n"
		+ "}\n";
	//@formatter:on

	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(expectedText, newText);
}
 
源代码3 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing new_line should format the current line if previous character doesn't close a block
public void testFormattingOnTypeNewLine() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {  \n"
		+ "String          name       ;\n"//typed \n here
		+ "}\n"
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(3, 28), "\n");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
	assertNotNull(edits);

	//@formatter:off
	String expectedText =
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {  \n"//this part won't be formatted
		+ "        String name;\n"
		+ "}\n";
	//@formatter:on

	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(expectedText, newText);
}
 
源代码4 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing } should format the previous block
public void testFormattingOnTypeCloseBlock() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {  \n"
		+ "String          name       ;\n"
		+ "}  "//typed } here
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(4, 0), "}");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
	assertNotNull(edits);

	//@formatter:off
	String expectedText =
		  "package org.sample;\n"
		+ "\n"
		+ "public class Baz {\n"
		+ "    String name;\n"
		+ "}";
	//@formatter:on

	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(expectedText, newText);
}
 
源代码5 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing new_line after opening a block should only format the current line
public void testFormattingOnTypeReturnAfterOpeningBlock() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {  \n"//typed \n here
		+ "String          name       ;\n"
		+ "}  \n"
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(2, 33), "\n");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(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);
}
 
源代码6 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing new_line after closing a block should format the that block
public void testFormattingOnTypeReturnAfterClosedBlock() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {  \n"
		+ "String          name       ;\n"
		+ "}  \n"//typed \n here
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(4, 3), "\n");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(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);
}
 
源代码7 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing new_line after inserting a new line should format the previous block if previous non-whitespace char is }
public void testFormattingOnTypeReturnAfterEmptyLine() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {  \n"
		+ "String          name       ;\n"
		+ "}  \n"
		+ "   \n"//typed \n here
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(5, 3), "\n");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
	assertNotNull(edits);

	//@formatter:off
	String expectedText =
		  "package org.sample;\n"
		+ "\n"
		+ "public class Baz {\n"
		+ "    String name;\n"
		+ "}\n"
		+ "   \n";
	//@formatter:on

	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(expectedText, newText);
}
 
源代码8 项目: eclipse.jdt.ls   文件: FormatterHandlerTest.java
@Test // typing new_line after an empty block on a single line should format that block
public void testFormattingOnTypeReturnAfterEmptyBlock() throws Exception {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
	//@formatter:off
		  "package org.sample;\n"
		+ "\n"
		+ "    public      class     Baz {}  \n"//typed \n here
	//@formatter:on
	);

	String uri = JDTUtils.toURI(unit);
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces

	DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(2, 34), "\n");
	params.setTextDocument(textDocument);
	params.setOptions(options);

	preferenceManager.getPreferences().setJavaFormatOnTypeEnabled(true);
	List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
	assertNotNull(edits);

	//@formatter:off
	String expectedText =
		  "package org.sample;\n"
		+ "\n"
		+ "public class Baz {\n"
		+ "}\n";
	//@formatter:on

	String newText = TextEditUtil.apply(unit, edits);
	assertEquals(expectedText, newText);
}
 
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
	LOGGER.info("onTypeFormatting: {}", params.getTextDocument());
	return CompletableFuture.completedFuture(Collections.emptyList());
}
 
源代码10 项目: n4js   文件: XLanguageServerImpl.java
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
	throw new UnsupportedOperationException("TODO: auto-generated method stub");
}
 
源代码11 项目: netbeans   文件: TextDocumentServiceImpl.java
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams arg0) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
源代码12 项目: syndesis   文件: TeiidDdlTextDocumentService.java
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
    LOGGER.debug("onTypeFormatting: {}", params.getTextDocument());
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
源代码13 项目: eclipse.jdt.ls   文件: FormatterHandler.java
public List<? extends org.eclipse.lsp4j.TextEdit> onTypeFormatting(DocumentOnTypeFormattingParams params, IProgressMonitor monitor) {
	return format(params.getTextDocument().getUri(), params.getOptions(), params.getPosition(), params.getCh(), monitor);
}
 
源代码14 项目: eclipse.jdt.ls   文件: JDTLanguageServer.java
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
	logInfo(">> document/onTypeFormatting");
	FormatterHandler handler = new FormatterHandler(preferenceManager);
	return computeAsync((monitor) -> handler.onTypeFormatting(params, monitor));
}
 
源代码15 项目: vscode-as3mxml   文件: ActionScriptServices.java
/**
 * This feature is not implemented at this time.
 */
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params)
{
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
源代码16 项目: xtext-core   文件: LanguageServerImpl.java
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
	throw new UnsupportedOperationException("TODO: auto-generated method stub");
}
 
源代码17 项目: lsp4j   文件: TextDocumentService.java
/**
 * The document on type formatting request is sent from the client to the
 * server to format parts of the document during typing.
 * 
 * Registration Options: DocumentOnTypeFormattingRegistrationOptions
 */
@JsonRequest
default CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
	throw new UnsupportedOperationException();
}
 
 类所在包
 同包方法