This repository was archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathvscodeSettings.ts
75 lines (61 loc) · 2.34 KB
/
vscodeSettings.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
const configKeys = {
ARDUINO_PATH: "arduino.path",
ARDUINO_COMMAND_PATH: "arduino.commandPath",
ADDITIONAL_URLS: "arduino.additionalUrls",
LOG_LEVEL: "arduino.logLevel",
AUTO_UPDATE_INDEX_FILES: "arduino.autoUpdateIndexFiles",
ENABLE_USB_DETECTOIN: "arduino.enableUSBDetection",
DISABLE_TESTING_OPEN: "arduino.disableTestingOpen",
};
export interface IVscodeSettings {
arduinoPath: string;
commandPath: string;
additionalUrls: string | string[];
logLevel: string;
enableUSBDetection: boolean;
disableTestingOpen: boolean;
updateAdditionalUrls(urls: string | string[]): void;
}
export class VscodeSettings implements IVscodeSettings {
public static getInstance(): IVscodeSettings {
if (!VscodeSettings._instance) {
VscodeSettings._instance = new VscodeSettings();
}
return VscodeSettings._instance;
}
private static _instance: IVscodeSettings;
private constructor() {
}
public get arduinoPath(): string {
return this.getConfigValue<string>(configKeys.ARDUINO_PATH);
}
public get commandPath(): string {
return this.getConfigValue<string>(configKeys.ARDUINO_COMMAND_PATH);
}
public get additionalUrls(): string | string[] {
return this.getConfigValue<string | string[]>(configKeys.ADDITIONAL_URLS);
}
public get logLevel(): string {
return this.getConfigValue<string>(configKeys.LOG_LEVEL) || "info";
}
public get enableUSBDetection(): boolean {
return this.getConfigValue<boolean>(configKeys.ENABLE_USB_DETECTOIN);
}
public get disableTestingOpen(): boolean {
return this.getConfigValue<boolean>(configKeys.DISABLE_TESTING_OPEN);
}
public async updateAdditionalUrls(value) {
await this.setConfigValue(configKeys.ADDITIONAL_URLS, value, true);
}
private getConfigValue<T>(key: string): T {
const workspaceConfig = vscode.workspace.getConfiguration();
return workspaceConfig.get<T>(key);
}
private async setConfigValue(key: string, value, global: boolean = true) {
const workspaceConfig = vscode.workspace.getConfiguration();
await workspaceConfig.update(key, value, global);
}
}