From 9170aa877cecbb84c5fd7e2d0d988fdca70c21b1 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 2 Jun 2023 09:44:18 +0200 Subject: [PATCH] Extension host veto is registered multiple times on restart (#183778) (#184126) --- .../api/browser/mainThreadCustomEditors.ts | 36 +++++++++---------- .../notebook/common/notebookEditorModel.ts | 2 +- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts index 132bd6a39ef..d32e4ef318e 100644 --- a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts @@ -106,26 +106,6 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc // Working copy operations this._register(workingCopyFileService.onWillRunWorkingCopyFileOperation(async e => this.onWillRunWorkingCopyFileOperation(e))); - - this._register(extensionService.onWillStop(e => { - const dirtyCustomEditors = workingCopyService.workingCopies.filter(workingCopy => { - return workingCopy instanceof MainThreadCustomEditorModel && workingCopy.isDirty(); - }); - if (!dirtyCustomEditors.length) { - return; - } - - e.veto((async () => { - for (const dirtyCustomEditor of dirtyCustomEditors) { - const didSave = await dirtyCustomEditor.save(); - if (!didSave) { - // Veto - return true; - } - } - return false; // Don't veto - })(), localize('vetoExtHostRestart', "One or more custom editors could not be saved.")); - })); } public $registerTextEditorProvider(extensionData: extHostProtocol.WebviewExtensionDescription, viewType: string, options: extHostProtocol.IWebviewPanelOptions, capabilities: extHostProtocol.CustomTextEditorCapabilities, serializeBuffersForPostMessage: boolean): void { @@ -399,6 +379,7 @@ class MainThreadCustomEditorModel extends ResourceWorkingCopy implements ICustom @IWorkbenchEnvironmentService private readonly _environmentService: IWorkbenchEnvironmentService, @IWorkingCopyService workingCopyService: IWorkingCopyService, @IPathService private readonly _pathService: IPathService, + @IExtensionService extensionService: IExtensionService, ) { super(MainThreadCustomEditorModel.toWorkingCopyResource(_viewType, _editorResource), fileService); @@ -406,6 +387,21 @@ class MainThreadCustomEditorModel extends ResourceWorkingCopy implements ICustom if (_editable) { this._register(workingCopyService.registerWorkingCopy(this)); + + this._register(extensionService.onWillStop(e => { + if (!this.isDirty()) { + return; + } + + e.veto((async () => { + const didSave = await this.save(); + if (!didSave) { + // Veto + return true; + } + return false; // Don't veto + })(), localize('vetoExtHostRestart', "Custom editor '{0}' could not be saved.", this.name)); + })); } // Normally means we're re-opening an untitled file diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts index 6b6e07b57fa..fa0c59b6f47 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts @@ -70,7 +70,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE return true; } return false; // Don't veto - })(), localize('vetoExtHostRestart', "Notebook could not be saved.")); + })(), localize('vetoExtHostRestart', "Notebook '{0}' could not be saved.", this._workingCopy?.name)); })); }