org.eclipse.lsp4j.DocumentOnTypeFormattingParams Java Examples
The following examples show how to use
org.eclipse.lsp4j.DocumentOnTypeFormattingParams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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); }
Example #2
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #3
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #4
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #5
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #6
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #7
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #8
Source File: FormatterHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #9
Source File: XLanguageServerImpl.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) { throw new UnsupportedOperationException("TODO: auto-generated method stub"); }
Example #10
Source File: LanguageServerImpl.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) { throw new UnsupportedOperationException("TODO: auto-generated method stub"); }
Example #11
Source File: ActionScriptServices.java From vscode-as3mxml with Apache License 2.0 | 4 votes |
/** * This feature is not implemented at this time. */ @Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) { return CompletableFuture.completedFuture(Collections.emptyList()); }
Example #12
Source File: JDTLanguageServer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) { logInfo(">> document/onTypeFormatting"); FormatterHandler handler = new FormatterHandler(preferenceManager); return computeAsync((monitor) -> handler.onTypeFormatting(params, monitor)); }
Example #13
Source File: FormatterHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public List<? extends org.eclipse.lsp4j.TextEdit> onTypeFormatting(DocumentOnTypeFormattingParams params, IProgressMonitor monitor) { return format(params.getTextDocument().getUri(), params.getOptions(), params.getPosition(), params.getCh(), monitor); }
Example #14
Source File: TeiidDdlTextDocumentService.java From syndesis with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) { LOGGER.debug("onTypeFormatting: {}", params.getTextDocument()); return CompletableFuture.completedFuture(Collections.emptyList()); }
Example #15
Source File: TextDocumentServiceImpl.java From netbeans with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams arg0) { throw new UnsupportedOperationException("Not supported yet."); }
Example #16
Source File: CamelTextDocumentService.java From camel-language-server with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) { LOGGER.info("onTypeFormatting: {}", params.getTextDocument()); return CompletableFuture.completedFuture(Collections.emptyList()); }
Example #17
Source File: TextDocumentService.java From lsp4j with Eclipse Public License 2.0 | 2 votes |
/** * 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(); }