Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/extensions/common/extHostCustomers.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IDisposable } from '../../../../base/common/lifecycle.js';
7
import { BrandedService, IConstructorSignature } from '../../../../platform/instantiation/common/instantiation.js';
8
import { ExtensionHostKind } from './extensionHostKind.js';
9
import { IExtensionHostProxy } from './extensionHostProxy.js';
10
import { IInternalExtensionService } from './extensions.js';
11
import { IRPCProtocol, ProxyIdentifier } from './proxyIdentifier.js';
12
13
export interface IExtHostContext extends IRPCProtocol {
14
readonly remoteAuthority: string | null;
15
readonly extensionHostKind: ExtensionHostKind;
16
}
17
18
export interface IInternalExtHostContext extends IExtHostContext {
19
readonly internalExtensionService: IInternalExtensionService;
20
_setExtensionHostProxy(extensionHostProxy: IExtensionHostProxy): void;
21
_setAllMainProxyIdentifiers(mainProxyIdentifiers: ProxyIdentifier<any>[]): void;
22
}
23
24
export type IExtHostNamedCustomer<T extends IDisposable> = [ProxyIdentifier<T>, IExtHostCustomerCtor<T>];
25
26
export type IExtHostCustomerCtor<T extends IDisposable> = IConstructorSignature<T, [IExtHostContext]>;
27
28
export function extHostNamedCustomer<T extends IDisposable>(id: ProxyIdentifier<T>) {
29
return function <Services extends BrandedService[]>(ctor: { new(context: IExtHostContext, ...services: Services): T }): void {
30
ExtHostCustomersRegistryImpl.INSTANCE.registerNamedCustomer(id, ctor as IExtHostCustomerCtor<T>);
31
};
32
}
33
34
export function extHostCustomer<T extends IDisposable, Services extends BrandedService[]>(ctor: { new(context: IExtHostContext, ...services: Services): T }): void {
35
ExtHostCustomersRegistryImpl.INSTANCE.registerCustomer(ctor as IExtHostCustomerCtor<T>);
36
}
37
38
export namespace ExtHostCustomersRegistry {
39
40
export function getNamedCustomers(): IExtHostNamedCustomer<IDisposable>[] {
41
return ExtHostCustomersRegistryImpl.INSTANCE.getNamedCustomers();
42
}
43
44
export function getCustomers(): IExtHostCustomerCtor<IDisposable>[] {
45
return ExtHostCustomersRegistryImpl.INSTANCE.getCustomers();
46
}
47
}
48
49
class ExtHostCustomersRegistryImpl {
50
51
public static readonly INSTANCE = new ExtHostCustomersRegistryImpl();
52
53
private _namedCustomers: IExtHostNamedCustomer<any>[];
54
private _customers: IExtHostCustomerCtor<any>[];
55
56
constructor() {
57
this._namedCustomers = [];
58
this._customers = [];
59
}
60
61
public registerNamedCustomer<T extends IDisposable>(id: ProxyIdentifier<T>, ctor: IExtHostCustomerCtor<T>): void {
62
const entry: IExtHostNamedCustomer<T> = [id, ctor];
63
this._namedCustomers.push(entry);
64
}
65
public getNamedCustomers(): IExtHostNamedCustomer<any>[] {
66
return this._namedCustomers;
67
}
68
69
public registerCustomer<T extends IDisposable>(ctor: IExtHostCustomerCtor<T>): void {
70
this._customers.push(ctor);
71
}
72
public getCustomers(): IExtHostCustomerCtor<any>[] {
73
return this._customers;
74
}
75
}
76
77