Skip to content

Commit

Permalink
Adopt ext host restart for custom editors (#182558)
Browse files Browse the repository at this point in the history
* Adopt ext host restart for custom editors

For #180514

* Show notification when restart is vetoed
  • Loading branch information
mjbvz authored May 18, 2023
1 parent 2946b1e commit 1c95491
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/vs/workbench/api/browser/mainThreadCustomEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1c95491

Please sign in to comment.