Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vscode] support globalStoragePath #6354

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 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,12 @@ 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 globalStorage = join(os.homedir(), '.theia', 'globalStorage');
await fs.ensureDir(globalStorage);
return globalStorage;
}
const globalStoragePath = join(configStorage.hostGlobalStoragePath || (await defaultGlobalStorage()), plugin.model.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g.~/.theia/globalStorage/mhutchie.git-graph
I think this fine now, thanks!

const pluginContext: theia.PluginContext = {
extensionPath: plugin.pluginFolder,
globalState: new Memento(plugin.model.id, true, this.storageProxy),
Expand All @@ -274,6 +282,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