Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up on plugins life-cycle / per connection scoped. #4562

Merged
merged 3 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ export interface ServerPluginRunner {
onMessage(jsonMessage: any): void;
setClient(client: HostedPluginClient): void;
setDefault(defaultRunner: ServerPluginRunner): void;
clientClosed(): void;

/**
* Provides additional metadata.
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class HostedPluginSupport {
Object.keys(pluginsPerHost).forEach(hostKey => {
const plugins: PluginMetadata[] = pluginsPerHost[hostKey];
let pluginID = hostKey;
if (plugins.length === 1) {
if (plugins.length >= 1) {
pluginID = getPluginId(plugins[0].model);
}
const rpc = this.createServerRpc(pluginID, hostKey);
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class HostedPluginProcess implements ServerPluginRunner {
this.client = client;
}

public clientClosed(): void {

}

public setDefault(defaultRunner: ServerPluginRunner): void {

}
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/hosted/node/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class HostedPluginSupport {
this.isPluginProcessRunning = false;
this.terminatePluginServer();
this.isPluginProcessRunning = false;
this.pluginRunners.forEach(runner => runner.clientClosed());
}

runPlugin(plugin: PluginModel): void {
Expand Down
20 changes: 15 additions & 5 deletions packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { WorkspaceExtImpl } from '../../plugin/workspace';
*/
export class PluginHostRPC {

private static apiFactory: PluginAPIFactory;
private apiFactory: PluginAPIFactory;

private pluginManager: PluginManagerExtImpl;

Expand All @@ -50,7 +50,7 @@ export class PluginHostRPC {
this.rpc.set(MAIN_RPC_CONTEXT.WORKSPACE_EXT, workspaceExt);
this.rpc.set(MAIN_RPC_CONTEXT.PREFERENCE_REGISTRY_EXT, preferenceRegistryExt);

PluginHostRPC.apiFactory = createAPIFactory(
this.apiFactory = createAPIFactory(
this.rpc,
this.pluginManager,
envExt,
Expand All @@ -62,23 +62,33 @@ export class PluginHostRPC {
}

// tslint:disable-next-line:no-any
static initialize(contextPath: string, plugin: Plugin): any {
initContext(contextPath: string, plugin: Plugin): any {
console.log('PLUGIN_HOST(' + process.pid + '): initializing(' + contextPath + ')');
try {
const backendInit = require(contextPath);
backendInit.doInitialization(PluginHostRPC.apiFactory, plugin);
backendInit.doInitialization(this.apiFactory, plugin);
} catch (e) {
console.error(e);
}
}

/*
* Stop the given context by calling the plug-in manager.
* note: stopPlugin can also be invoked through RPC proxy.
*/
stopContext(): PromiseLike<void> {
return this.pluginManager.$stopPlugin('');
}

// tslint:disable-next-line:no-any
createPluginManager(envExt: EnvExtImpl, preferencesManager: PreferenceRegistryExtImpl, rpc: any): PluginManagerExtImpl {
const { extensionTestsPath } = process.env;
const self = this;
const pluginManager = new PluginManagerExtImpl({
loadPlugin(plugin: Plugin): void {
console.log('PLUGIN_HOST(' + process.pid + '): PluginManagerExtImpl/loadPlugin(' + plugin.pluginPath + ')');
try {
delete require.cache[require.resolve(plugin.pluginPath)];
return require(plugin.pluginPath);
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -107,7 +117,7 @@ export class PluginHostRPC {
rawModel: plg.source
};

PluginHostRPC.initialize(backendInitPath, plugin);
self.initContext(backendInitPath, plugin);

result.push(plugin);
} else {
Expand Down