问题
I'm making a extension for VSCode.
What method is generally to store data? For example, settings for each user, not for each workspace.
I knew the way to store data in user's workspace. But it is troublesome to set values for each workspace again and again.
回答1:
I've found a answer by myself.
ExtensionContext.globalState
https://code.visualstudio.com/api/extension-capabilities/common-capabilities
Code Sample(read and write)
function method_registerCommand(context){
var store = context.globalState;
store.update('user_name', 'Jhon').then(() =>{
console.log(store.get('user_name'));
});
}
or
function method_registerCommand(context){
var store = context.globalState;
store.update('user_name', 'Jhon');
store.setKeysForSync(['user_name']);
console.log(store.get('user_name'));
}
来源:https://stackoverflow.com/questions/65963955/how-to-store-data-for-each-user-vscode-extention