Skip to main content

Module StorageProvider

Module StorageProvider 

Source
Expand description

StorageProvider: persists extension and workspace state blobs.

§StorageProvider (Environment)

Implements the StorageProvider trait for MountainEnvironment. Contains the core logic for Memento storage: reading from and writing to JSON storage files on disk.

§Storage scopes

  • Global (IsGlobalScope = true) - application-level key-value store shared across all workspaces; persisted to GlobalMementoPath. Used for user preferences, extension state.
  • Workspace (IsGlobalScope = false) - workspace-specific state; persisted to WorkspaceMementoPath (reloaded on workspace change via UpdateWorkspaceMementoPathAndReload). Used for workspace configs.

§Storage operations

  • GetStorageValue(scope, key) - reads from in-memory HashMap; returns None for missing or empty keys; rejects keys > 1 024 chars.
  • UpdateStorageValue(scope, key, value) - inserts or removes key; rejects values > 10 MB; spawns async SaveStorageToDisk after each mutation.
  • GetAllStorage(scope) - returns the full in-memory map as JSON.
  • SetAllStorage(scope, state) - overwrites the full map and persists.

§Async persistence

All disk writes go through SaveStorageToDisk, which is spawned via tokio::spawn so the trait call returns immediately. The function creates parent directories as needed and logs errors without propagating them (fire-and-forget pattern). Writes are NOT yet atomic (temp+rename); that is a known TODO.

§VS Code reference

  • vs/platform/storage/common/storageService.ts
  • vs/platform/storage/common/memento.ts

Functions§

SaveStorageToDisk 🔒
An internal helper function to asynchronously write the storage map to a file.