-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcache.ts
More file actions
59 lines (52 loc) · 2.2 KB
/
cache.ts
File metadata and controls
59 lines (52 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { ENVS_EXTENSION_ID } from '../../common/constants';
import { getGlobalPersistentState, getWorkspacePersistentState } from '../../common/persistentState';
export const SYSTEM_WORKSPACE_KEY = `${ENVS_EXTENSION_ID}:system:WORKSPACE_SELECTED`;
export const SYSTEM_GLOBAL_KEY = `${ENVS_EXTENSION_ID}:system:GLOBAL_SELECTED`;
export async function clearSystemEnvCache(): Promise<void> {
const workspaceState = await getWorkspacePersistentState();
await workspaceState.clear([SYSTEM_WORKSPACE_KEY]);
const globalState = await getGlobalPersistentState();
await globalState.clear([SYSTEM_GLOBAL_KEY]);
}
export async function getSystemEnvForWorkspace(fsPath: string): Promise<string | undefined> {
const state = await getWorkspacePersistentState();
const data: { [key: string]: string } | undefined = await state.get(SYSTEM_WORKSPACE_KEY);
if (data) {
try {
return data[fsPath];
} catch {
return undefined;
}
}
return undefined;
}
export async function setSystemEnvForWorkspace(fsPath: string, envPath: string | undefined): Promise<void> {
const state = await getWorkspacePersistentState();
const data: { [key: string]: string } = (await state.get(SYSTEM_WORKSPACE_KEY)) ?? {};
if (envPath) {
data[fsPath] = envPath;
} else {
delete data[fsPath];
}
await state.set(SYSTEM_WORKSPACE_KEY, data);
}
export async function setSystemEnvForWorkspaces(fsPath: string[], envPath: string | undefined): Promise<void> {
const state = await getWorkspacePersistentState();
const data: { [key: string]: string } = (await state.get(SYSTEM_WORKSPACE_KEY)) ?? {};
fsPath.forEach((s) => {
if (envPath) {
data[s] = envPath;
} else {
delete data[s];
}
});
await state.set(SYSTEM_WORKSPACE_KEY, data);
}
export async function getSystemEnvForGlobal(): Promise<string | undefined> {
const state = await getGlobalPersistentState();
return await state.get(SYSTEM_GLOBAL_KEY);
}
export async function setSystemEnvForGlobal(envPath: string | undefined): Promise<void> {
const state = await getGlobalPersistentState();
await state.set(SYSTEM_GLOBAL_KEY, envPath);
}