提交 72cbf699 编写于 作者: M Matt Bierner

Split out main thread webview panels into own class/file

上级 7e4ccf16
......@@ -54,7 +54,7 @@ import './mainThreadTreeViews';
import './mainThreadDownloadService';
import './mainThreadUrls';
import './mainThreadWindow';
import './mainThreadWebviewPanelsAndViews';
import './mainThreadWebviewManager';
import './mainThreadWorkspace';
import './mainThreadComments';
import './mainThreadNotebook';
......
......@@ -19,7 +19,7 @@ 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 { MainThreadWebviewPanelsAndViews } from 'vs/workbench/api/browser/mainThreadWebviewPanelsAndViews';
import { MainThreadWebviewPanels } from 'vs/workbench/api/browser/mainThreadWebviewPanels';
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';
......@@ -49,7 +49,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
constructor(
private readonly mainThreadWebview: MainThreadWebviews,
private readonly mainThreadWebviewPanelsAndViews: MainThreadWebviewPanelsAndViews,
private readonly mainThreadWebviewPanels: MainThreadWebviewPanels,
context: extHostProtocol.IExtHostContext,
@IWorkingCopyService workingCopyService: IWorkingCopyService,
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
......@@ -121,7 +121,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
const handle = webviewInput.id;
const resource = webviewInput.resource;
this.mainThreadWebviewPanelsAndViews.addWebviewInput(handle, webviewInput);
this.mainThreadWebviewPanels.addWebviewInput(handle, webviewInput);
webviewInput.webview.options = options;
webviewInput.webview.extension = extension;
......@@ -210,7 +210,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
case CustomEditorModelType.Custom:
{
const model = MainThreadCustomEditorModel.create(this._instantiationService, this._proxyCustomEditors, viewType, resource, options, () => {
return Array.from(this.mainThreadWebviewPanelsAndViews.webviewInputs)
return Array.from(this.mainThreadWebviewPanels.webviewInputs)
.filter(editor => editor instanceof CustomEditorInput && isEqual(editor.resource, resource)) as CustomEditorInput[];
}, cancellation, this._backupService);
return this._customEditorService.models.add(resource, viewType, model);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { MainThreadCustomEditors } from 'vs/workbench/api/browser/mainThreadCustomEditors';
import { MainThreadWebviewPanels } from 'vs/workbench/api/browser/mainThreadWebviewPanels';
import { MainThreadWebviews } from 'vs/workbench/api/browser/mainThreadWebviews';
import { MainThreadWebviewsViews } from 'vs/workbench/api/browser/mainThreadWebviewViews';
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { extHostCustomer } from '../common/extHostCustomers';
@extHostCustomer
export class MainThreadWebviewManager extends Disposable {
constructor(
context: extHostProtocol.IExtHostContext,
@IInstantiationService instantiationService: IInstantiationService,
) {
super();
const webviews = this._register(instantiationService.createInstance(MainThreadWebviews, context));
context.set(extHostProtocol.MainContext.MainThreadWebviews, webviews);
const webviewPanels = this._register(instantiationService.createInstance(MainThreadWebviewPanels, webviews, context));
context.set(extHostProtocol.MainContext.MainThreadWebviewPanels, webviewPanels);
const customEditors = this._register(instantiationService.createInstance(MainThreadCustomEditors, webviews, webviewPanels, context));
context.set(extHostProtocol.MainContext.MainThreadCustomEditors, customEditors);
const webviewViews = this._register(instantiationService.createInstance(MainThreadWebviewsViews, webviews, context));
context.set(extHostProtocol.MainContext.MainThreadWebviewViews, webviewViews);
}
}
......@@ -6,11 +6,8 @@
import { onUnexpectedError } from 'vs/base/common/errors';
import { Disposable, DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { MainThreadCustomEditors } from 'vs/workbench/api/browser/mainThreadCustomEditors';
import { MainThreadWebviews, reviveWebviewExtension, reviveWebviewOptions } from 'vs/workbench/api/browser/mainThreadWebviews';
import { MainThreadWebviewsViews } from 'vs/workbench/api/browser/mainThreadWebviewViews';
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/common/shared/editor';
import { IEditorInput } from 'vs/workbench/common/editor';
......@@ -22,7 +19,6 @@ import { ICreateWebViewShowOptions, IWebviewWorkbenchService, WebviewInputOption
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { extHostNamedCustomer } from '../common/extHostCustomers';
/**
* Bi-directional map between webview handles and inputs.
......@@ -77,8 +73,7 @@ class WebviewViewTypeTransformer {
}
}
@extHostNamedCustomer(extHostProtocol.MainContext.MainThreadWebviewService)
export class MainThreadWebviewPanelsAndViews extends Disposable implements extHostProtocol.MainThreadWebviewPanelsAndViewsShape {
export class MainThreadWebviewPanels extends Disposable implements extHostProtocol.MainThreadWebviewPanelsShape {
private readonly webviewPanelViewType = new WebviewViewTypeTransformer('mainThreadWebview-');
......@@ -89,32 +84,21 @@ export class MainThreadWebviewPanelsAndViews extends Disposable implements extHo
private readonly _editorProviders = new Map<string, IDisposable>();
private readonly _webviewFromDiffEditorHandles = new Set<string>();
private readonly _mainThreadWebviews: MainThreadWebviews;
private readonly _revivers = new Map<string, IDisposable>();
constructor(
private readonly _mainThreadWebviews: MainThreadWebviews,
context: extHostProtocol.IExtHostContext,
@IExtensionService extensionService: IExtensionService,
@IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService,
@IEditorService private readonly _editorService: IEditorService,
@ITelemetryService private readonly _telemetryService: ITelemetryService,
@IWebviewWorkbenchService private readonly _webviewWorkbenchService: IWebviewWorkbenchService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
) {
super();
this._proxy = context.getProxy(extHostProtocol.ExtHostContext.ExtHostWebviewPanels);
this._mainThreadWebviews = this._instantiationService.createInstance(MainThreadWebviews, context);
context.set(extHostProtocol.MainContext.MainThreadWebviews, this._mainThreadWebviews);
const webviewViews = this._instantiationService.createInstance(MainThreadWebviewsViews, this._mainThreadWebviews, context);
context.set(extHostProtocol.MainContext.MainThreadWebviewViews, webviewViews);
const customEditors = this._instantiationService.createInstance(MainThreadCustomEditors, this._mainThreadWebviews, this, context);
context.set(extHostProtocol.MainContext.MainThreadCustomEditors, customEditors);
this._register(_editorService.onDidActiveEditorChange(() => {
const activeInput = this._editorService.activeEditor;
if (activeInput instanceof DiffEditorInput && activeInput.primary instanceof WebviewInput && activeInput.secondary instanceof WebviewInput) {
......
......@@ -614,7 +614,7 @@ export interface MainThreadWebviewsShape extends IDisposable {
$postMessage(handle: WebviewHandle, value: any): Promise<boolean>
}
export interface MainThreadWebviewPanelsAndViewsShape extends IDisposable {
export interface MainThreadWebviewPanelsShape extends IDisposable {
$createWebviewPanel(extension: WebviewExtensionDescription, handle: WebviewHandle, viewType: string, title: string, showOptions: WebviewPanelShowOptions, options: modes.IWebviewPanelOptions & modes.IWebviewOptions): void;
$disposeWebview(handle: WebviewHandle): void;
$reveal(handle: WebviewHandle, showOptions: WebviewPanelShowOptions): void;
......@@ -1720,8 +1720,8 @@ export const MainContext = {
MainThreadStorage: createMainId<MainThreadStorageShape>('MainThreadStorage'),
MainThreadTelemetry: createMainId<MainThreadTelemetryShape>('MainThreadTelemetry'),
MainThreadTerminalService: createMainId<MainThreadTerminalServiceShape>('MainThreadTerminalService'),
MainThreadWebviewService: createMainId<MainThreadWebviewPanelsAndViewsShape>('MainThreadWebviewService'),
MainThreadWebviews: createMainId<MainThreadWebviewsShape>('MainThreadWebviews'),
MainThreadWebviewPanels: createMainId<MainThreadWebviewPanelsShape>('MainThreadWebviewPanels'),
MainThreadWebviewViews: createMainId<MainThreadWebviewViewsShape>('MainThreadWebviewViews'),
MainThreadCustomEditors: createMainId<MainThreadCustomEditorsShape>('MainThreadCustomEditors'),
MainThreadUrls: createMainId<MainThreadUrlsShape>('MainThreadUrls'),
......
......@@ -122,7 +122,7 @@ type IconPath = URI | { light: URI, dark: URI };
class ExtHostWebviewPanel extends Disposable implements vscode.WebviewPanel {
readonly #handle: extHostProtocol.WebviewHandle;
readonly #proxy: extHostProtocol.MainThreadWebviewPanelsAndViewsShape;
readonly #proxy: extHostProtocol.MainThreadWebviewPanelsShape;
readonly #viewType: string;
readonly #webview: ExtHostWebview;
......@@ -143,7 +143,7 @@ class ExtHostWebviewPanel extends Disposable implements vscode.WebviewPanel {
constructor(
handle: extHostProtocol.WebviewHandle,
proxy: extHostProtocol.MainThreadWebviewPanelsAndViewsShape,
proxy: extHostProtocol.MainThreadWebviewPanelsShape,
viewType: string,
title: string,
viewColumn: vscode.ViewColumn | undefined,
......@@ -269,7 +269,7 @@ export class ExtHostWebviews implements extHostProtocol.ExtHostWebviewsShape, ex
return generateUuid();
}
private readonly _proxy: extHostProtocol.MainThreadWebviewPanelsAndViewsShape;
private readonly _proxy: extHostProtocol.MainThreadWebviewPanelsShape;
private readonly _webviewProxy: extHostProtocol.MainThreadWebviewsShape;
private readonly _webviews = new Map<extHostProtocol.WebviewHandle, ExtHostWebview>();
......@@ -287,7 +287,7 @@ export class ExtHostWebviews implements extHostProtocol.ExtHostWebviewsShape, ex
private readonly _logService: ILogService,
private readonly _deprecationService: IExtHostApiDeprecationService,
) {
this._proxy = mainContext.getProxy(extHostProtocol.MainContext.MainThreadWebviewService);
this._proxy = mainContext.getProxy(extHostProtocol.MainContext.MainThreadWebviewPanels);
this._webviewProxy = mainContext.getProxy(extHostProtocol.MainContext.MainThreadWebviews);
}
......
......@@ -8,7 +8,7 @@ import { URI } from 'vs/base/common/uri';
import { mock } from 'vs/base/test/common/mock';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { NullLogService } from 'vs/platform/log/common/log';
import { MainThreadWebviewPanelsAndViews } from 'vs/workbench/api/browser/mainThreadWebviewPanelsAndViews';
import { MainThreadWebviewManager } from 'vs/workbench/api/browser/mainThreadWebviewManager';
import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
import { NullApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
......@@ -150,7 +150,7 @@ suite('ExtHostWebview', () => {
function createNoopMainThreadWebviews() {
return new class extends mock<MainThreadWebviewPanelsAndViews>() {
return new class extends mock<MainThreadWebviewManager>() {
$createWebviewPanel() { /* noop */ }
$registerSerializer() { /* noop */ }
$unregisterSerializer() { /* noop */ }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册