diff --git a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts index 1614c9466a597..132bd6a39efe4 100644 --- a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts @@ -70,9 +70,9 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc @IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService, @ICustomEditorService private readonly _customEditorService: ICustomEditorService, @IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService, - @IWebviewWorkbenchService private readonly _webviewWorkbenchService: IWebviewWorkbenchService, - @IInstantiationService private readonly _instantiationService: IInstantiationService, @IEditorService private readonly _editorService: IEditorService, + @IInstantiationService private readonly _instantiationService: IInstantiationService, + @IWebviewWorkbenchService private readonly _webviewWorkbenchService: IWebviewWorkbenchService, ) { super(); @@ -106,6 +106,26 @@ 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 {