Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ext host restart for custom editors #182558

Merged
merged 4 commits into from
May 18, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/vs/workbench/api/browser/mainThreadCustomEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { FileOperation, IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILabelService } from 'vs/platform/label/common/label';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo';
import { MainThreadWebviewPanels } from 'vs/workbench/api/browser/mainThreadWebviewPanels';
Expand Down Expand Up @@ -65,14 +66,15 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
private readonly mainThreadWebview: MainThreadWebviews,
private readonly mainThreadWebviewPanels: MainThreadWebviewPanels,
@IExtensionService extensionService: IExtensionService,
@INotificationService _notificationService: INotificationService,
@IStorageService storageService: IStorageService,
@IWorkingCopyService workingCopyService: IWorkingCopyService,
@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 +108,28 @@ 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) {
_notificationService.error(localize('vetoExtHostRestart', "'{0}' was not saved which prevented restarting the extension host. Please save or revert this file to restart the extension host.", dirtyCustomEditor.name));

// Veto
return true;
}
}
return false; // Don't veto
})(), 'mainThreadCustomEditors');
}));
}

public $registerTextEditorProvider(extensionData: extHostProtocol.WebviewExtensionDescription, viewType: string, options: extHostProtocol.IWebviewPanelOptions, capabilities: extHostProtocol.CustomTextEditorCapabilities, serializeBuffersForPostMessage: boolean): void {
Expand Down