How to store data for each “user” - VSCode Extention

▼魔方 西西 提交于 2021-02-11 04:31:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!