diff --git a/packages/main/src/plugin/provider-registry.spec.ts b/packages/main/src/plugin/provider-registry.spec.ts index e798ad4d28c92..73b9241ad38f8 100644 --- a/packages/main/src/plugin/provider-registry.spec.ts +++ b/packages/main/src/plugin/provider-registry.spec.ts @@ -1241,3 +1241,33 @@ describe('shellInProviderConnection', () => { expect(closeMock).toBeCalled(); }); }); + +test('should retrieve provider info from provider internal id', async () => { + providerRegistry.createProvider('id1', 'name1', { + id: 'internal1', + name: 'internal1name', + status: 'installed', + }); + + providerRegistry.createProvider('id2', 'name2', { + id: 'internal2', + name: 'internal2name', + status: 'installed', + }); + + const provider1 = providerRegistry.getProviderInfo('0'); + const provider2 = providerRegistry.getProviderInfo('1'); + const provider3 = providerRegistry.getProviderInfo('2'); + + expect(provider1).toBeDefined(); + expect(provider2).toBeDefined(); + expect(provider3).toBeUndefined(); + + expect(provider1?.id).toBe('internal1'); + expect(provider1?.name).toBe('internal1name'); + expect(provider1?.extensionId).toBe('id1'); + + expect(provider2?.id).toBe('internal2'); + expect(provider2?.name).toBe('internal2name'); + expect(provider2?.extensionId).toBe('id2'); +}); diff --git a/packages/main/src/plugin/provider-registry.ts b/packages/main/src/plugin/provider-registry.ts index e4cf53af070f2..3a1de2da774cb 100644 --- a/packages/main/src/plugin/provider-registry.ts +++ b/packages/main/src/plugin/provider-registry.ts @@ -169,7 +169,7 @@ export class ProviderRegistry { // If the status does not match the current one, we will send a listener event and update the status if (status !== this.providerStatuses.get(providerKey)) { provider.updateStatus(status); - this.listeners.forEach(listener => listener('provider:update-status', this.getProviderInfo(provider))); + this.listeners.forEach(listener => listener('provider:update-status', this.toProviderInfo(provider))); this.providerStatuses.set(providerKey, status); } } @@ -197,7 +197,7 @@ export class ProviderRegistry { ); this.count++; this.providers.set(id, providerImpl); - this.listeners.forEach(listener => listener('provider:create', this.getProviderInfo(providerImpl))); + this.listeners.forEach(listener => listener('provider:create', this.toProviderInfo(providerImpl))); const trackOpts: { name: string; status: string; version?: string } = { name: providerOptions.name, status: providerOptions.status.toString(), @@ -213,7 +213,7 @@ export class ProviderRegistry { disposeProvider(providerImpl: ProviderImpl): void { this.providers.delete(providerImpl.internalId); - this.listeners.forEach(listener => listener('provider:delete', this.getProviderInfo(providerImpl))); + this.listeners.forEach(listener => listener('provider:delete', this.toProviderInfo(providerImpl))); this.apiSender.send('provider-delete', providerImpl.id); } @@ -223,14 +223,14 @@ export class ProviderRegistry { this.providerLifecycleContexts.set(providerImpl.internalId, new LifecycleContextImpl()); this.lifecycleListeners.forEach(listener => - listener('provider:register-lifecycle', this.getProviderInfo(providerImpl), lifecycle), + listener('provider:register-lifecycle', this.toProviderInfo(providerImpl), lifecycle), ); return Disposable.create(() => { this.providerLifecycles.delete(providerImpl.internalId); this.providerLifecycleContexts.delete(providerImpl.internalId); this.lifecycleListeners.forEach(listener => - listener('provider:removal-lifecycle', this.getProviderInfo(providerImpl), lifecycle), + listener('provider:removal-lifecycle', this.toProviderInfo(providerImpl), lifecycle), ); }); } @@ -335,12 +335,12 @@ export class ProviderRegistry { } this.lifecycleListeners.forEach(listener => - listener('provider:before-initialize-lifecycle', this.getProviderInfo(provider), providerLifecycle), + listener('provider:before-initialize-lifecycle', this.toProviderInfo(provider), providerLifecycle), ); await providerLifecycle.initialize(context); this.lifecycleListeners.forEach(listener => - listener('provider:after-initialize-lifecycle', this.getProviderInfo(provider), providerLifecycle), + listener('provider:after-initialize-lifecycle', this.toProviderInfo(provider), providerLifecycle), ); } @@ -350,12 +350,12 @@ export class ProviderRegistry { const context = this.getMatchingLifecycleContext(providerId); this.lifecycleListeners.forEach(listener => - listener('provider:before-start-lifecycle', this.getProviderInfo(provider), providerLifecycle), + listener('provider:before-start-lifecycle', this.toProviderInfo(provider), providerLifecycle), ); await providerLifecycle.start(context); this.lifecycleListeners.forEach(listener => - listener('provider:after-start-lifecycle', this.getProviderInfo(provider), providerLifecycle), + listener('provider:after-start-lifecycle', this.toProviderInfo(provider), providerLifecycle), ); this._onDidUpdateProvider.fire({ id: providerId, @@ -370,11 +370,11 @@ export class ProviderRegistry { const context = this.getMatchingLifecycleContext(providerId); this.lifecycleListeners.forEach(listener => - listener('provider:before-stop-lifecycle', this.getProviderInfo(provider), providerLifecycle), + listener('provider:before-stop-lifecycle', this.toProviderInfo(provider), providerLifecycle), ); await providerLifecycle.stop(context); this.lifecycleListeners.forEach(listener => - listener('provider:after-stop-lifecycle', this.getProviderInfo(provider), providerLifecycle), + listener('provider:after-stop-lifecycle', this.toProviderInfo(provider), providerLifecycle), ); this._onDidUpdateProvider.fire({ id: providerId, @@ -684,7 +684,7 @@ export class ProviderRegistry { return providerConnection; } - protected getProviderInfo(provider: ProviderImpl): ProviderInfo { + protected toProviderInfo(provider: ProviderImpl): ProviderInfo { const containerConnections: ProviderContainerConnectionInfo[] = provider.containerConnections.map(connection => { return this.getProviderContainerConnectionInfo(connection); }); @@ -780,7 +780,7 @@ export class ProviderRegistry { getProviderInfos(): ProviderInfo[] { return Array.from(this.providers.values()) .map(provider => { - return this.getProviderInfo(provider); + return this.toProviderInfo(provider); }) .sort((provider1, provider2) => provider2.name.localeCompare(provider1.name)); } @@ -1157,7 +1157,7 @@ export class ProviderRegistry { this.containerConnectionLifecycleListeners.forEach(listener => { listener( 'provider-container-connection:register', - this.getProviderInfo(provider), + this.toProviderInfo(provider), this.getProviderContainerConnectionInfo(containerProviderConnection), ); }); @@ -1181,7 +1181,7 @@ export class ProviderRegistry { this.containerConnectionLifecycleListeners.forEach(listener => { listener( 'provider-container-connection:update-status', - this.getProviderInfo(provider), + this.toProviderInfo(provider), this.getProviderContainerConnectionInfo(containerConnection), ); }); @@ -1195,7 +1195,7 @@ export class ProviderRegistry { this.containerConnectionLifecycleListeners.forEach(listener => { listener( 'provider-container-connection:unregister', - this.getProviderInfo(provider), + this.toProviderInfo(provider), this.getProviderContainerConnectionInfo(containerConnection), ); }); @@ -1215,7 +1215,7 @@ export class ProviderRegistry { const provider = this.getMatchingProvider(providerId); provider.onDidUpdateStatus(() => { - callback(this.getProviderInfo(provider)); + callback(this.toProviderInfo(provider)); }); this._onDidUpdateProvider.fire({ @@ -1325,4 +1325,12 @@ export class ProviderRegistry { throw error; } } + + getProviderInfo(internalProviderId: string): ProviderInfo | undefined { + const provider = this.providers.get(internalProviderId); + if (provider) { + return this.toProviderInfo(provider); + } + return undefined; + } }