13

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?

3
  • What did you wind up choosing?
    – bkelley
    Commented Aug 28, 2019 at 16:47
  • The reason I ask is I like the globalStoragePath, which is very useful, but it's hard to use for paths inside the extension contribution points. (ie, html.experiment.customData = './mystuff' in package.json. There isn't a $globalStoragePath/mystuff that I can put into package.json of my extension, which then gets expanded upon usage.)
    – bkelley
    Commented Aug 28, 2019 at 21:11
  • @bkelley I'm still using storagePath, but globalStoragePath meets my requirements. In fact, it turns out they had already created it when I created this issue, but it was still in "proposed" status. Which contribution do you need it for? I'd strongly recommend you just create an issue on github asking for the ability, perhaps reference #66030. Commented Aug 29, 2019 at 15:57

2 Answers 2

8

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

1

You might want to consider creating a file path defined in the User Settings; I think this solution covers all of your requirements.

You can set a default value in the package.json and it's transparent to the user - they can change it if they want to.

More info here: https://code.visualstudio.com/api/references/contribution-points#contributes.configuration

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.