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
134 lines (110 loc) · 4.44 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { toStringArray } from "../common/util";
const configKeys = {
ARDUINO_PATH: "arduino.path",
ARDUINO_COMMAND_PATH: "arduino.commandPath",
ADDITIONAL_URLS: "arduino.additionalUrls",
LOG_LEVEL: "arduino.logLevel",
CLEAR_OUTPUT_ON_START: "arduino.clearOutputOnBuild",
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",
USE_ARDUINO_CLI: "arduino.useArduinoCli",
DISABLE_INTELLISENSE_AUTO_GEN: "arduino.disableIntelliSenseAutoGen",
};
export interface IVscodeSettings {
arduinoPath: string;
commandPath: string;
additionalUrls: string[];
logLevel: string;
clearOutputOnBuild: boolean;
allowPDEFiletype: boolean;
enableUSBDetection: boolean;
disableTestingOpen: boolean;
ignoreBoards: string[];
skipHeaderProvider: boolean;
defaultBaudRate: number;
useArduinoCli: boolean;
disableIntelliSenseAutoGen: boolean;
updateAdditionalUrls(urls: 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[] {
const value = this.getConfigValue<string | string[]>(configKeys.ADDITIONAL_URLS);
// Even though the schema says value must be a string array, version
// 0.4.9 and earlier also allowed a single comma delimeted string. We
// continue to unofficially support that format to avoid breaking
// existing settings, but we immediately write back the correctly
// formatted version.
const split = toStringArray(value);
if (typeof value === "string") {
this.updateAdditionalUrls(split);
}
return split;
}
public get logLevel(): string {
return this.getConfigValue<string>(configKeys.LOG_LEVEL) || "info";
}
public get clearOutputOnBuild(): boolean {
return this.getConfigValue<boolean>(configKeys.CLEAR_OUTPUT_ON_START);
}
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 useArduinoCli(): boolean {
return this.getConfigValue<boolean>(configKeys.USE_ARDUINO_CLI);
}
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);
}
}