diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 78cbeeb3182..1e096e0a6c2 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -40,7 +40,7 @@ import { ExtHostProgress } from 'vs/workbench/api/common/extHostProgress'; import { ExtHostQuickOpen } from 'vs/workbench/api/common/extHostQuickOpen'; import { ExtHostSCM } from 'vs/workbench/api/common/extHostSCM'; import { ExtHostStatusBar } from 'vs/workbench/api/common/extHostStatusBar'; -import { ExtHostStorage } from 'vs/workbench/api/common/extHostStorage'; +import { IExtHostStorage } from 'vs/workbench/api/common/extHostStorage'; import { IExtHostTerminalService } from 'vs/workbench/api/common/extHostTerminalService'; import { ExtHostEditors } from 'vs/workbench/api/common/extHostTextEditors'; import { ExtHostTreeViews } from 'vs/workbench/api/common/extHostTreeViews'; @@ -85,10 +85,7 @@ function proposedApiFunction(extension: IExtensionDescription, fn: T): T { /** * This method instantiates and returns the extension API surface */ -export function createApiFactory( - accessor: ServicesAccessor, - extHostStorage: ExtHostStorage, -): IExtensionApiFactory { +export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): IExtensionApiFactory { // services const initData = accessor.get(IExtHostInitDataService); @@ -97,6 +94,7 @@ export function createApiFactory( const extHostConfiguration = accessor.get(IExtHostConfiguration); const uriTransformer = accessor.get(IURITransformerService); const rpcProtocol = accessor.get(IExtHostRpcService); + const extHostStorage = accessor.get(IExtHostStorage); const extHostLogService = accessor.get(ILogService); // register addressable instances diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts index 5b296ee5390..57baf95adce 100644 --- a/src/vs/workbench/api/common/extHostExtensionService.ts +++ b/src/vs/workbench/api/common/extHostExtensionService.ts @@ -8,9 +8,13 @@ import { ExtensionActivationReason, IExtensionAPI } from 'vs/workbench/api/commo import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry'; import * as vscode from 'vscode'; import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { TernarySearchTree } from 'vs/base/common/map'; +export interface IInitializeParticipant { + (accessor: ServicesAccessor): Promise | void; +} + export const IExtHostExtensionService = createDecorator('IExtHostExtensionService'); export interface IExtHostExtensionService extends ExtHostExtensionServiceShape { diff --git a/src/vs/workbench/api/common/extHostStorage.ts b/src/vs/workbench/api/common/extHostStorage.ts index 72c6e02f6d4..f8669c45311 100644 --- a/src/vs/workbench/api/common/extHostStorage.ts +++ b/src/vs/workbench/api/common/extHostStorage.ts @@ -6,6 +6,7 @@ import { MainContext, MainThreadStorageShape, ExtHostStorageShape } from './extHost.protocol'; import { Emitter } from 'vs/base/common/event'; import { IExtHostRpcService } from 'vs/workbench/api/common/rpcService'; +import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; export interface IStorageChangeEvent { shared: boolean; @@ -15,6 +16,8 @@ export interface IStorageChangeEvent { export class ExtHostStorage implements ExtHostStorageShape { + readonly _serviceBrand: any; + private _proxy: MainThreadStorageShape; private _onDidChangeStorage = new Emitter(); @@ -36,3 +39,6 @@ export class ExtHostStorage implements ExtHostStorageShape { this._onDidChangeStorage.fire({ shared, key, value }); } } + +export interface IExtHostStorage extends ExtHostStorage { } +export const IExtHostStorage = createDecorator('IExtHostStorage'); diff --git a/src/vs/workbench/api/node/extHost.services.ts b/src/vs/workbench/api/node/extHost.services.ts index f6896f19e04..153413e086e 100644 --- a/src/vs/workbench/api/node/extHost.services.ts +++ b/src/vs/workbench/api/node/extHost.services.ts @@ -23,6 +23,7 @@ import { ExtensionStoragePaths } from 'vs/workbench/api/node/extHostStoragePaths import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths'; import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService'; import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService'; +import { IExtHostStorage, ExtHostStorage } from 'vs/workbench/api/common/extHostStorage'; // register singleton services registerSingleton(IExtHostOutputService, ExtHostOutputService2); @@ -37,4 +38,4 @@ registerSingleton(IExtHostDebugService, ExtHostDebugService); registerSingleton(IExtHostSearch, ExtHostSearch); registerSingleton(IExtensionStoragePaths, ExtensionStoragePaths); registerSingleton(IExtHostExtensionService, ExtHostExtensionService); - +registerSingleton(IExtHostStorage, ExtHostStorage); diff --git a/src/vs/workbench/api/node/extHostExtensionService.ts b/src/vs/workbench/api/node/extHostExtensionService.ts index 0de3f0f5974..eb2fb4ae37b 100644 --- a/src/vs/workbench/api/node/extHostExtensionService.ts +++ b/src/vs/workbench/api/node/extHostExtensionService.ts @@ -11,13 +11,13 @@ import { dispose, toDisposable, DisposableStore } from 'vs/base/common/lifecycle import { TernarySearchTree } from 'vs/base/common/map'; import { URI } from 'vs/base/common/uri'; import { ILogService } from 'vs/platform/log/common/log'; -import { createApiFactory } from 'vs/workbench/api/common/extHost.api.impl'; +import { createApiFactoryAndRegisterActors } from 'vs/workbench/api/common/extHost.api.impl'; import { NodeModuleRequireInterceptor, VSCodeNodeModuleFactory, KeytarNodeModuleFactory, OpenNodeModuleFactory } from 'vs/workbench/api/node/extHostRequireInterceptor'; import { ExtHostExtensionServiceShape, IInitData, MainContext, MainThreadExtensionServiceShape, MainThreadTelemetryShape, MainThreadWorkspaceShape, IResolveAuthorityResult } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostConfiguration, IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration'; import { ActivatedExtension, EmptyExtension, ExtensionActivatedByAPI, ExtensionActivatedByEvent, ExtensionActivationReason, ExtensionActivationTimes, ExtensionActivationTimesBuilder, ExtensionsActivator, IExtensionAPI, IExtensionContext, IExtensionModule, HostExtension, ExtensionActivationTimesFragment } from 'vs/workbench/api/common/extHostExtensionActivator'; import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService'; -import { ExtHostStorage } from 'vs/workbench/api/common/extHostStorage'; +import { ExtHostStorage, IExtHostStorage } from 'vs/workbench/api/common/extHostStorage'; import { ExtHostWorkspace, IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; import { ExtensionActivationError } from 'vs/workbench/services/extensions/common/extensions'; import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry'; @@ -38,6 +38,7 @@ import { ExtHostDownloadService } from 'vs/workbench/api/node/extHostDownloadSer import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer'; import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths'; import { IExtHostRpcService } from 'vs/workbench/api/common/rpcService'; +import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; interface ITestRunner { /** Old test runner API, as exported from `vscode/lib/testrunner` */ @@ -115,7 +116,6 @@ export class ExtHostExtensionService implements IExtHostExtensionService, ExtHos this._extHostContext = extHostContext; this._initData = initData; - this._instaService = instaService; this._extHostWorkspace = extHostWorkspace; this._extHostConfiguration = extHostConfiguration; this._extHostLogService = extHostLogService; @@ -132,6 +132,10 @@ export class ExtHostExtensionService implements IExtHostExtensionService, ExtHos this._storage = new ExtHostStorage(this._extHostContext); this._storagePath = storagePath; + this._instaService = instaService.createChild(new ServiceCollection( + [IExtHostStorage, this._storage] + )); + const hostExtensions = new Set(); this._initData.hostExtensions.forEach((extensionId) => hostExtensions.add(ExtensionIdentifier.toKey(extensionId))); @@ -165,8 +169,8 @@ export class ExtHostExtensionService implements IExtHostExtensionService, ExtHos private async _initialize(): Promise { try { - // initialize API - const extensionApiFactory = this._instaService.invokeFunction(createApiFactory, this._storage); + // initialize API and register actors + const extensionApiFactory = this._instaService.invokeFunction(createApiFactoryAndRegisterActors); // Register Download command this._instaService.createInstance(ExtHostDownloadService);