Enable syncing extensions storage

- Implement logic to sync extension storage
- Register keys to sync provided by extension
This commit is contained in:
Sandeep Somavarapu
2020-10-24 21:15:33 +02:00
parent 9b507d2bad
commit 20601293fe
8 changed files with 156 additions and 17 deletions

View File

@@ -57,6 +57,7 @@ import { Dto } from 'vs/base/common/types';
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
import { DebugConfigurationProviderTriggerKind } from 'vs/workbench/api/common/extHostTypes';
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/storageKeys';
export interface IEnvironment {
isExtensionDevelopmentDebug: boolean;
@@ -571,6 +572,7 @@ export interface MainThreadStatusBarShape extends IDisposable {
export interface MainThreadStorageShape extends IDisposable {
$getValue<T>(shared: boolean, key: string): Promise<T | undefined>;
$setValue(shared: boolean, key: string, value: object): Promise<void>;
$registerExtensionStorageKeysToSync(extension: IExtensionIdWithVersion, keys: string[]): void;
}
export interface MainThreadTelemetryShape extends IDisposable {

View File

@@ -371,8 +371,8 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
private _loadExtensionContext(extensionDescription: IExtensionDescription): Promise<vscode.ExtensionContext> {
const globalState = new ExtensionMemento(extensionDescription.identifier.value, true, this._storage);
const workspaceState = new ExtensionMemento(extensionDescription.identifier.value, false, this._storage);
const globalState = new ExtensionMemento(extensionDescription, true, this._storage);
const workspaceState = new ExtensionMemento(extensionDescription, false, this._storage);
const extensionMode = extensionDescription.isUnderDevelopment
? (this._initData.environment.extensionTestsLocationURI ? ExtensionMode.Test : ExtensionMode.Development)
: ExtensionMode.Production;

View File

@@ -6,10 +6,12 @@
import type * as vscode from 'vscode';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
export class ExtensionMemento implements vscode.Memento {
private readonly _id: string;
private readonly _version: string;
private readonly _shared: boolean;
private readonly _storage: ExtHostStorage;
@@ -17,8 +19,16 @@ export class ExtensionMemento implements vscode.Memento {
private _value?: { [n: string]: any; };
private readonly _storageListener: IDisposable;
constructor(id: string, global: boolean, storage: ExtHostStorage) {
this._id = id;
private _syncKeys: string[] = [];
get syncKeys(): ReadonlyArray<string> { return Object.freeze(this._syncKeys); }
set syncKeys(syncKeys: ReadonlyArray<string>) {
this._syncKeys = [...syncKeys];
this._storage.registerExtensionStorageKeysToSync({ id: this._id, version: this._version }, this._syncKeys);
}
constructor(extensionDescription: IExtensionDescription, global: boolean, storage: ExtHostStorage) {
this._id = extensionDescription.identifier.value;
this._version = extensionDescription.version;
this._shared = global;
this._storage = storage;

View File

@@ -7,6 +7,7 @@ import { MainContext, MainThreadStorageShape, ExtHostStorageShape } from './extH
import { Emitter } from 'vs/base/common/event';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/storageKeys';
export interface IStorageChangeEvent {
shared: boolean;
@@ -27,6 +28,10 @@ export class ExtHostStorage implements ExtHostStorageShape {
this._proxy = mainContext.getProxy(MainContext.MainThreadStorage);
}
registerExtensionStorageKeysToSync(extension: IExtensionIdWithVersion, keys: string[]): void {
this._proxy.$registerExtensionStorageKeysToSync(extension, keys);
}
getValue<T>(shared: boolean, key: string, defaultValue?: T): Promise<T | undefined> {
return this._proxy.$getValue<T>(shared, key).then(value => value || defaultValue);
}