You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

19 lines
746 B

import { commands } from 'vscode';
import type { ContextKeys } from './constants';
import { CoreCommands } from './constants';
const contextStorage = new Map<string, unknown>();
export function getContext<T>(key: ContextKeys): T | undefined;
export function getContext<T>(key: ContextKeys, defaultValue: T): T;
export function getContext<T>(key: ContextKeys, defaultValue?: T): T | undefined {
return (contextStorage.get(key) as T | undefined) ?? defaultValue;
}
export async function setContext(
key: ContextKeys | `${ContextKeys.ActionPrefix}${string}` | `${ContextKeys.KeyPrefix}${string}`,
value: unknown,
): Promise<void> {
contextStorage.set(key, value);
void (await commands.executeCommand(CoreCommands.SetContext, key, value));
}