diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 9761b0b131b..6571abe72a2 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1227,9 +1227,11 @@ declare module 'vscode' { /** * Save the resource. * + * @param cancellation Token that signals the save is no longer required (for example, if another save was triggered). + * * @return Thenable signaling that the save has completed. */ - save(): Thenable; + save(cancellation: CancellationToken): Thenable; /** * Save the existing resource at a new path. diff --git a/src/vs/workbench/api/browser/mainThreadWebview.ts b/src/vs/workbench/api/browser/mainThreadWebview.ts index 858b1ac21d4..9fd5f3d3b17 100644 --- a/src/vs/workbench/api/browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/browser/mainThreadWebview.ts @@ -625,7 +625,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod if (!this._editable) { return false; } - await this._proxy.$onSave(this.resource, this.viewType); + await createCancelablePromise(token => this._proxy.$onSave(this.resource, this.viewType, token)); this.setDirty(false); return true; } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 74e6e2a3fbc..a21449c9036 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -618,7 +618,7 @@ export interface ExtHostWebviewsShape { $undo(resource: UriComponents, viewType: string): void; $redo(resource: UriComponents, viewType: string): void; $revert(resource: UriComponents, viewType: string): void; - $onSave(resource: UriComponents, viewType: string): Promise; + $onSave(resource: UriComponents, viewType: string, cancellation: CancellationToken): Promise; $onSaveAs(resource: UriComponents, viewType: string, targetResource: UriComponents): Promise; $backup(resource: UriComponents, viewType: string, cancellation: CancellationToken): Promise; diff --git a/src/vs/workbench/api/common/extHostWebview.ts b/src/vs/workbench/api/common/extHostWebview.ts index 988358cbfe7..bdb51f8977c 100644 --- a/src/vs/workbench/api/common/extHostWebview.ts +++ b/src/vs/workbench/api/common/extHostWebview.ts @@ -350,8 +350,8 @@ class CustomDocument extends Disposable implements vscode.CustomDocument { this.updateState(); } - /** @internal*/ _save() { - return this.getEditingCapability().save(); + /** @internal*/ _save(cancellation: CancellationToken) { + return this.getEditingCapability().save(cancellation); } /** @internal*/ _saveAs(target: vscode.Uri) { @@ -714,9 +714,9 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { document._revert(); } - async $onSave(resourceComponents: UriComponents, viewType: string): Promise { + async $onSave(resourceComponents: UriComponents, viewType: string, cancellation: CancellationToken): Promise { const document = this.getCustomDocument(viewType, resourceComponents); - document._save(); + document._save(cancellation); } async $onSaveAs(resourceComponents: UriComponents, viewType: string, targetResource: UriComponents): Promise {