如何保留 vscode 扩展的信息? [英] How to persist information for a vscode extension?
问题描述
我打算编写一个 Visual Studio Code 扩展,它需要保存一些信息,例如计数器.用户可以按快捷键增加或减少计数器,计数器的值将保存在某个地方.下次当用户启动 Visual Studio Code 时,扩展可以加载计数器的最后一个值.我的问题是,存储这些信息的正确位置在哪里?
您可能正在寻找 Memento
API.ExtensionContext
有两个不同的纪念品实例可以访问:
据我所知,两者都在 VSCode 更新中幸存下来.
I'm planning to write a Visual Studio Code extension and it need to save some information for example a counter. The user can press a shortcut to increase or decrease the counter and the value of the counter will be saved some where. Next time when the user starts Visual Studio Code, the extension can load the counter's last value. My question is, where is the proper place to store this info?
You're probably looking for the Memento
API. The ExtensionContext
has two different memento instances you can access:
workspaceState
A memento object that stores state in the context of the currently opened workspace.
globalState
A memento object that stores state independent of the current opened workspace.
Both survive VSCode updates to my knowledge.
这篇关于如何保留 vscode 扩展的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!