microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.59k stars 29.03k forks source link

How extension store persist key-value data #46195

Closed axetroy closed 6 years ago

axetroy commented 6 years ago

I am writing an extension.

need to store a key-value map data.

And globalState and workspaceState can be persistent?

I have tried it. but it seems not support

// first time should get undefined, next time bootstrap should find it.
console.log(context.workspaceState.get(storageKey)) // undefined

// set state, in the next bootstrap, It should can get the value
context.workspaceState.update(storageKey, "hello world");

Even reboot the vscode or upgrade extension. The data should be found in next bootstrap.

bpasero commented 6 years ago

@axetroy if you are using workspaceState you have to reopen that exact same workspace to get the value. Does it work if you try globalState instead?

axetroy commented 6 years ago

@bpasero

I don't know why it doesn't work before

I try again with globalState. It works now.

Thanks for your time.

btw, can I set the icon of the menus context? I have set the command's icon. but it doesn't work.

should I open other issues or now it does not support?

vscodebot[bot] commented 6 years ago

Please ask your question on StackOverflow. We have a great community over there. They have already answered thousands of questions and are happy to answer yours as well. See also our issue reporting guidelines.

Happy Coding!