Path: blob/main/src/vs/workbench/services/extensions/common/extHostCustomers.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IDisposable } from '../../../../base/common/lifecycle.js';6import { BrandedService, IConstructorSignature } from '../../../../platform/instantiation/common/instantiation.js';7import { ExtensionHostKind } from './extensionHostKind.js';8import { IExtensionHostProxy } from './extensionHostProxy.js';9import { IInternalExtensionService } from './extensions.js';10import { IRPCProtocol, ProxyIdentifier } from './proxyIdentifier.js';1112export interface IExtHostContext extends IRPCProtocol {13readonly remoteAuthority: string | null;14readonly extensionHostKind: ExtensionHostKind;15}1617export interface IInternalExtHostContext extends IExtHostContext {18readonly internalExtensionService: IInternalExtensionService;19_setExtensionHostProxy(extensionHostProxy: IExtensionHostProxy): void;20_setAllMainProxyIdentifiers(mainProxyIdentifiers: ProxyIdentifier<any>[]): void;21}2223export type IExtHostNamedCustomer<T extends IDisposable> = [ProxyIdentifier<T>, IExtHostCustomerCtor<T>];2425export type IExtHostCustomerCtor<T extends IDisposable> = IConstructorSignature<T, [IExtHostContext]>;2627export function extHostNamedCustomer<T extends IDisposable>(id: ProxyIdentifier<T>) {28return function <Services extends BrandedService[]>(ctor: { new(context: IExtHostContext, ...services: Services): T }): void {29ExtHostCustomersRegistryImpl.INSTANCE.registerNamedCustomer(id, ctor as IExtHostCustomerCtor<T>);30};31}3233export function extHostCustomer<T extends IDisposable, Services extends BrandedService[]>(ctor: { new(context: IExtHostContext, ...services: Services): T }): void {34ExtHostCustomersRegistryImpl.INSTANCE.registerCustomer(ctor as IExtHostCustomerCtor<T>);35}3637export namespace ExtHostCustomersRegistry {3839export function getNamedCustomers(): IExtHostNamedCustomer<IDisposable>[] {40return ExtHostCustomersRegistryImpl.INSTANCE.getNamedCustomers();41}4243export function getCustomers(): IExtHostCustomerCtor<IDisposable>[] {44return ExtHostCustomersRegistryImpl.INSTANCE.getCustomers();45}46}4748class ExtHostCustomersRegistryImpl {4950public static readonly INSTANCE = new ExtHostCustomersRegistryImpl();5152private _namedCustomers: IExtHostNamedCustomer<any>[];53private _customers: IExtHostCustomerCtor<any>[];5455constructor() {56this._namedCustomers = [];57this._customers = [];58}5960public registerNamedCustomer<T extends IDisposable>(id: ProxyIdentifier<T>, ctor: IExtHostCustomerCtor<T>): void {61const entry: IExtHostNamedCustomer<T> = [id, ctor];62this._namedCustomers.push(entry);63}64public getNamedCustomers(): IExtHostNamedCustomer<any>[] {65return this._namedCustomers;66}6768public registerCustomer<T extends IDisposable>(ctor: IExtHostCustomerCtor<T>): void {69this._customers.push(ctor);70}71public getCustomers(): IExtHostCustomerCtor<any>[] {72return this._customers;73}74}757677