-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Support synchronising extension's global state #95209
Comments
For Docker extension, we'd need to be able to sync on a per-key basis. There are some areas where sync would be nice to have (nothing imperative, right now), but there are some where we cannot sync (e.g. machine-specific information that we want to cache forever because it's expensive to compute but never changes). |
Proposal: Provide a contribution point for the extension to register memento keys to sync "contributes": {
"settingsSync.memento": {
"global": [
"key1"
]
}
} |
I like that plan. We do have some keys in the Docker extension that are determined at runtime (thus couldn't be in package.json), but I don't think any of them need synchronization. |
export interface Memento {
/**
* Return a value.
*
* @param key A string.
* @return The stored value or `undefined`.
*/
get<T>(key: string): T | undefined;
/**
* Return a value.
*
* @param key A string.
* @param defaultValue A value that should be returned when there is no
* value (`undefined`) with the given key.
* @return The stored value or the defaultValue.
*/
get<T>(key: string, defaultValue: T): T;
/**
* Store a value. The value must be JSON-stringifyable.
*
* @param key A string.
* @param value A value. MUST not contain cyclic references.
*/
update(key: string, value: any, includeInSettingsSync?: boolean): Thenable<void>;
keys(): ReadonlyArray<string>;
onDidChange: Event<{ readonly keys: ReadonlyArray<string> }>;
} |
Alternative proposal avoiding update-sync-not-sync confusion and very simple migration.
|
@bwateratmsft agreed! But that is a different feature - we need context properties for the settings just like commands have :) Worths creating an issue for that if there isn't one yet 😊 |
@legomushroom I'm not sure I follow. This issue is about using settings sync to synchronize global state (mementos), right? I'm not sure commands are related. |
Added following proposed API export interface ExtensionContext {
readonly syncedGlobalState: Memento & {
/**
* List of keys whose values should be synced across devices when extensions synchronization is enabled .
* Set synced keys to an empty array to unset the synced state.
*/
syncedKeys: ReadonlyArray<string>;
};
} Note: @jrieken let me know if there are any suggestions. |
Is having |
Mainly to support
Edit: Also inlined in the proposed API
Planning to add the event later. |
This would still include the change to package.json to specify which keys to sync, right? |
|
If it's read-only, how do they update it? |
|
You have it as a Or are we just approaching this from opposite directions, I'm thinking you add/remove elements, you're thinking you replace the whole array? |
I do not think there is an easy way to listen to changes when elements are added or removed from an array. Hence went with updating the entire array for updates. |
Good point, that makes sense. 👍 |
Finalised following:
|
this is great! please link to this issue in your vscode v1.51 update docs, or to better docs on this ext. state sync feature since the api link in that section is circular atm: https://code.visualstudio.com/updates/v1_51#_settings-sync should probably be linked to this: https://code.visualstudio.com/updates/v1_51#_sync-global-state |
Support synchronising extension's global state
The text was updated successfully, but these errors were encountered: