forked from intel/Edk2Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.ts
More file actions
334 lines (262 loc) · 9.94 KB
/
configuration.ts
File metadata and controls
334 lines (262 loc) · 9.94 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import path = require('path');
import * as vscode from 'vscode';
import { gDebugLog, gWorkspacePath } from './extension';
import * as fs from 'fs';
import { LogLevel } from './debugLog';
import { askReloadFiles } from './ui/messages';
import { readFile } from './utils';
import { SettingsPanel } from './settings/settingsPanel';
import { getEdkCodeFolderFilePath, existsEdkCodeFolderFile, writeEdkCodeFolderFile } from './edk2CodeFolder';
export interface WorkspaceConfig {
packagePaths:string[];
dscPaths:string[];
buildDefines:string[];
}
export interface WorkspaceConfigErrors{
packagePaths:string;
dscPaths:string;
buildDefines:string;
}
export class ConfigAgent {
getWorkspaceErrors(): WorkspaceConfigErrors | null {
return {packagePaths:"", dscPaths:"", buildDefines:""};
}
public vscodeSettings: vscode.WorkspaceConfiguration;
private reloadConfigs = ["dscPaths", "buildDefines"];
private configFileWatcher: vscode.FileSystemWatcher | null = null;
private propertiesFile: vscode.Uri | undefined | null = undefined; // undefined and null values are handled differently
private settingsPanel:SettingsPanel|undefined;
private workspaceConfig:WorkspaceConfig;
private settingsFileName: string = "edk2_workspace_properties.json";
public constructor() {
this.vscodeSettings = vscode.workspace.getConfiguration('edk2code');
this.workspaceConfig = this.readWpConfig();
vscode.workspace.onDidChangeConfiguration(this.reloadVscodeSettings.bind(this));
}
reloadVscodeSettings(){
this.vscodeSettings = vscode.workspace.getConfiguration('edk2code');
}
isWarningCppExtension(){
return <boolean>this.get("warningAboutCppExtension");
}
async setWarningCppExtension(value:boolean){
await this.set("warningAboutCppExtension",value);
}
isDiagnostics(){
return <boolean>this.get("enableDiagnostics");
}
isAddVscodeLinksToReferences(){
return <boolean>this.get("addVscodeLinksToReferences");
}
reloadConfigFile(){
this.workspaceConfig = this.readWpConfig();
}
getConfigFileUri(){
return vscode.Uri.file(getEdkCodeFolderFilePath(this.settingsFileName));
}
private readWpConfig(){
let settingsPath = getEdkCodeFolderFilePath(this.settingsFileName);
gDebugLog.trace(`Loading configuration from ${settingsPath}`);
if(existsEdkCodeFolderFile(this.settingsFileName)){
try {
return JSON.parse(readFile(settingsPath));
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(`${settingsPath} is corrupted: ${error}`);
return this.getCleanWpConfig();
}
}else{
return this.getCleanWpConfig();
}
}
getWorkspaceConfig(): WorkspaceConfig {
return this.workspaceConfig;
}
writeWorkspaceConfig(config:WorkspaceConfig){
let data = JSON.stringify(config,null,4);
writeEdkCodeFolderFile(this.settingsFileName,data);
this.workspaceConfig = config;
}
clearWpConfiguration(){
this.workspaceConfig = this.getCleanWpConfig();
}
initConfigWatcher(){
this.configFileWatcher = vscode.workspace.createFileSystemWatcher(getEdkCodeFolderFilePath(this.settingsFileName));
// this.configFileWatcher.onDidCreate((uri) => {
// this.propertiesFile = uri;
// this.handleConfigurationChange();
// });
// this.configFileWatcher.onDidDelete(() => {
// this.propertiesFile = null;
// this.resetToDefaultSettings(true);
// this.handleConfigurationChange();
// });
this.configFileWatcher.onDidChange(() => {
this.handleConfigurationChange();
});
}
setPanel(settingsPanel: SettingsPanel) {
this.settingsPanel = settingsPanel;
settingsPanel.configValuesChanged(() => this.saveConfigurationUI());
}
saveConfigurationUI(){
}
handleConfigurationChange() {
let newConfig:WorkspaceConfig = this.readWpConfig();
let reload = false;
if(this.workspaceConfig.dscPaths.toString() !== newConfig.dscPaths.toString()){
reload = true;
}
if(this.workspaceConfig.buildDefines.toString() !== newConfig.buildDefines.toString()){
reload = true;
}
this.workspaceConfig = this.readWpConfig();
if(reload){
askReloadFiles();
}
}
resetToDefaultSettings(arg0: boolean) {
throw new Error('Method not implemented.');
}
getCleanWpConfig():WorkspaceConfig{
return {packagePaths:[], dscPaths:[], buildDefines:[]};
}
get(option: string) {
return this.vscodeSettings.get(option);
}
async set(option: string, value: any) {
await this.vscodeSettings.update(option, value);
}
getLogLevel(): LogLevel {
let logLevel: string = <string>this.get("logLevel");
switch (logLevel) {
case "None":
return LogLevel.none;
case "Error":
return LogLevel.error;
case "Warning":
return LogLevel.warning;
case "Info":
return LogLevel.info;
case "Verbose":
return LogLevel.verbose;
case "Debug":
return LogLevel.debug;
default:
return LogLevel.none;
break;
}
}
async setBuildDefines(defines: Map<string, string>) {
let toSave: string[] = [];
for (const [key, value] of defines.entries()) {
toSave.push(`${key.trim()}=${value.trim()}`);
}
this.workspaceConfig.buildDefines = toSave;
this.writeWorkspaceConfig(this.workspaceConfig);
}
async setBuildDefine(name: string, value: string) {
let buildDefines: string[] = this.workspaceConfig.buildDefines;
let toSave: string[] = [];
for (const def of buildDefines) {
if (!def.startsWith(`${name}=`)) {
toSave.push(def);
}
}
toSave.push(`${name}=${value.trim()}`);
this.workspaceConfig.buildDefines = toSave;
this.writeWorkspaceConfig(this.workspaceConfig);
}
getBuildDefines() {
let buildDefines: string[] = this.workspaceConfig.buildDefines;
let buildDefinesObj: Map<string, string> = new Map();
for (const def of buildDefines) {
if(def.length === 0){continue;}
if (def.includes("=")) {
let values = def.split("=");
if (values.length !== 2) { continue; }
buildDefinesObj.set(values[0].trim(), values[1].trim());
} else {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(`Malformed define in setting: "${def}"`);
}
}
return buildDefinesObj;
}
getBuildPackagePaths() {
let paths = this.workspaceConfig.packagePaths;
let retPaths = [];
for (const p of paths) {
retPaths.push(path.join(gWorkspacePath, p));
}
return retPaths;
}
pushBuildPackagePaths(path:string) {
if(this.workspaceConfig.packagePaths.includes(path)){
return;
}
this.workspaceConfig.packagePaths.push(path);
this.writeWorkspaceConfig(this.workspaceConfig);
}
async setBuildDscPaths(dscFiles: string[]) {
this.workspaceConfig.dscPaths = dscFiles;
this.writeWorkspaceConfig(this.workspaceConfig);
}
getBuildDscPaths() {
return this.workspaceConfig.dscPaths;
}
getIsGenIgnoreFile() {
return <boolean>this.get("generateIgnoreFile");
}
getDelayToRefreshWorkspace() {
return <number>this.get("delayToRefreshWorkspace");
}
getUseEdkCallHiearchy(){
return <boolean>this.get("useEdkCallHierarchy");
}
getExpandCircularOrDuplicateLibraries(){
return <boolean>this.get("ExpandCircularOrDuplicateLibraries");
}
getExtraIgnorePatterns() {
return <string[]>this.get("extraIgnorePatterns");
}
getCscopeOverwritePath() {
return (<string>this.get("cscopeOverwritePath")).trim();
}
getIsGenGuidXrefFile() {
return <boolean>this.get("generateGuidXref");
}
getIsShowLanguageWarnings() {
return <boolean>this.get("showEdk2LanguageWarnings");
}
getIsDimmUnusedLibraries() {
return <boolean>this.get("dimUnusedLibraries");
}
async setDimmUnusedLibraries(value: boolean) {
await this.set("dimUnusedLibraries", value);
}
async saveBuildConfig() {
let savePath = await vscode.window.showSaveDialog({
defaultUri: vscode.Uri.file(gWorkspacePath),
filters: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Json': ['json'],
},
});
if (savePath) {
let packages = this.getBuildPackagePaths();
let dscs = this.getBuildDscPaths();
let defines = this.getBuildDefines();
let definesList = [];
for (const [key, value] of defines) {
definesList.push(`${key}=${value}`);
}
let object = {
"includePaths": packages,
"dscs": dscs,
"defines": definesList
};
fs.writeFileSync(savePath.fsPath, JSON.stringify(object, null, 2));
}
}
}