Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store global binary data for a vscode extension

I've written a language server extension for VS code. In order to improve start-up time, I'd like to cache some global state. I'm struggling to find a safe, user transparent, location.

  • The cache is shared between all workspaces
  • It consists of 200-300MB of serialized data
  • It should persist between updates of the extension
  • The extension is cross-platform

I've discovered the following four options, but none of them seem appropriate:

  1. ExtensionContext.extensionPath: This is almost perfect. Obvious to the user, safe sandboxed space. However, it's wiped on extension update.
  2. ExtensionContext.storagePath: This is not global, and hard for the user to clear, so would very quickly end up using GBs of storage space.
  3. ExtensionContext.globalState: Placing 300MB of binary data into a JSON dictionary store seems bad.
  4. %UserData%/linux/OSX equivalents: Adding and deleting files in uncontrolled general userspace is a risk I'd rather avoid.

Where's the appropriate place to store this data?

like image 720
Thomas Boby Avatar asked Jan 04 '19 13:01

Thomas Boby


People also ask

What is a .VS Code folder?

At its heart, Visual Studio Code is a code editor. Like many other code editors, VS Code adopts a common user interface and layout of an explorer on the left, showing all of the files and folders you have access to, and an editor on the right, showing the content of the files you have opened.

How do I create a .VS Code folder?

Adding folders#The File > Add Folder to Workspace command brings up an Open Folder dialog to select the new folder. Once a root folder is added, the Explorer will show the new folder as a root in the File Explorer. You can right-click on any of the root folders and use the context menu to add or remove folders.


1 Answers

The January 2019 release of VS Code added ExtensionContext.globalStoragePath, which is a global version of storagePath

An absolute file path in which the extension can store global state. The directory might not exist on disk and creation is up to the extension. However, the parent directory is guaranteed to be existent.

https://code.visualstudio.com/updates/v1_31#_global-storage-path

like image 124
Thomas Boby Avatar answered Oct 04 '22 07:10

Thomas Boby