-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfig.ts
109 lines (88 loc) · 3.17 KB
/
config.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import * as vscode from "vscode";
import { Location } from "vs-verification-toolbox";
import * as util from "./util";
import { findJavaHome, JavaHome } from "./javaHome";
const namespace = "prusti-assistant";
export function config(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration(namespace);
}
export enum PrustiVersion {
Latest = "Latest",
Tag = "Tag",
Local = "Local"
}
export const prustiVersionKey = "prustiVersion";
export const prustiVersionPath = `${namespace}.${prustiVersionKey}`;
export function prustiVersion(): PrustiVersion {
const defaultVersion = PrustiVersion.Latest;
const versionName = config().get(prustiVersionKey, defaultVersion as string);
const version = PrustiVersion[
// Convert string to enum. See https://stackoverflow.com/a/17381004/2491528
versionName as keyof typeof PrustiVersion
];
if (version !== undefined) {
return version;
} else {
util.userError(
`Prusti has no version named ${versionName}; defaulting to ${defaultVersion}. ` +
"This has been probably caused by an update of the extension. " +
"To fix this error, please choose a valid version in the settings."
);
return defaultVersion;
}
}
const localPrustiPathKey = "localPrustiPath";
export const localPrustiPathPath = `${namespace}.${localPrustiPathKey}`;
export function localPrustiPath(): string {
return config().get(localPrustiPathKey, "");
}
const prustiTagKey = "prustiTag";
export const prustiTagPath = `${namespace}.${prustiTagKey}`;
export function prustiTag(): string {
return config().get(prustiTagKey, "").trim();
}
export function checkForUpdates(): boolean {
return config().get("checkForUpdates", true);
}
export function verifyOnSave(): boolean {
return config().get("verifyOnSave", true);
}
export function verifyOnOpen(): boolean {
return config().get("verifyOnOpen", true);
}
export function reportErrorsOnly(): boolean {
return config().get("reportErrorsOnly", false);
}
// Avoid calling `findJavaHome()` each time.
let cachedFindJavaHome: string | null = null;
export async function javaHome(): Promise<JavaHome | null> {
const configPath = config().get<string>("javaHome", "");
let path;
if (configPath.length > 0) {
path = configPath;
} else {
if (cachedFindJavaHome === null) {
cachedFindJavaHome = await findJavaHome();
}
path = cachedFindJavaHome;
}
if (path === null) { return null; }
return new JavaHome(new Location(path));
}
const serverAddressKey = "serverAddress";
export const serverAddressPath = `${namespace}.${serverAddressKey}`;
export function serverAddress(): string {
return config().get(serverAddressKey, "");
}
export function extraPrustiEnv(): Record<string, string> {
return config().get("extraPrustiEnv", {});
}
export function extraPrustiRustcArgs(): string[] {
return config().get("extraPrustiRustcArgs", []);
}
export function extraCargoPrustiArgs(): string[] {
return config().get("extraCargoPrustiArgs", []);
}
export function extraPrustiServerArgs(): string[] {
return config().get("extraPrustiServerArgs", []);
}