Skip to content

Commit

Permalink
PR eclipse-theia#6252 introduces a refactoring about metadata introdu…
Browse files Browse the repository at this point in the history
…cing pluginIds, deployedPlugins, etc.

Update the extra information to match the real expectations of methods (string ids in some case, DeployedPlugin in the other case)

Change-Id: I82b5e5cdad2e42cba9e1dd469eadbeb0fac29e3e
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf authored and akosyakov committed Feb 24, 2020
1 parent 493e051 commit 98efb1a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
10 changes: 8 additions & 2 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,15 @@ export interface ServerPluginRunner {
clientClosed(): void;

/**
* Provides additional metadata.
* Provides additional deployed plugins.
*/
getExtraPluginMetadata(): Promise<PluginMetadata[]>;
getExtraDeployedPlugins(): Promise<DeployedPlugin[]>;

/**
* Provides additional plugin ids.
*/
getExtraDeployedPluginIds(): Promise<string[]>;

}

export const PluginHostEnvironmentVariable = Symbol('PluginHostEnvironmentVariable');
Expand Down
14 changes: 12 additions & 2 deletions packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { injectable, inject, named } from 'inversify';
import { ILogger, ConnectionErrorHandler, ContributionProvider, MessageService } from '@theia/core/lib/common';
import { Emitter } from '@theia/core/lib/common/event';
import { createIpcEnv } from '@theia/core/lib/node/messaging/ipc-protocol';
import { HostedPluginClient, ServerPluginRunner, PluginMetadata, PluginHostEnvironmentVariable } from '../../common/plugin-protocol';
import { HostedPluginClient, ServerPluginRunner, PluginHostEnvironmentVariable, DeployedPlugin } from '../../common/plugin-protocol';
import { RPCProtocolImpl } from '../../common/rpc-protocol';
import { MAIN_RPC_CONTEXT } from '../../common/plugin-api-rpc';
import { HostedPluginCliContribution } from './hosted-plugin-cli-contribution';
Expand Down Expand Up @@ -192,7 +192,17 @@ export class HostedPluginProcess implements ServerPluginRunner {
this.logger.error(`Error from plugin host: ${err.message}`);
}

async getExtraPluginMetadata(): Promise<PluginMetadata[]> {
/**
* Provides additional plugin ids.
*/
public async getExtraDeployedPluginIds(): Promise<string[]> {
return [];
}

/**
* Provides additional deployed plugins.
*/
public async getExtraDeployedPlugins(): Promise<DeployedPlugin[]> {
return [];
}

Expand Down
16 changes: 13 additions & 3 deletions packages/plugin-ext/src/hosted/node/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { injectable, inject, multiInject, postConstruct, optional } from 'inversify';
import { ILogger, ConnectionErrorHandler } from '@theia/core/lib/common';
import { HostedPluginClient, PluginModel, ServerPluginRunner, PluginMetadata } from '../../common/plugin-protocol';
import { HostedPluginClient, PluginModel, ServerPluginRunner, DeployedPlugin } from '../../common/plugin-protocol';
import { LogPart } from '../../common/types';
import { HostedPluginProcess } from './hosted-plugin-process';

Expand Down Expand Up @@ -98,8 +98,18 @@ export class HostedPluginSupport {
}
}

public async getExtraPluginMetadata(): Promise<PluginMetadata[]> {
return [].concat.apply([], await Promise.all(this.pluginRunners.map(runner => runner.getExtraPluginMetadata())));
/**
* Provides additional plugin ids.
*/
public async getExtraDeployedPluginIds(): Promise<string[]> {
return [].concat.apply([], await Promise.all(this.pluginRunners.map(runner => runner.getExtraDeployedPluginIds())));
}

/**
* Provides additional deployed plugins.
*/
public async getExtraDeployedPlugins(): Promise<DeployedPlugin[]> {
return [].concat.apply([], await Promise.all(this.pluginRunners.map(runner => runner.getExtraDeployedPlugins())));
}

public sendLog(logPart: LogPart): void {
Expand Down
22 changes: 9 additions & 13 deletions packages/plugin-ext/src/hosted/node/plugin-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { injectable, inject, named, postConstruct } from 'inversify';
import { HostedPluginServer, HostedPluginClient, PluginMetadata, PluginDeployer, GetDeployedPluginsParams, DeployedPlugin } from '../../common/plugin-protocol';
import { HostedPluginServer, HostedPluginClient, PluginDeployer, GetDeployedPluginsParams, DeployedPlugin } from '../../common/plugin-protocol';
import { HostedPluginSupport } from './hosted-plugin';
import { ILogger, Disposable } from '@theia/core';
import { ContributionProvider } from '@theia/core';
Expand Down Expand Up @@ -75,9 +75,8 @@ export class HostedPluginServerImpl implements HostedPluginServer {
for (const pluginId of backendMetadata) {
plugins.add(pluginId);
}
const extraPluginMetadata = await this.hostedPlugin.getExtraPluginMetadata();
for (const plugin of extraPluginMetadata) {
plugins.add(plugin.model.id);
for (const pluginId of await this.hostedPlugin.getExtraDeployedPluginIds()) {
plugins.add(pluginId);
}
return [...plugins.values()];
}
Expand All @@ -87,20 +86,17 @@ export class HostedPluginServerImpl implements HostedPluginServer {
return [];
}
const plugins = [];
let extraPluginMetadata: Map<string, PluginMetadata> | undefined;
let extraDeployedPlugins: Map<string, DeployedPlugin> | undefined;
for (const pluginId of pluginIds) {
let plugin = this.deployerHandler.getDeployedPlugin(pluginId);
if (!plugin) {
if (!extraPluginMetadata) {
extraPluginMetadata = new Map<string, PluginMetadata>();
for (const extraMetadata of await this.hostedPlugin.getExtraPluginMetadata()) {
extraPluginMetadata.set(extraMetadata.model.id, extraMetadata);
if (!extraDeployedPlugins) {
extraDeployedPlugins = new Map<string, DeployedPlugin>();
for (const extraDeployedPlugin of await this.hostedPlugin.getExtraDeployedPlugins()) {
extraDeployedPlugins.set(extraDeployedPlugin.metadata.model.id, extraDeployedPlugin);
}
}
const metadata = extraPluginMetadata.get(pluginId);
if (metadata) {
plugin = { metadata };
}
plugin = extraDeployedPlugins.get(pluginId);
}
if (plugin) {
plugins.push(plugin);
Expand Down

0 comments on commit 98efb1a

Please sign in to comment.