@@ -1099,67 +1099,70 @@ export interface IActiveResourceService {
1099
1099
//#region Custom editors: https://github.com/microsoft/vscode/issues/77131
1100
1100
1101
1101
// tslint:disable: interface-name
1102
-
1103
- /**
1104
- * Defines the capabilities of a custom webview editor.
1105
- */
1106
- export interface CustomEditorCapabilities {
1107
- /**
1108
- * Defines the editing capability of a custom webview document.
1109
- *
1110
- * When not provided, the document is considered readonly.
1111
- */
1112
- readonly editing ?: CustomEditorEditingCapability ;
1113
- }
1114
-
1115
1102
/**
1116
1103
* Defines the editing capability of a custom webview editor. This allows the webview editor to hook into standard
1117
1104
* editor events such as `undo` or `save`.
1118
1105
*
1119
1106
* @param EditType Type of edits.
1120
1107
*/
1121
- export interface CustomEditorEditingCapability < EditType = unknown > {
1108
+ export interface CustomEditorEditingDelegate < EditType = unknown > {
1122
1109
/**
1123
1110
* Event triggered by extensions to signal to VS Code that an edit has occurred.
1124
1111
*/
1125
- readonly onDidEdit : Event < EditType > ;
1112
+ readonly onDidEdit : Event < CustomDocumentEditEvent < EditType > > ;
1126
1113
/**
1127
1114
* Save the resource.
1128
1115
*
1116
+ * @param document Document to save.
1117
+ * @param cancellation Token that signals the save is no longer required (for example, if another save was triggered).
1118
+ *
1129
1119
* @return Thenable signaling that the save has completed.
1130
1120
*/
1131
- save ( ) : Thenable < void > ;
1121
+ save ( document : CustomDocument , cancellation : CancellationToken ) : Thenable < void > ;
1132
1122
1133
1123
/**
1134
1124
* Save the existing resource at a new path.
1135
1125
*
1126
+ * @param document Document to save.
1136
1127
* @param targetResource Location to save to.
1137
1128
*
1138
1129
* @return Thenable signaling that the save has completed.
1139
1130
*/
1140
- saveAs ( targetResource : Uri ) : Thenable < void > ;
1131
+ saveAs ( document : CustomDocument , targetResource : Uri ) : Thenable < void > ;
1141
1132
1142
1133
/**
1143
1134
* Apply a set of edits.
1144
1135
*
1145
1136
* Note that is not invoked when `onDidEdit` is called because `onDidEdit` implies also updating the view to reflect the edit.
1146
1137
*
1138
+ * @param document Document to apply edits to.
1147
1139
* @param edit Array of edits. Sorted from oldest to most recent.
1148
1140
*
1149
1141
* @return Thenable signaling that the change has completed.
1150
1142
*/
1151
- applyEdits ( edits : readonly EditType [ ] ) : Thenable < void > ;
1143
+ applyEdits ( document : CustomDocument , edits : readonly EditType [ ] ) : Thenable < void > ;
1152
1144
1153
1145
/**
1154
1146
* Undo a set of edits.
1155
1147
*
1156
- * This is triggered when a user undoes an edit or when revert is called on a file .
1148
+ * This is triggered when a user undoes an edit.
1157
1149
*
1150
+ * @param document Document to undo edits from.
1158
1151
* @param edit Array of edits. Sorted from most recent to oldest.
1159
1152
*
1160
1153
* @return Thenable signaling that the change has completed.
1161
1154
*/
1162
- undoEdits ( edits : readonly EditType [ ] ) : Thenable < void > ;
1155
+ undoEdits ( document : CustomDocument , edits : readonly EditType [ ] ) : Thenable < void > ;
1156
+
1157
+ /**
1158
+ * Revert the file to its last saved state.
1159
+ *
1160
+ * @param document Document to revert.
1161
+ * @param edits Added or applied edits.
1162
+ *
1163
+ * @return Thenable signaling that the change has completed.
1164
+ */
1165
+ revert ( document : CustomDocument , edits : CustomDocumentRevert < EditType > ) : Thenable < void > ;
1163
1166
1164
1167
/**
1165
1168
* Back up the resource in its current state.
@@ -1174,19 +1177,57 @@ export interface CustomEditorEditingCapability<EditType = unknown> {
1174
1177
* made in quick succession, `backup` is only triggered after the last one. `backup` is not invoked when
1175
1178
* `auto save` is enabled (since auto save already persists resource ).
1176
1179
*
1180
+ * @param document Document to revert.
1177
1181
* @param cancellation Token that signals the current backup since a new backup is coming in. It is up to your
1178
1182
* extension to decided how to respond to cancellation. If for example your extension is backing up a large file
1179
1183
* in an operation that takes time to complete, your extension may decide to finish the ongoing backup rather
1180
1184
* than cancelling it to ensure that VS Code has some valid backup.
1181
1185
*/
1182
- backup ( cancellation : CancellationToken ) : Thenable < void > ;
1186
+ backup ( document : CustomDocument , cancellation : CancellationToken ) : Thenable < void > ;
1187
+ }
1188
+
1189
+ /**
1190
+ * Event triggered by extensions to signal to VS Code that an edit has occurred on a CustomDocument``.
1191
+ */
1192
+ export interface CustomDocumentEditEvent < EditType = unknown > {
1193
+ /**
1194
+ * Document the edit is for.
1195
+ */
1196
+ readonly document : CustomDocument ;
1197
+
1198
+ /**
1199
+ * Object that describes the edit.
1200
+ *
1201
+ * Edit objects are passed back to your extension in `undoEdits`, `applyEdits`, and `revert`.
1202
+ */
1203
+ readonly edit : EditType ;
1204
+
1205
+ /**
1206
+ * Display name describing the edit.
1207
+ */
1208
+ readonly label ?: string ;
1209
+ }
1210
+
1211
+ /**
1212
+ * Data about a revert for a `CustomDocument`.
1213
+ */
1214
+ export interface CustomDocumentRevert < EditType = unknown > {
1215
+ /**
1216
+ * List of edits that were undone to get the document back to its on disk state.
1217
+ */
1218
+ readonly undoneEdits : readonly EditType [ ] ;
1219
+
1220
+ /**
1221
+ * List of edits that were reapplied to get the document back to its on disk state.
1222
+ */
1223
+ readonly appliedEdits : readonly EditType [ ] ;
1183
1224
}
1184
1225
1185
1226
/**
1186
- * Represents a custom document for a custom webview editor .
1227
+ * Represents a custom document used by a `CustomEditorProvider` .
1187
1228
*
1188
1229
* Custom documents are only used within a given `CustomEditorProvider`. The lifecycle of a
1189
- * `CustomDocument` is managed by VS Code. When more more references remain to a given `CustomDocument`
1230
+ * `CustomDocument` is managed by VS Code. When no more references remain to a given `CustomDocument`,
1190
1231
* then it is disposed of.
1191
1232
*
1192
1233
* @param UserDataType Type of custom object that extensions can store on the document.
@@ -1223,23 +1264,38 @@ export interface CustomDocument<UserDataType = unknown> {
1223
1264
* based documents, use [`WebviewTextEditorProvider`](#WebviewTextEditorProvider) instead.
1224
1265
*/
1225
1266
export interface CustomEditorProvider {
1267
+ /**
1268
+ * Defines the editing capability of a custom webview document.
1269
+ *
1270
+ * When not provided, the document is considered readonly.
1271
+ */
1272
+ readonly editingDelegate ?: CustomEditorEditingDelegate ;
1226
1273
/**
1227
1274
* Resolve the model for a given resource.
1228
1275
*
1276
+ * `resolveCustomDocument` is called when the first editor for a given resource is opened, and the resolve document
1277
+ * is passed to `resolveCustomEditor`. The resolved `CustomDocument` is re-used for subsequent editor opens.
1278
+ * If all editors for a given resource are closed, the `CustomDocument` is disposed of. Opening an editor at
1279
+ * this point will trigger another call to `resolveCustomDocument`.
1280
+ *
1229
1281
* @param document Document to resolve.
1230
1282
*
1231
1283
* @return The capabilities of the resolved document.
1232
1284
*/
1233
- resolveCustomDocument ( document : CustomDocument ) : Thenable < CustomEditorCapabilities > ;
1285
+ resolveCustomDocument ( document : CustomDocument ) : Thenable < void > ;
1234
1286
1235
1287
/**
1236
1288
* Resolve a webview editor for a given resource.
1237
1289
*
1290
+ * This is called when a user first opens a resource for a `CustomTextEditorProvider`, or if they reopen an
1291
+ * existing editor using this `CustomTextEditorProvider`.
1292
+ *
1238
1293
* To resolve a webview editor, the provider must fill in its initial html content and hook up all
1239
- * the event listeners it is interested it. The provider should also take ownership of the passed in `WebviewPanel`.
1294
+ * the event listeners it is interested it. The provider can also hold onto the `WebviewPanel` to use later,
1295
+ * for example in a command. See [`WebviewPanel`](#WebviewPanel) for additional details
1240
1296
*
1241
1297
* @param document Document for the resource being resolved.
1242
- * @param webviewPanel Webview to resolve. The provider should take ownership of this webview.
1298
+ * @param webviewPanel Webview to resolve.
1243
1299
*
1244
1300
* @return Thenable indicating that the webview editor has been resolved.
1245
1301
*/
@@ -1258,13 +1314,17 @@ export interface CustomEditorProvider {
1258
1314
*/
1259
1315
export interface CustomTextEditorProvider {
1260
1316
/**
1261
- * Resolve a webview editor for a given resource.
1317
+ * Resolve a webview editor for a given text resource.
1318
+ *
1319
+ * This is called when a user first opens a resource for a `CustomTextEditorProvider`, or if they reopen an
1320
+ * existing editor using this `CustomTextEditorProvider`.
1262
1321
*
1263
1322
* To resolve a webview editor, the provider must fill in its initial html content and hook up all
1264
- * the event listeners it is interested it. The provider should also take ownership of the passed in `WebviewPanel`.
1323
+ * the event listeners it is interested it. The provider can also hold onto the `WebviewPanel` to use later,
1324
+ * for example in a command. See [`WebviewPanel`](#WebviewPanel) for additional details.
1265
1325
*
1266
- * @param document Resource being resolved .
1267
- * @param webviewPanel Webview to resolve. The provider should take ownership of this webview.
1326
+ * @param document Document for the resource to resolve .
1327
+ * @param webviewPanel Webview to resolve.
1268
1328
*
1269
1329
* @return Thenable indicating that the webview editor has been resolved.
1270
1330
*/
0 commit comments