/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import { Event, EventEmitter, Memento, Uri } from 'vscode'; export const contextKeyPrefix = 'github.context|'; export class ContextStore { private _onDidChange = new EventEmitter(); get onDidChange(): Event { return this._onDidChange.event; } constructor(private readonly memento: Memento, private readonly scheme: string) { } delete(uri: Uri) { return this.set(uri, undefined); } get(uri: Uri): T | undefined { return this.memento.get(`${contextKeyPrefix}${uri.toString()}`); } async set(uri: Uri, context: T | undefined) { if (uri.scheme !== this.scheme) { throw new Error(`Invalid context scheme: ${uri.scheme}`); } await this.memento.update(`${contextKeyPrefix}${uri.toString()}`, context); this._onDidChange.fire(uri); } }