org.eclipse.lsp4j.WillSaveTextDocumentParams Java Examples
The following examples show how to use
org.eclipse.lsp4j.WillSaveTextDocumentParams.
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: SaveActionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testWillSaveWaitUntil() throws Exception { URI srcUri = project.getFile("src/java/Foo4.java").getRawLocationURI(); ICompilationUnit cu = JDTUtils.resolveCompilationUnit(srcUri); StringBuilder buf = new StringBuilder(); buf.append("package java;\n"); buf.append("\n"); buf.append("public class Foo4 {\n"); buf.append("}\n"); WillSaveTextDocumentParams params = new WillSaveTextDocumentParams(); TextDocumentIdentifier document = new TextDocumentIdentifier(); document.setUri(srcUri.toString()); params.setTextDocument(document); List<TextEdit> result = handler.willSaveWaitUntil(params, monitor); Document doc = new Document(); doc.set(cu.getSource()); assertEquals(TextEditUtil.apply(doc, result), buf.toString()); }
Example #2
Source File: EditorEventManager.java From lsp4intellij with Apache License 2.0 | 5 votes |
/** * Indicates that the document will be saved */ //TODO Manual public void willSave() { if (wrapper.isWillSaveWaitUntil() && !needSave) { willSaveWaitUntil(); } else pool(() -> { if (!editor.isDisposed()) { requestManager.willSave(new WillSaveTextDocumentParams(identifier, TextDocumentSaveReason.Manual)); } }); }
Example #3
Source File: SaveActionHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public List<TextEdit> willSaveWaitUntil(WillSaveTextDocumentParams params, IProgressMonitor monitor) { List<TextEdit> edit = new ArrayList<>(); if (monitor.isCanceled()) { return edit; } String documentUri = params.getTextDocument().getUri(); if (preferenceManager.getPreferences().isJavaSaveActionsOrganizeImportsEnabled()) { edit.addAll(handleSaveActionOrganizeImports(documentUri, monitor)); } return edit; }
Example #4
Source File: SaveActionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testStaticWillSaveWaitUntil() throws Exception { String[] favourites = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getJavaCompletionFavoriteMembers(); try { List<String> list = new ArrayList<>(); list.add("java.lang.Math.*"); list.add("java.util.stream.Collectors.*"); JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setJavaCompletionFavoriteMembers(list); URI srcUri = project.getFile("src/org/sample/Foo6.java").getRawLocationURI(); ICompilationUnit cu = JDTUtils.resolveCompilationUnit(srcUri); /* @formatter:off */ String expected = "package org.sample;\n" + "\n" + "import static java.lang.Math.PI;\n" + "import static java.lang.Math.abs;\n" + "import static java.util.stream.Collectors.toList;\n" + "\n" + "import java.util.List;\n" + "\n" + "public class Foo6 {\n" + " List list = List.of(1).stream().collect(toList());\n" + " double i = abs(-1);\n" + " double pi = PI;\n" + "}\n"; //@formatter:on WillSaveTextDocumentParams params = new WillSaveTextDocumentParams(); TextDocumentIdentifier document = new TextDocumentIdentifier(); document.setUri(srcUri.toString()); params.setTextDocument(document); List<TextEdit> result = handler.willSaveWaitUntil(params, monitor); Document doc = new Document(); doc.set(cu.getSource()); assertEquals(expected, TextEditUtil.apply(doc, result)); } finally { JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setJavaCompletionFavoriteMembers(Arrays.asList(favourites)); } }
Example #5
Source File: JDTLanguageServer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public CompletableFuture<List<TextEdit>> willSaveWaitUntil(WillSaveTextDocumentParams params) { logInfo(">> document/willSaveWaitUntil"); SaveActionHandler handler = new SaveActionHandler(preferenceManager); return computeAsync((monitor) -> handler.willSaveWaitUntil(params, monitor)); }
Example #6
Source File: TextDocumentService.java From lsp4j with Eclipse Public License 2.0 | 2 votes |
/** * The document will save notification is sent from the client to the server before the document is actually saved. * * Registration Options: TextDocumentRegistrationOptions */ @JsonNotification default void willSave(WillSaveTextDocumentParams params) {}
Example #7
Source File: TextDocumentService.java From lsp4j with Eclipse Public License 2.0 | 2 votes |
/** * The document will save request is sent from the client to the server before the document is actually saved. * The request can return an array of TextEdits which will be applied to the text document before it is saved. * Please note that clients might drop results if computing the text edits took too long or if a server constantly fails on this request. * This is done to keep the save fast and reliable. * * Registration Options: TextDocumentRegistrationOptions */ @JsonRequest default CompletableFuture<List<TextEdit>> willSaveWaitUntil(WillSaveTextDocumentParams params) { throw new UnsupportedOperationException(); }