Skip to content

Commit cf64598

Browse files
authored
Refactor to accommodate upstream VSCode API changes (#10569)
* Accomodate upstream VSC changes * Use weekmap * Ignore
1 parent c9f315f commit cf64598

File tree

6 files changed

+184
-77
lines changed

6 files changed

+184
-77
lines changed

src/client/common/application/types.ts

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,67 +1099,70 @@ export interface IActiveResourceService {
10991099
//#region Custom editors: https://github.com/microsoft/vscode/issues/77131
11001100

11011101
// 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-
11151102
/**
11161103
* Defines the editing capability of a custom webview editor. This allows the webview editor to hook into standard
11171104
* editor events such as `undo` or `save`.
11181105
*
11191106
* @param EditType Type of edits.
11201107
*/
1121-
export interface CustomEditorEditingCapability<EditType = unknown> {
1108+
export interface CustomEditorEditingDelegate<EditType = unknown> {
11221109
/**
11231110
* Event triggered by extensions to signal to VS Code that an edit has occurred.
11241111
*/
1125-
readonly onDidEdit: Event<EditType>;
1112+
readonly onDidEdit: Event<CustomDocumentEditEvent<EditType>>;
11261113
/**
11271114
* Save the resource.
11281115
*
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+
*
11291119
* @return Thenable signaling that the save has completed.
11301120
*/
1131-
save(): Thenable<void>;
1121+
save(document: CustomDocument, cancellation: CancellationToken): Thenable<void>;
11321122

11331123
/**
11341124
* Save the existing resource at a new path.
11351125
*
1126+
* @param document Document to save.
11361127
* @param targetResource Location to save to.
11371128
*
11381129
* @return Thenable signaling that the save has completed.
11391130
*/
1140-
saveAs(targetResource: Uri): Thenable<void>;
1131+
saveAs(document: CustomDocument, targetResource: Uri): Thenable<void>;
11411132

11421133
/**
11431134
* Apply a set of edits.
11441135
*
11451136
* Note that is not invoked when `onDidEdit` is called because `onDidEdit` implies also updating the view to reflect the edit.
11461137
*
1138+
* @param document Document to apply edits to.
11471139
* @param edit Array of edits. Sorted from oldest to most recent.
11481140
*
11491141
* @return Thenable signaling that the change has completed.
11501142
*/
1151-
applyEdits(edits: readonly EditType[]): Thenable<void>;
1143+
applyEdits(document: CustomDocument, edits: readonly EditType[]): Thenable<void>;
11521144

11531145
/**
11541146
* Undo a set of edits.
11551147
*
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.
11571149
*
1150+
* @param document Document to undo edits from.
11581151
* @param edit Array of edits. Sorted from most recent to oldest.
11591152
*
11601153
* @return Thenable signaling that the change has completed.
11611154
*/
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>;
11631166

11641167
/**
11651168
* Back up the resource in its current state.
@@ -1174,19 +1177,57 @@ export interface CustomEditorEditingCapability<EditType = unknown> {
11741177
* made in quick succession, `backup` is only triggered after the last one. `backup` is not invoked when
11751178
* `auto save` is enabled (since auto save already persists resource ).
11761179
*
1180+
* @param document Document to revert.
11771181
* @param cancellation Token that signals the current backup since a new backup is coming in. It is up to your
11781182
* extension to decided how to respond to cancellation. If for example your extension is backing up a large file
11791183
* in an operation that takes time to complete, your extension may decide to finish the ongoing backup rather
11801184
* than cancelling it to ensure that VS Code has some valid backup.
11811185
*/
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[];
11831224
}
11841225

11851226
/**
1186-
* Represents a custom document for a custom webview editor.
1227+
* Represents a custom document used by a `CustomEditorProvider`.
11871228
*
11881229
* 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`,
11901231
* then it is disposed of.
11911232
*
11921233
* @param UserDataType Type of custom object that extensions can store on the document.
@@ -1223,23 +1264,38 @@ export interface CustomDocument<UserDataType = unknown> {
12231264
* based documents, use [`WebviewTextEditorProvider`](#WebviewTextEditorProvider) instead.
12241265
*/
12251266
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;
12261273
/**
12271274
* Resolve the model for a given resource.
12281275
*
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+
*
12291281
* @param document Document to resolve.
12301282
*
12311283
* @return The capabilities of the resolved document.
12321284
*/
1233-
resolveCustomDocument(document: CustomDocument): Thenable<CustomEditorCapabilities>;
1285+
resolveCustomDocument(document: CustomDocument): Thenable<void>;
12341286

12351287
/**
12361288
* Resolve a webview editor for a given resource.
12371289
*
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+
*
12381293
* 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
12401296
*
12411297
* @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.
12431299
*
12441300
* @return Thenable indicating that the webview editor has been resolved.
12451301
*/
@@ -1258,13 +1314,17 @@ export interface CustomEditorProvider {
12581314
*/
12591315
export interface CustomTextEditorProvider {
12601316
/**
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`.
12621321
*
12631322
* 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.
12651325
*
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.
12681328
*
12691329
* @return Thenable indicating that the webview editor has been resolved.
12701330
*/

0 commit comments

Comments
 (0)