Split up main thread webview services

This commit is contained in:
Matt Bierner
2020-08-26 14:40:17 -07:00
parent a6103e8faa
commit 4d88b39b7d
12 changed files with 209 additions and 188 deletions

View File

@@ -19,7 +19,8 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILabelService } from 'vs/platform/label/common/label';
import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo';
import type { MainThreadWebviews } from 'vs/workbench/api/browser/mainThreadWebview';
import type { MainThreadWebviewPanelsAndViews } from 'vs/workbench/api/browser/mainThreadWebviewPanelsAndViews';
import { MainThreadWebviews, reviveWebviewExtension } from 'vs/workbench/api/browser/mainThreadWebviews';
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { editorGroupToViewColumn } from 'vs/workbench/api/common/shared/editor';
import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
@@ -35,19 +36,20 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
import { IWorkingCopy, IWorkingCopyBackup, IWorkingCopyService, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService';
export const enum CustomEditorModelType {
const enum CustomEditorModelType {
Custom,
Text,
}
export class MainThreadCustomEditors extends Disposable {
export class MainThreadCustomEditors extends Disposable implements extHostProtocol.MainThreadCustomEditorsShape {
private readonly _proxyCustomEditors: extHostProtocol.ExtHostCustomEditorsShape;
private readonly _editorProviders = new Map<string, IDisposable>();
constructor(
private readonly mainThreadWebviews: MainThreadWebviews,
private readonly mainThreadWebview: MainThreadWebviews,
private readonly mainThreadWebviewPanelsAndViews: MainThreadWebviewPanelsAndViews,
context: extHostProtocol.IExtHostContext,
@IWorkingCopyService workingCopyService: IWorkingCopyService,
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
@@ -85,7 +87,15 @@ export class MainThreadCustomEditors extends Disposable {
this._editorProviders.clear();
}
public registerEditorProvider(
public $registerTextEditorProvider(extensionData: extHostProtocol.WebviewExtensionDescription, viewType: string, options: modes.IWebviewPanelOptions, capabilities: extHostProtocol.CustomTextEditorCapabilities): void {
this.registerEditorProvider(CustomEditorModelType.Text, reviveWebviewExtension(extensionData), viewType, options, capabilities, true);
}
public $registerCustomEditorProvider(extensionData: extHostProtocol.WebviewExtensionDescription, viewType: string, options: modes.IWebviewPanelOptions, supportsMultipleEditorsPerDocument: boolean): void {
this.registerEditorProvider(CustomEditorModelType.Custom, reviveWebviewExtension(extensionData), viewType, options, {}, supportsMultipleEditorsPerDocument);
}
private registerEditorProvider(
modelType: CustomEditorModelType,
extension: WebviewExtensionDescription,
viewType: string,
@@ -111,7 +121,7 @@ export class MainThreadCustomEditors extends Disposable {
const handle = webviewInput.id;
const resource = webviewInput.resource;
this.mainThreadWebviews.addWebviewInput(handle, webviewInput);
this.mainThreadWebviewPanelsAndViews.addWebviewInput(handle, webviewInput);
webviewInput.webview.options = options;
webviewInput.webview.extension = extension;
@@ -120,7 +130,7 @@ export class MainThreadCustomEditors extends Disposable {
modelRef = await this.getOrCreateCustomEditorModel(modelType, resource, viewType, { backupId: webviewInput.backupId }, cancellation);
} catch (error) {
onUnexpectedError(error);
webviewInput.webview.html = this.mainThreadWebviews.getWebviewResolvedFailedContent(viewType);
webviewInput.webview.html = this.mainThreadWebview.getWebviewResolvedFailedContent(viewType);
return;
}
@@ -157,7 +167,7 @@ export class MainThreadCustomEditors extends Disposable {
await this._proxyCustomEditors.$resolveWebviewEditor(resource, handle, viewType, webviewInput.getTitle(), editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0), webviewInput.webview.options, cancellation);
} catch (error) {
onUnexpectedError(error);
webviewInput.webview.html = this.mainThreadWebviews.getWebviewResolvedFailedContent(viewType);
webviewInput.webview.html = this.mainThreadWebview.getWebviewResolvedFailedContent(viewType);
modelRef.dispose();
return;
}
@@ -200,7 +210,7 @@ export class MainThreadCustomEditors extends Disposable {
case CustomEditorModelType.Custom:
{
const model = MainThreadCustomEditorModel.create(this._instantiationService, this._proxyCustomEditors, viewType, resource, options, () => {
return Array.from(this.mainThreadWebviews.webviewInputs)
return Array.from(this.mainThreadWebviewPanelsAndViews.webviewInputs)
.filter(editor => editor instanceof CustomEditorInput && isEqual(editor.resource, resource)) as CustomEditorInput[];
}, cancellation, this._backupService);
return this._customEditorService.models.add(resource, viewType, model);