@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()); }
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; }
@Override public CompletableFuture<List<TextEdit>> willSaveWaitUntil(WillSaveTextDocumentParams params) { logInfo(">> document/willSaveWailUntil"); SaveActionHandler handler = new SaveActionHandler(preferenceManager); return computeAsync((cc) -> handler.willSaveWaitUntil(params, toMonitor(cc))); }
/** * 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) { }
/** * 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(); }