1 /* 2 * SourceServerOperations.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 package org.rstudio.studio.client.workbench.views.source.model; 16 17 import com.google.gwt.core.client.JavaScriptObject; 18 import com.google.gwt.core.client.JsArray; 19 import com.google.gwt.core.client.JsArrayString; 20 21 import org.rstudio.core.client.js.JsObject; 22 import org.rstudio.studio.client.common.codetools.CodeToolsServerOperations; 23 import org.rstudio.studio.client.common.crypto.CryptoServerOperations; 24 import org.rstudio.studio.client.events.GetEditorContextEvent; 25 import org.rstudio.studio.client.htmlpreview.model.HTMLPreviewServerOperations; 26 import org.rstudio.studio.client.notebook.CompileNotebookOptions; 27 import org.rstudio.studio.client.notebook.CompileNotebookResult; 28 import org.rstudio.studio.client.quarto.model.QuartoServerOperations; 29 import org.rstudio.studio.client.rsconnect.model.RSConnectServerOperations; 30 import org.rstudio.studio.client.server.ServerRequestCallback; 31 import org.rstudio.studio.client.server.Void; 32 import org.rstudio.studio.client.workbench.codesearch.model.CodeSearchServerOperations; 33 import org.rstudio.studio.client.workbench.views.buildtools.model.BuildServerOperations; 34 import org.rstudio.studio.client.workbench.views.files.model.FilesServerOperations; 35 import org.rstudio.studio.client.workbench.views.output.lint.model.LintServerOperations; 36 import org.rstudio.studio.client.workbench.views.presentation.model.PresentationServerOperations; 37 import org.rstudio.studio.client.workbench.views.source.editors.explorer.ObjectExplorerServerOperations; 38 import org.rstudio.studio.client.workbench.views.source.editors.text.IconvListResult; 39 import org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkDefinition; 40 import org.rstudio.studio.client.workbench.views.source.events.AvailablePackagesReadyEvent; 41 42 import java.util.HashMap; 43 import java.util.List; 44 45 /** 46 * The server manages a "working list" of documents that are being edited by 47 * the user. The working list must contain the current "live" contents of 48 * the tab (within a tolerance of a few seconds of latency) regardless of 49 * whether the user has actually hit save. 50 */ 51 public interface SourceServerOperations extends FilesServerOperations, 52 CodeToolsServerOperations, 53 CodeSearchServerOperations, 54 CppServerOperations, 55 TexServerOperations, 56 HTMLPreviewServerOperations, 57 BuildServerOperations, 58 PresentationServerOperations, 59 LintServerOperations, 60 RSConnectServerOperations, 61 ObjectExplorerServerOperations, 62 TestServerOperations, 63 QuartoServerOperations, 64 CryptoServerOperations 65 { 66 /** 67 * Create a new, empty document, without a path but with a unique ID, and 68 * appends it to the current working list. 69 * 70 * The unique ID is necessary to distinguish between multiple docs that 71 * have never been saved. 72 */ newDocument(String fileType, String contents, JsObject properties, ServerRequestCallback<SourceDocument> requestCallback)73 void newDocument(String fileType, 74 String contents, 75 JsObject properties, 76 ServerRequestCallback<SourceDocument> requestCallback); 77 78 /** 79 * Opens a document from disk, assigns it a unique ID, and appends it to 80 * the current working list. 81 */ openDocument(String path, String fileType, String encoding, ServerRequestCallback<SourceDocument> requestCallback)82 void openDocument(String path, 83 String fileType, 84 String encoding, 85 ServerRequestCallback<SourceDocument> requestCallback); 86 87 /** 88 * Saves the given contents for the given ID, and optionally saves it to 89 * a path on disk. 90 * 91 * If path is null, then this is an autosave operation--nothing is written 92 * to the persistent area of disk, whether this ID has a path associated 93 * with it or not. 94 * 95 * If path is non-null, then it's a Save or Save As operation. Data will 96 * be written to the actual file path, and the ID will now be associated 97 * with that path. 98 */ saveDocument(String id, String path, String fileType, String encoding, String foldSpec, JsArray<ChunkDefinition> chunkOutput, String contents, boolean retryWrite, ServerRequestCallback<String> requestCallback)99 void saveDocument(String id, 100 String path, 101 String fileType, 102 String encoding, 103 String foldSpec, 104 JsArray<ChunkDefinition> chunkOutput, 105 String contents, 106 boolean retryWrite, 107 ServerRequestCallback<String> requestCallback); 108 109 /** 110 * Same as saveDocument, but instead of sending the full contents, just 111 * a diff is sent, along with a hash of the contents it expects the server 112 * to currently have (before the diff is applied). 113 * 114 * Note in particular that the semantics for the path parameter is the 115 * same as saveDocument. 116 * 117 * If the return value is null, the save failed for some reason and 118 * saveDocument() should be used as a fallback. If the return value is 119 * non-null, it is the hash value of the new contents. 120 */ saveDocumentDiff(String id, String path, String fileType, String encoding, String foldSpec, JsArray<ChunkDefinition> chunkOutput, String replacement, int offset, int length, boolean valid, String hash, boolean retryWrite, ServerRequestCallback<String> requestCallback)121 void saveDocumentDiff(String id, 122 String path, 123 String fileType, 124 String encoding, 125 String foldSpec, 126 JsArray<ChunkDefinition> chunkOutput, 127 String replacement, 128 int offset, 129 int length, 130 boolean valid, 131 String hash, 132 boolean retryWrite, 133 ServerRequestCallback<String> requestCallback); 134 checkForExternalEdit( String id, ServerRequestCallback<CheckForExternalEditResult> requestCallback)135 void checkForExternalEdit( 136 String id, 137 ServerRequestCallback<CheckForExternalEditResult> requestCallback); 138 ignoreExternalEdit(String id, ServerRequestCallback<Void> requestCallback)139 void ignoreExternalEdit(String id, 140 ServerRequestCallback<Void> requestCallback); 141 142 /** 143 * Removes an item from the working list. 144 */ closeDocument(String id, ServerRequestCallback<Void> requestCallback)145 void closeDocument(String id, ServerRequestCallback<Void> requestCallback); 146 147 /** 148 * Clears the working list. 149 */ closeAllDocuments(ServerRequestCallback<Void> requestCallback)150 void closeAllDocuments(ServerRequestCallback<Void> requestCallback); 151 setSourceDocumentOnSave(String id, boolean shouldSourceOnSave, ServerRequestCallback<Void> requestCallback)152 void setSourceDocumentOnSave(String id, boolean shouldSourceOnSave, 153 ServerRequestCallback<Void> requestCallback); 154 saveActiveDocument(String contents, boolean sweave, String rnwWeave, ServerRequestCallback<Void> requestCallback)155 void saveActiveDocument(String contents, 156 boolean sweave, 157 String rnwWeave, 158 ServerRequestCallback<Void> requestCallback); 159 160 /** 161 * Applies the values in the given HashMap to the document's property bag. 162 * This does NOT replace all of the doc's properties on the server; any 163 * properties that already exist but are not present in the HashMap, are 164 * left unchanged. If a HashMap entry has a null value, that property 165 * should be removed. 166 * These properties are durable (they exist even after the document closed). 167 * This makes them suitable for long-term document meta-data such as 168 * publishing history. However, note that they are actually associated with 169 * the path rather than the document and are not currently cleaned up if 170 * files are deleted. Therefore they can be "resurrected" to be associated 171 * with a different file if another file with the same path is created. 172 */ modifyDocumentProperties(String id, HashMap<String, String> properties, ServerRequestCallback<Void> requestCallback)173 void modifyDocumentProperties(String id, HashMap<String, String> properties, 174 ServerRequestCallback<Void> requestCallback); 175 getDocumentProperties(String path, ServerRequestCallback<JsObject> requestCallback)176 void getDocumentProperties(String path, 177 ServerRequestCallback<JsObject> requestCallback); 178 revertDocument(String id, String fileType, ServerRequestCallback<SourceDocument> requestCallback)179 void revertDocument(String id, 180 String fileType, 181 ServerRequestCallback<SourceDocument> requestCallback); 182 reopenWithEncoding( String id, String encoding, ServerRequestCallback<SourceDocument> requestCallback)183 void reopenWithEncoding( 184 String id, 185 String encoding, 186 ServerRequestCallback<SourceDocument> requestCallback); 187 removeContentUrl(String contentUrl, ServerRequestCallback<Void> requestCallback)188 void removeContentUrl(String contentUrl, 189 ServerRequestCallback<Void> requestCallback); 190 detectFreeVars(String code, ServerRequestCallback<JsArrayString> requestCallback)191 void detectFreeVars(String code, 192 ServerRequestCallback<JsArrayString> requestCallback); 193 iconvlist(ServerRequestCallback<IconvListResult> requestCallback)194 void iconvlist(ServerRequestCallback<IconvListResult> requestCallback); 195 getSourceTemplate(String name, String template, ServerRequestCallback<String> requestCallback)196 void getSourceTemplate(String name, 197 String template, 198 ServerRequestCallback<String> requestCallback); 199 createRdShell(String name, String type, ServerRequestCallback<RdShellResult> requestCallback)200 void createRdShell(String name, 201 String type, 202 ServerRequestCallback<RdShellResult> requestCallback); 203 204 createNotebook( CompileNotebookOptions options, ServerRequestCallback<CompileNotebookResult> requestCallback)205 void createNotebook( 206 CompileNotebookOptions options, 207 ServerRequestCallback<CompileNotebookResult> requestCallback); 208 isReadOnlyFile(String path, ServerRequestCallback<Boolean> requestCallback)209 void isReadOnlyFile(String path, 210 ServerRequestCallback<Boolean> requestCallback); 211 getScriptRunCommand(String interpreter, String path, ServerRequestCallback<String> requestCallback)212 void getScriptRunCommand(String interpreter, 213 String path, 214 ServerRequestCallback<String> requestCallback); 215 getMinimalSourcePath(String path, ServerRequestCallback<String> requestCallback)216 void getMinimalSourcePath(String path, 217 ServerRequestCallback<String> requestCallback); 218 setDocOrder( List<String> order, ServerRequestCallback<Void> requestCallback)219 void setDocOrder( 220 List<String> order, ServerRequestCallback<Void> requestCallback); 221 removeCachedData(String cacheKey, ServerRequestCallback<Void> requestCallback)222 void removeCachedData(String cacheKey, 223 ServerRequestCallback<Void> requestCallback); 224 ensureFileExists(String path, ServerRequestCallback<Boolean> requestCallback)225 void ensureFileExists(String path, 226 ServerRequestCallback<Boolean> requestCallback); 227 getFileContents(String path, String encoding, ServerRequestCallback<String> requestCallback)228 public void getFileContents(String path, 229 String encoding, 230 ServerRequestCallback<String> requestCallback); 231 executeRCode(String code, ServerRequestCallback<String> requestCallback)232 public void executeRCode(String code, 233 ServerRequestCallback<String> requestCallback); 234 getSourceDocument(String docId, ServerRequestCallback<SourceDocument> requestCallback)235 public void getSourceDocument(String docId, 236 ServerRequestCallback<SourceDocument> requestCallback); 237 createShinyApp(String appName, String appType, String appDir, ServerRequestCallback<JsArrayString> requestCallback)238 public void createShinyApp(String appName, 239 String appType, 240 String appDir, 241 ServerRequestCallback<JsArrayString> requestCallback); 242 getEditorContextCompleted(GetEditorContextEvent.SelectionData data, ServerRequestCallback<Void> requestCallback)243 public void getEditorContextCompleted(GetEditorContextEvent.SelectionData data, 244 ServerRequestCallback<Void> requestCallback); 245 setSourceDocumentDirty(String docId, boolean dirty, ServerRequestCallback<Void> requestCallback)246 public void setSourceDocumentDirty(String docId, boolean dirty, 247 ServerRequestCallback<Void> requestCallback); 248 extractRmdFromNotebook(String inputPath, ServerRequestCallback<SourceDocumentResult> requestCallback)249 public void extractRmdFromNotebook(String inputPath, 250 ServerRequestCallback<SourceDocumentResult> requestCallback); 251 defaultSqlConnectionName(ServerRequestCallback<String> requestCallback)252 public void defaultSqlConnectionName(ServerRequestCallback<String> requestCallback); 253 requestDocumentSaveCompleted(boolean isSuccessfulSave, ServerRequestCallback<Void> requestCallback)254 public void requestDocumentSaveCompleted(boolean isSuccessfulSave, 255 ServerRequestCallback<Void> requestCallback); 256 requestDocumentCloseCompleted(boolean isSuccessfulClose, ServerRequestCallback<Void> requestCallback)257 public void requestDocumentCloseCompleted(boolean isSuccessfulClose, 258 ServerRequestCallback<Void> requestCallback); 259 adaptToLanguage(String language, ServerRequestCallback<Void> requestCallback)260 public void adaptToLanguage(String language, ServerRequestCallback<Void> requestCallback); 261 createPlumberAPI(String apiName, String apiDir, ServerRequestCallback<JsArrayString> requestCallback)262 public void createPlumberAPI(String apiName, 263 String apiDir, 264 ServerRequestCallback<JsArrayString> requestCallback); 265 discoverPackageDependencies(String id, String fileType, ServerRequestCallback<AvailablePackagesReadyEvent.Data> requestCallback)266 void discoverPackageDependencies(String id, 267 String fileType, 268 ServerRequestCallback<AvailablePackagesReadyEvent.Data> requestCallback); 269 replaceCommentHeader(String command, String path, String code, ServerRequestCallback<String> requestCallback)270 public void replaceCommentHeader(String command, 271 String path, 272 String code, 273 ServerRequestCallback<String> requestCallback); 274 rstudioApiResponse(JavaScriptObject response, ServerRequestCallback<Void> requestCallback)275 public void rstudioApiResponse(JavaScriptObject response, 276 ServerRequestCallback<Void> requestCallback); 277 } 278