如何保留 vscode 扩展的信息? [英] How to persist information for a vscode extension?

查看:60
本文介绍了如何保留 vscode 扩展的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算编写一个 Visual Studio Code 扩展,它需要保存一些信息,例如计数器.用户可以按快捷键增加或减少计数器,计数器的值将保存在某个地方.下次当用户启动 Visual Studio Code 时,扩展可以加载计数器的最后一个值.我的问题是,存储这些信息的正确位置在哪里?

解决方案

您可能正在寻找 Memento API.ExtensionContext 有两个不同的纪念品实例可以访问:

  • workspaceState<块引用>

    在当前打开的上下文中存储状态的备忘录对象 工作区.

  • globalState<块引用>

    存储独立于当前打开的状态的备忘录对象 工作区.

据我所知,两者都在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆