-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathstate.ts
84 lines (71 loc) · 2.7 KB
/
state.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// state.ts
import * as vscode from "vscode";
// Class for the management of all the workspace state variables
export class StateManager {
constructor(readonly extensionContext: vscode.ExtensionContext) {}
private _get<T>(key: string): T | undefined {
return this.extensionContext.workspaceState.get<T>(key);
}
private _update(key: string, value: any): Thenable<void> {
return this.extensionContext.workspaceState.update(key, value);
}
// The project build configuration (one of the entries in the array of makefile.configurations
// or a default).
get buildConfiguration(): string | undefined {
return this._get<string>("buildConfiguration");
}
set buildConfiguration(v: string | undefined) {
this._update("buildConfiguration", v);
}
// The project build target (one of the targets defined in the makefile).
get buildTarget(): string | undefined {
return this._get<string>("buildTarget");
}
set buildTarget(v: string | undefined) {
this._update("buildTarget", v);
}
// The project launch configuration (one of the entries in the array of makefile.launchConfigurations).
get launchConfiguration(): string | undefined {
return this._get<string>("launchConfiguration");
}
set launchConfiguration(v: string | undefined) {
this._update("launchConfiguration", v);
}
// Whether this project had any configure attempt before
// (it didn't have to succeed or even complete).
// Sent as telemetry information and useful to know
// how many projects are able to configure out of the box.
get ranConfigureInCodebaseLifetime(): boolean {
return this._get<boolean>("ranConfigureInCodebaseLifetime") || false;
}
set ranConfigureInCodebaseLifetime(v: boolean) {
this._update("ranConfigureInCodebaseLifetime", v);
}
// If the project needs a clean configure as a result
// of an operation that alters the configure state
// (makefile configuration change, build target change,
// settings or makefiles edits)
get configureDirty(): boolean {
let dirty: boolean | undefined = this._get<boolean>("configureDirty");
if (dirty === undefined) {
dirty = true;
}
return dirty;
}
set configureDirty(v: boolean) {
this._update("configureDirty", v);
}
// Reset all the variables saved in the workspace state.
reset(reloadWindow: boolean = true): void {
this.buildConfiguration = undefined;
this.buildTarget = undefined;
this.launchConfiguration = undefined;
this.ranConfigureInCodebaseLifetime = false;
this.configureDirty = false;
if (reloadWindow) {
vscode.commands.executeCommand("workbench.action.reloadWindow");
}
}
}