Skip to content

Commit

Permalink
Add PluginContext related API
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Mar 31, 2021
1 parent d3cc96f commit 71f762c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ExtPluginApi } from '../common/plugin-ext-api-contribution';
import { RPCProtocol } from '../common/rpc-protocol';
import { Emitter } from '@theia/core/lib/common/event';
import { WebviewsExtImpl } from './webviews';
import { URI as Uri } from '@theia/core/shared/vscode-uri';

export interface PluginHost {

Expand Down Expand Up @@ -346,13 +347,16 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
const globalStoragePath = join(configStorage.hostGlobalStoragePath, plugin.model.id);
const pluginContext: theia.PluginContext = {
extensionPath: plugin.pluginFolder,
extensionUri: Uri.file(plugin.pluginFolder),
globalState: new Memento(plugin.model.id, true, this.storageProxy),
workspaceState: new Memento(plugin.model.id, false, this.storageProxy),
subscriptions: subscriptions,
asAbsolutePath: asAbsolutePath,
logPath: logPath,
storagePath: storagePath,
storageUri: storagePath ? Uri.file(storagePath) : undefined,
globalStoragePath: globalStoragePath,
globalStorageUri: Uri.file(globalStoragePath),
environmentVariableCollection: this.terminalService.getEnvironmentVariableCollection(plugin.model.id)
};
this.pluginContextsMap.set(plugin.model.id, pluginContext);
Expand Down
41 changes: 38 additions & 3 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3088,6 +3088,11 @@ declare module '@theia/plugin' {
*/
extensionPath: string;

/**
* The uri of the directory containing the extension.
*/
readonly extensionUri: Uri;

/**
* Gets the extension's environment variable collection for this workspace, enabling changes
* to be applied to terminal environment variables.
Expand All @@ -3107,20 +3112,50 @@ declare module '@theia/plugin' {
* can store private state. The directory might not exist on disk and creation is
* up to the extension. However, the parent directory is guaranteed to be existent.
*
* Use [`workspaceState`](#ExtensionContext.workspaceState) or
* [`globalState`](#ExtensionContext.globalState) to store key value data.
* Use [`workspaceState`](#PluginContext.workspaceState) or
* [`globalState`](#PluginContext.globalState) to store key value data.
*
* @deprecated Use [storageUri](#PluginContext.storageUri) instead.
*/
storagePath: string | undefined;

/**
* The uri of a workspace specific directory in which the extension
* can store private state. The directory might not exist and creation is
* up to the extension. However, the parent directory is guaranteed to be existent.
* The value is `undefined` when no workspace nor folder has been opened.
*
* Use [`workspaceState`](#PluginContext.workspaceState) or
* [`globalState`](#PluginContext.globalState) to store key value data.
*
* @see [`workspace.fs`](#FileSystem) for how to read and write files and folders from
* an uri.
*/
readonly storageUri: Uri | undefined;

/**
* An absolute file path in which the extension can store global state.
* The directory might not exist on disk and creation is
* up to the extension. However, the parent directory is guaranteed to be existent.
*
* Use [`globalState`](#ExtensionContext.globalState) to store key value data.
* Use [`globalState`](#PluginContext.globalState) to store key value data.
*
* @deprecated Use [globalStorageUri](#PluginContext.globalStorageUri) instead.
*/
readonly globalStoragePath: string;

/**
* The uri of a directory in which the extension can store global state.
* The directory might not exist on disk and creation is
* up to the extension. However, the parent directory is guaranteed to be existent.
*
* Use [`globalState`](#PluginContext.globalState) to store key value data.
*
* @see [`workspace.fs`](#FileSystem) for how to read and write files and folders from
* an uri.
*/
readonly globalStorageUri: Uri;

/**
* An absolute file path of a directory in which the extension can create log files.
* The directory might not exist on disk and creation is up to the extension. However,
Expand Down

0 comments on commit 71f762c

Please sign in to comment.