-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcontextManager.ts
More file actions
44 lines (36 loc) · 1.17 KB
/
contextManager.ts
File metadata and controls
44 lines (36 loc) · 1.17 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
import * as vscode from "vscode";
const CONTEXT_DEFAULTS = {
"coder.authenticated": false,
"coder.isOwner": false,
"coder.loaded": false,
"coder.agentsEnabled": false,
"coder.workspace.connected": false,
"coder.workspace.updatable": false,
} as const;
type CoderContext = keyof typeof CONTEXT_DEFAULTS;
export class ContextManager implements vscode.Disposable {
private readonly context = new Map<CoderContext, boolean>();
public constructor(extensionContext: vscode.ExtensionContext) {
for (const key of Object.keys(CONTEXT_DEFAULTS) as CoderContext[]) {
this.set(key, CONTEXT_DEFAULTS[key]);
}
this.setInternalContexts(extensionContext);
}
private setInternalContexts(extensionContext: vscode.ExtensionContext): void {
vscode.commands.executeCommand(
"setContext",
"coder.devMode",
extensionContext.extensionMode === vscode.ExtensionMode.Development,
);
}
public set(key: CoderContext, value: boolean): void {
this.context.set(key, value);
vscode.commands.executeCommand("setContext", key, value);
}
public get(key: CoderContext): boolean {
return this.context.get(key) ?? CONTEXT_DEFAULTS[key];
}
public dispose() {
this.context.clear();
}
}