forked from microsoft/vscode-arduino
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvscodeSettings.ts
109 lines (89 loc) · 3.52 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
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
// 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",
ALLOW_PDE_FILETYPE: "arduino.allowPDEFiletype",
ENABLE_USB_DETECTION: "arduino.enableUSBDetection",
DISABLE_TESTING_OPEN: "arduino.disableTestingOpen",
IGNORE_BOARDS: "arduino.ignoreBoards",
SKIP_HEADER_PROVIDER: "arduino.skipHeaderProvider",
DEFAULT_BAUD_RATE: "arduino.defaultBaudRate",
DISABLE_INTELLISENSE_AUTO_GEN: "arduino.disableIntelliSenseAutoGen",
};
export interface IVscodeSettings {
arduinoPath: string;
commandPath: string;
additionalUrls: string | string[];
logLevel: string;
allowPDEFiletype: boolean;
enableUSBDetection: boolean;
disableTestingOpen: boolean;
ignoreBoards: string[];
skipHeaderProvider: boolean;
defaultBaudRate: number;
disableIntelliSenseAutoGen: 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 allowPDEFiletype(): boolean {
return this.getConfigValue<boolean>(configKeys.ALLOW_PDE_FILETYPE);
}
public get enableUSBDetection(): boolean {
return this.getConfigValue<boolean>(configKeys.ENABLE_USB_DETECTION);
}
public get disableTestingOpen(): boolean {
return this.getConfigValue<boolean>(configKeys.DISABLE_TESTING_OPEN);
}
public get ignoreBoards(): string[] {
return this.getConfigValue<string[]>(configKeys.IGNORE_BOARDS);
}
public set ignoreBoards(value: string[]) {
this.setConfigValue(configKeys.IGNORE_BOARDS, value, true);
}
public get defaultBaudRate(): number {
return this.getConfigValue<number>(configKeys.DEFAULT_BAUD_RATE);
}
public get skipHeaderProvider(): boolean {
return this.getConfigValue<boolean>(configKeys.SKIP_HEADER_PROVIDER);
}
public get disableIntelliSenseAutoGen(): boolean {
return this.getConfigValue<boolean>(configKeys.DISABLE_INTELLISENSE_AUTO_GEN);
}
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);
}
}