Skip to content

Commit

Permalink
[vscode] support globalStoragePath
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Efftinge <sven.efftinge@typefox.io>
  • Loading branch information
svenefftinge committed Oct 10, 2019
1 parent 46a3bf3 commit e7bb225
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export interface Plugin {

export interface ConfigStorage {
hostLogPath: string;
hostStoragePath?: string,
hostStoragePath?: string;
hostGlobalStoragePath?: string;
}

export interface EnvInit {
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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 * as os from 'os';
import * as fs from 'fs-extra';

export interface PluginHost {

Expand Down Expand Up @@ -266,6 +268,18 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
const asAbsolutePath = (relativePath: string): string => join(plugin.pluginFolder, relativePath);
const logPath = join(configStorage.hostLogPath, plugin.model.id); // todo check format
const storagePath = join(configStorage.hostStoragePath || '', plugin.model.id);
async function defaultGlobalStorage(): Promise<string> {
const homeTheia = join(os.homedir(), '.theia');
if (!(await fs.pathExists(homeTheia))) {
await fs.mkdir(homeTheia);
}
const globalStorage = join(homeTheia, 'globalStorage');
if (!(await fs.pathExists(globalStorage))) {
await fs.mkdir(globalStorage);
}
return globalStorage;
}
const globalStoragePath = join(configStorage.hostGlobalStoragePath || (await defaultGlobalStorage()), plugin.model.id);
const pluginContext: theia.PluginContext = {
extensionPath: plugin.pluginFolder,
globalState: new Memento(plugin.model.id, true, this.storageProxy),
Expand All @@ -274,6 +288,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
asAbsolutePath: asAbsolutePath,
logPath: logPath,
storagePath: storagePath,
globalStoragePath: globalStoragePath
};
this.pluginContextsMap.set(plugin.model.id, pluginContext);

Expand Down
21 changes: 16 additions & 5 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2648,11 +2648,6 @@ declare module '@theia/plugin' {
*/
asAbsolutePath(relativePath: string): string;

/**
* Return log path for current of the extension.
*/
logPath: string;

/**
* An absolute file path of a workspace specific directory in which the extension
* can store private state. The directory might not exist on disk and creation is
Expand All @@ -2662,6 +2657,22 @@ declare module '@theia/plugin' {
* [`globalState`](#ExtensionContext.globalState) to store key value data.
*/
storagePath: string | 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.
*/
readonly globalStoragePath: string;

/**
* 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,
* the parent directory is guaranteed to be existent.
*/
readonly logPath: string;
}

/**
Expand Down

0 comments on commit e7bb225

Please sign in to comment.