Skip to content

Commit

Permalink
Add correct extension mode to plugin context (#10977)
Browse files Browse the repository at this point in the history
* Add correct extension mode to plugin context

The plugin context was hardcoded to have the production extensionMode.
Now a flag is passed to mark a plugin as under development when
deploying it. This flag is stored in the plugin metadata and later set in
the plugin. When creating the context this flag is then converted to the
correct extensionMode.

Fix #10201

Contributed on behalf of STMicroelectronics
Signed-off-by: Eugen Neufeld <[email protected]>

* Remove passing `isUnderDevelopment`

As indicated in a review, remove the passing `isUnderDevelopment`
through the deployment system.

* Rebase on master and include review comments
  • Loading branch information
eneufeld authored May 25, 2022
1 parent fad026f commit 1732179
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- [plugin] Introduce `DebugSession#workspaceFolder` [#11090](https://github.com/eclipse-theia/theia/pull/11090) - Contributed on behalf of STMicroelectronics
- [console] fixed issue in Debug console where console history was not being trimmed in accordance with the maximum commands limit [#10598](https://github.com/eclipse-theia/theia/pull/10598)
- [plugin] added support for `ExtensionMode` [#10201](https://github.com/eclipse-theia/theia/pull/10201) - Contributed on behalf of STMicroelectronics

<a name="breaking_changes_1.26.0">[Breaking Changes:](#breaking_changes_1.26.0)</a>

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-dev/src/node/hosted-plugin-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class HostedPluginReader implements BackendApplicationContribution {
const pluginPath = process.env.HOSTED_PLUGIN;
if (pluginPath) {
const hostedPlugin = new PluginDeployerEntryImpl('Hosted Plugin', pluginPath!, pluginPath);
hostedPlugin.storeValue('isUnderDevelopment', true);
const hostedMetadata = await this.hostedPlugin.promise;
if (hostedMetadata!.model.entryPoint && hostedMetadata!.model.entryPoint.backend) {
this.deployerHandler.deployBackendPlugins([hostedPlugin]);
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export interface Plugin {
model: PluginModel;
rawModel: PluginPackage;
lifecycle: PluginLifecycle;
isUnderDevelopment: boolean;
}

export interface ConfigStorage {
Expand Down Expand Up @@ -197,7 +198,8 @@ export const emptyPlugin: Plugin = {
version: 'empty'
},
packagePath: 'empty'
}
},
isUnderDevelopment: false
};

export interface PluginManagerInitializeParams {
Expand Down
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 @@ -795,6 +795,7 @@ export interface PluginMetadata {
host: string;
model: PluginModel;
lifecycle: PluginLifecycle;
isUnderDevelopment?: boolean;
}

export const MetadataProcessor = Symbol('MetadataProcessor');
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-ext/src/hosted/browser/worker/worker-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ const pluginManager = new PluginManagerExtImpl({
pluginUri: pluginModel.packageUri,
model: pluginModel,
lifecycle: pluginLifecycle,
rawModel
rawModel,
isUnderDevelopment: !!plg.isUnderDevelopment
};
const apiImpl = apiFactory(plugin);
pluginsApiImpl.set(plugin.model.id, apiImpl);
Expand All @@ -146,7 +147,8 @@ const pluginManager = new PluginManagerExtImpl({
lifecycle: pluginLifecycle,
get rawModel(): never {
throw new Error('not supported');
}
},
isUnderDevelopment: !!plg.isUnderDevelopment
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler {
}

const metadata = this.reader.readMetadata(manifest);
metadata.isUnderDevelopment = entry.getValue('isUnderDevelopment') ?? false;

const deployedLocations = this.deployedLocations.get(metadata.model.id) || new Set<string>();
deployedLocations.add(entry.rootPath);
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export class PluginHostRPC {
pluginUri: pluginModel.packageUri,
model: pluginModel,
lifecycle: pluginLifecycle,
rawModel
rawModel,
isUnderDevelopment: !!plg.isUnderDevelopment
});
} else {
let backendInitPath = pluginLifecycle.backendInitPath;
Expand All @@ -182,7 +183,8 @@ export class PluginHostRPC {
pluginUri: pluginModel.packageUri,
model: pluginModel,
lifecycle: pluginLifecycle,
rawModel
rawModel,
isUnderDevelopment: !!plg.isUnderDevelopment
};

self.initContext(backendInitPath, plugin);
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '../common/plugin-api-rpc';
import { PluginMetadata, PluginJsonValidationContribution } from '../common/plugin-protocol';
import * as theia from '@theia/plugin';
import * as types from './types-impl';
import { join } from './path';
import { EnvExtImpl } from './env';
import { PreferenceRegistryExtImpl } from './preference-registry';
Expand Down Expand Up @@ -372,6 +373,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
const secrets = new SecretStorageExt(plugin, this.secrets);
const globalStoragePath = join(configStorage.hostGlobalStoragePath, plugin.model.id);
const extension = new PluginExt(this, plugin);
const extensionModeValue = plugin.isUnderDevelopment ? types.ExtensionMode.Development : types.ExtensionMode.Production;
const pluginContext: theia.PluginContext = {
extensionPath: extension.extensionPath,
extensionUri: extension.extensionUri,
Expand All @@ -386,7 +388,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
globalStoragePath: globalStoragePath,
globalStorageUri: Uri.file(globalStoragePath),
environmentVariableCollection: this.terminalService.getEnvironmentVariableCollection(plugin.model.id),
extensionMode: 1, // @todo: implement proper `extensionMode`.
extensionMode: extensionModeValue,
extension,
logUri: Uri.file(logPath)
};
Expand Down

0 comments on commit 1732179

Please sign in to comment.