Skip to content

Commit

Permalink
[plugin] fix resolution of missing and promisified activation
Browse files Browse the repository at this point in the history
Before a promise will be returned instead of an API or a VS Code extension is never considered activated (for missing activate fn)

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Aug 26, 2019
1 parent 06a0b1f commit 1f7501e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { Memento, KeyValueStorageProxy } from './plugin-storage';
import { ExtPluginApi } from '../common/plugin-ext-api-contribution';
import { RPCProtocol } from '../common/rpc-protocol';
import { Emitter } from '@theia/core/lib/common/event';
import { MaybePromise } from '@theia/core/lib/common/types';

export interface PluginHost {

Expand Down Expand Up @@ -254,17 +255,18 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
if (typeof pluginMain[plugin.lifecycle.stopMethod] === 'function') {
stopFn = pluginMain[plugin.lifecycle.stopMethod];
}
// No activate found => the module is the extension's exports
let pluginExports = pluginMain;
if (typeof pluginMain[plugin.lifecycle.startMethod] === 'function') {
const pluginExport = await pluginMain[plugin.lifecycle.startMethod].apply(getGlobal(), [pluginContext]);
this.activatedPlugins.set(plugin.model.id, new ActivatedPlugin(pluginContext, pluginExport, stopFn));
const maybePluginExports: MaybePromise<PluginAPI> | undefined = await pluginMain[plugin.lifecycle.startMethod].apply(getGlobal(), [pluginContext]);
pluginExports = await maybePluginExports;
}
this.activatedPlugins.set(plugin.model.id, new ActivatedPlugin(pluginContext, pluginExports, stopFn));

// resolve activation promise
if (this.pluginActivationPromises.has(plugin.model.id)) {
this.pluginActivationPromises.get(plugin.model.id)!.resolve();
this.pluginActivationPromises.delete(plugin.model.id);
}
} else {
console.log(`There is no ${plugin.lifecycle.startMethod} method on plugin`);
// resolve activation promise
if (this.pluginActivationPromises.has(plugin.model.id)) {
this.pluginActivationPromises.get(plugin.model.id)!.resolve();
this.pluginActivationPromises.delete(plugin.model.id);
}
}

Expand Down

0 comments on commit 1f7501e

Please sign in to comment.