From e7bb2257a8fd18ac97d799258751bc0edc90a72f Mon Sep 17 00:00:00 2001 From: Sven Efftinge Date: Thu, 10 Oct 2019 08:37:42 +0000 Subject: [PATCH] [vscode] support `globalStoragePath` Signed-off-by: Sven Efftinge --- .../plugin-ext/src/common/plugin-api-rpc.ts | 3 ++- .../plugin-ext/src/plugin/plugin-manager.ts | 15 +++++++++++++ packages/plugin/src/theia.d.ts | 21 ++++++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index b315440bebe8f..3cc92a7501667 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -88,7 +88,8 @@ export interface Plugin { export interface ConfigStorage { hostLogPath: string; - hostStoragePath?: string, + hostStoragePath?: string; + hostGlobalStoragePath?: string; } export interface EnvInit { diff --git a/packages/plugin-ext/src/plugin/plugin-manager.ts b/packages/plugin-ext/src/plugin/plugin-manager.ts index c74fe7160014b..6ef1f3ef62fd4 100644 --- a/packages/plugin-ext/src/plugin/plugin-manager.ts +++ b/packages/plugin-ext/src/plugin/plugin-manager.ts @@ -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 { @@ -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 { + 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), @@ -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); diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 38ea14aa4b3a8..36a9ee08e81cf 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -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 @@ -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; } /**