-
Notifications
You must be signed in to change notification settings - Fork 319
/
Copy pathextension.ts
4243 lines (4069 loc) · 138 KB
/
extension.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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2019 Espressif Systems (Shanghai) CO LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
"use strict";
import * as path from "path";
import * as vscode from "vscode";
import { srcOp, UpdateCmakeLists } from "./cmake/srcsWatcher";
import {
DebugAdapterManager,
IDebugAdapterConfig,
} from "./espIdf/debugAdapter/debugAdapterManager";
import { ConfserverProcess } from "./espIdf/menuconfig/confServerProcess";
import {
IOpenOCDConfig,
OpenOCDManager,
} from "./espIdf/openOcd/openOcdManager";
import { SerialPort } from "./espIdf/serial/serialPort";
import { IDFSize } from "./espIdf/size/idfSize";
import { IDFSizePanel } from "./espIdf/size/idfSizePanel";
import { AppTraceManager } from "./espIdf/tracing/appTraceManager";
import { AppTracePanel } from "./espIdf/tracing/appTracePanel";
import { GdbHeapTraceManager } from "./espIdf/tracing/gdbHeapTraceManager";
import {
AppTraceArchiveTreeDataProvider,
AppTraceArchiveItems,
TraceType,
} from "./espIdf/tracing/tree/appTraceArchiveTreeDataProvider";
import { AppTraceTreeDataProvider } from "./espIdf/tracing/tree/appTraceTreeDataProvider";
import { ExamplesPlanel } from "./examples/ExamplesPanel";
import * as idfConf from "./idfConfiguration";
import { Logger } from "./logger/logger";
import { OutputChannel } from "./logger/outputChannel";
import * as utils from "./utils";
import { PreCheck } from "./utils";
import {
getIdfTargetFromSdkconfig,
getProjectName,
initSelectedWorkspace,
updateIdfComponentsTree,
} from "./workspaceConfig";
import { SystemViewResultParser } from "./espIdf/tracing/system-view";
import { Telemetry } from "./telemetry";
import { ESPRainMakerTreeDataProvider } from "./rainmaker";
import { CommandsProvider } from "./cmdTreeView/cmdTreeDataProvider";
import { RainmakerAPIClient } from "./rainmaker/client";
import { ESP } from "./config";
import { PromptUserToLogin } from "./rainmaker/view/login";
import { RMakerItem } from "./rainmaker/view/item";
import { RainmakerStore } from "./rainmaker/store";
import { RainmakerDeviceParamStructure } from "./rainmaker/client/model";
import { RainmakerOAuthManager } from "./rainmaker/oauth";
import { CoverageRenderer, getCoverageOptions } from "./coverage/renderer";
import { previewReport } from "./coverage/coverageService";
import { WSServer } from "./espIdf/communications/ws";
import { IDFMonitor } from "./espIdf/monitor";
import { BuildTask } from "./build/buildTask";
import { FlashTask } from "./flash/flashTask";
import { ESPCoreDumpPyTool, InfoCoreFileFormat } from "./espIdf/core-dump";
import { ArduinoComponentInstaller } from "./espIdf/arduino/addArduinoComponent";
import { PartitionTableEditorPanel } from "./espIdf/partition-table";
import { ESPEFuseTreeDataProvider } from "./efuse/view";
import { ESPEFuseManager } from "./efuse";
import { constants, createFileSync, pathExists } from "fs-extra";
import { getEspAdf } from "./espAdf/espAdfDownload";
import { getEspMdf } from "./espMdf/espMdfDownload";
import { SetupPanel } from "./setup/SetupPanel";
import { ChangelogViewer } from "./changelog-viewer";
import { getSetupInitialValues, ISetupInitArgs } from "./setup/setupInit";
import {
installEspMatterPyReqs,
installExtensionPyReqs,
} from "./pythonManager";
import { checkExtensionSettings } from "./checkExtensionSettings";
import { CmakeListsEditorPanel } from "./cmake/cmakeEditorPanel";
import { seachInEspDocs } from "./espIdf/documentation/getSearchResults";
import {
DocSearchResult,
DocSearchResultTreeDataProvider,
} from "./espIdf/documentation/docResultsTreeView";
import del from "del";
import { NVSPartitionTable } from "./espIdf/nvs/partitionTable/panel";
import {
getBoards,
getOpenOcdScripts,
} from "./espIdf/openOcd/boardConfiguration";
import { generateConfigurationReport } from "./support";
import { initializeReportObject } from "./support/initReportObj";
import { writeTextReport } from "./support/writeReport";
import { kill } from "process";
import { getNewProjectArgs } from "./newProject/newProjectInit";
import { NewProjectPanel } from "./newProject/newProjectPanel";
import { buildCommand } from "./build/buildCmd";
import { verifyCanFlash } from "./flash/flashCmd";
import { flashCommand } from "./flash/uartFlash";
import { jtagFlashCommand } from "./flash/jtagCmd";
import { createNewIdfMonitor } from "./espIdf/monitor/command";
import { KconfigLangClient } from "./kconfig";
import { configureProjectWithGcov } from "./coverage/configureProject";
import { ComponentManagerUIPanel } from "./component-manager/panel";
import { verifyAppBinary } from "./espIdf/debugAdapter/verifyApp";
import { mergeFlashBinaries } from "./qemu/mergeFlashBin";
import { IQemuOptions, QemuManager } from "./qemu/qemuManager";
import {
PartitionItem,
PartitionTreeDataProvider,
} from "./espIdf/partition-table/tree";
import { flashBinaryToPartition } from "./espIdf/partition-table/partitionFlasher";
import { CustomTask, CustomTaskType } from "./customTasks/customTaskProvider";
import { TaskManager } from "./taskManager";
import { WelcomePanel } from "./welcome/panel";
import { getWelcomePageInitialValues } from "./welcome/welcomeInit";
import { selectDfuDevice } from "./flash/dfu";
import { getEspMatter } from "./espMatter/espMatterDownload";
import { setIdfTarget } from "./espIdf/setTarget";
import { PeripheralTreeView } from "./espIdf/debugAdapter/peripheralTreeView";
import { PeripheralBaseNode } from "./espIdf/debugAdapter/nodes/base";
import { ExtensionConfigStore } from "./common/store";
import { projectConfigurationPanel } from "./project-conf/projectConfPanel";
import {
getProjectConfigurationElements,
ProjectConfigStore,
} from "./project-conf";
import { clearPreviousIdfSetups } from "./setup/existingIdfSetups";
import { getEspRainmaker } from "./rainmaker/download/espRainmakerDownload";
import { UnitTest } from "./espIdf/unitTest/adapter";
import {
buildFlashTestApp,
checkPytestRequirements,
copyTestAppProject,
installPyTestPackages,
} from "./espIdf/unitTest/configure";
import { getFileList, getTestComponents } from "./espIdf/unitTest/utils";
import { saveDefSdkconfig } from "./espIdf/menuconfig/saveDefConfig";
import { createSBOM, installEspSBOM } from "./espBom";
import { getEspHomeKitSdk } from "./espHomekit/espHomekitDownload";
import { getCurrentIdfSetup, selectIdfSetup } from "./versionSwitcher";
import { checkDebugAdapterRequirements } from "./espIdf/debugAdapter/checkPyReqs";
import { CDTDebugConfigurationProvider } from "./cdtDebugAdapter/debugConfProvider";
import { CDTDebugAdapterDescriptorFactory } from "./cdtDebugAdapter/server";
// Global variables shared by commands
let workspaceRoot: vscode.Uri;
const DEBUG_DEFAULT_PORT = 43474;
let covRenderer: CoverageRenderer;
// OpenOCD and Debug Adapter Manager
let statusBarItems: { [key: string]: vscode.StatusBarItem };
const openOCDManager = OpenOCDManager.init();
let isOpenOCDLaunchedByDebug: boolean = false;
let debugAdapterManager: DebugAdapterManager;
let isMonitorLaunchedByDebug: boolean = false;
// QEMU
const qemuManager = QemuManager.init();
// ESP-IDF Docs search results Tree view
let espIdfDocsResultTreeDataProvider: DocSearchResultTreeDataProvider;
// App Tracing
let appTraceTreeDataProvider: AppTraceTreeDataProvider;
let appTraceArchiveTreeDataProvider: AppTraceArchiveTreeDataProvider;
let appTraceManager: AppTraceManager;
let gdbHeapTraceManager: GdbHeapTraceManager;
// Partition table
let partitionTableTreeDataProvider: PartitionTreeDataProvider;
// ESP-IDF Search results
let idfSearchResults: vscode.TreeView<DocSearchResult>;
// ESP Rainmaker
let rainMakerTreeDataProvider: ESPRainMakerTreeDataProvider;
// Commands Provider
let commandTreeDataProvider: CommandsProvider;
// ESP eFuse Explorer
let eFuseExplorer: ESPEFuseTreeDataProvider;
// Peripheral Tree Data Provider
let peripheralTreeProvider: PeripheralTreeView;
let peripheralTreeView: vscode.TreeView<PeripheralBaseNode>;
// Process to execute build, debug or monitor
let monitorTerminal: vscode.Terminal;
// Websocket Server
let wsServer: WSServer;
// Precheck methods and their messages
const openFolderFirstMsg = vscode.l10n.t("Open a folder first.");
const cmdNotForWebIdeMsg = vscode.l10n.t(
"Selected command is not available in WebIDE"
);
const openFolderCheck = [
PreCheck.isWorkspaceFolderOpen,
openFolderFirstMsg,
] as utils.PreCheckInput;
const webIdeCheck = [
PreCheck.notUsingWebIde,
cmdNotForWebIdeMsg,
] as utils.PreCheckInput;
const minOpenOcdVersionCheck = async function () {
const currOpenOcdVersion = await openOCDManager.version();
return [
() =>
PreCheck.openOCDVersionValidator(
"v0.10.0-esp32-20201125",
currOpenOcdVersion
),
`Minimum OpenOCD version v0.10.0-esp32-20201125 is required while you have ${currOpenOcdVersion} version installed`,
] as utils.PreCheckInput;
};
const minIdfVersionCheck = async function (
minVersion: string,
workspace: vscode.Uri
) {
const espIdfPath = idfConf.readParameter(
"idf.espIdfPath",
workspace
) as string;
const gitPath = idfConf.readParameter("idf.gitPath", workspace) || "git";
const currentVersion = await utils.getEspIdfFromCMake(espIdfPath);
return [
() => PreCheck.espIdfVersionValidator(minVersion, currentVersion),
`Selected command needs ESP-IDF v${minVersion} or higher`,
] as utils.PreCheckInput;
};
export async function activate(context: vscode.ExtensionContext) {
// Always load Logger first
Logger.init(context);
Telemetry.init(idfConf.readParameter("idf.telemetry") || false);
utils.setExtensionContext(context);
ChangelogViewer.showChangeLogAndUpdateVersion(context);
debugAdapterManager = DebugAdapterManager.init(context);
OutputChannel.init();
const registerIDFCommand = (
name: string,
callback: (...args: any[]) => any
): number => {
const telemetryCallback = (...args: any[]): any => {
const startTime = Date.now();
Logger.info(`Command::${name}::Executed`);
const cbResult = callback.apply(this, args);
const timeSpent = Date.now() - startTime;
Telemetry.sendEvent("command", { commandName: name }, { timeSpent });
return cbResult;
};
return context.subscriptions.push(
vscode.commands.registerCommand(name, telemetryCallback)
);
};
// init rainmaker cache store
ESP.Rainmaker.store = RainmakerStore.init(context);
ESP.GlobalConfiguration.store = ExtensionConfigStore.init(context);
ESP.ProjectConfiguration.store = ProjectConfigStore.init(context);
// Create a status bar item with current workspace
// Status Bar Item with common commands
statusBarItems = await createCmdsStatusBarItems();
// Create Kconfig Language Server Client
KconfigLangClient.startKconfigLangServer(context);
// Register Tree Provider for IDF Explorer
registerTreeProvidersForIDFExplorer(context);
appTraceManager = new AppTraceManager(
appTraceTreeDataProvider,
appTraceArchiveTreeDataProvider
);
gdbHeapTraceManager = new GdbHeapTraceManager(
appTraceTreeDataProvider,
appTraceArchiveTreeDataProvider
);
// Debug session Peripherals tree view
peripheralTreeProvider = new PeripheralTreeView();
peripheralTreeView = vscode.window.createTreeView("espIdf.peripheralView", {
treeDataProvider: peripheralTreeProvider,
});
context.subscriptions.push(
peripheralTreeView,
peripheralTreeView.onDidExpandElement((e) => {
e.element.expanded = true;
e.element.getPeripheral().updateData();
peripheralTreeProvider.refresh();
})
),
peripheralTreeView.onDidCollapseElement((e) => {
e.element.expanded = false;
});
// register openOCD status bar item
registerOpenOCDStatusBarItem(context);
registerQemuStatusBarItem(context);
if (PreCheck.isWorkspaceFolderOpen()) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
if (statusBarItems && statusBarItems["port"]) {
statusBarItems["port"].text =
"$(plug) " + idfConf.readParameter("idf.port", workspaceRoot);
}
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
}
let unitTestController = new UnitTest(context);
// Add delete or update new sources in CMakeLists.txt of same folder
const newSrcWatcher = vscode.workspace.createFileSystemWatcher(
"**/*.{c,cpp,cc,S}",
false,
false,
false
);
const srcWatchDeleteDisposable = newSrcWatcher.onDidDelete(async (e) => {
if (UpdateCmakeLists.singletonPromise) {
UpdateCmakeLists.singletonPromise.then(() => {
UpdateCmakeLists.updateSrcsInCmakeLists(e.fsPath, srcOp.delete);
UpdateCmakeLists.singletonPromise = undefined;
});
} else {
UpdateCmakeLists.updateSrcsInCmakeLists(e.fsPath, srcOp.delete);
}
});
context.subscriptions.push(srcWatchDeleteDisposable);
const srcWatchCreateDisposable = newSrcWatcher.onDidCreate(async (e) => {
if (UpdateCmakeLists.singletonPromise) {
UpdateCmakeLists.singletonPromise.then(() => {
UpdateCmakeLists.updateSrcsInCmakeLists(e.fsPath, srcOp.other);
UpdateCmakeLists.singletonPromise = undefined;
});
} else {
UpdateCmakeLists.updateSrcsInCmakeLists(e.fsPath, srcOp.other);
}
});
context.subscriptions.push(srcWatchCreateDisposable);
const srcWatchOnChangeDisposable = newSrcWatcher.onDidChange(async (e) => {
if (UpdateCmakeLists.singletonPromise) {
UpdateCmakeLists.singletonPromise.then(() => {
UpdateCmakeLists.updateSrcsInCmakeLists(e.fsPath, srcOp.other);
UpdateCmakeLists.singletonPromise = undefined;
});
} else {
UpdateCmakeLists.updateSrcsInCmakeLists(e.fsPath, srcOp.other);
}
});
context.subscriptions.push(srcWatchOnChangeDisposable);
vscode.workspace.onDidChangeWorkspaceFolders(async (e) => {
if (PreCheck.isWorkspaceFolderOpen()) {
for (const ws of e.removed) {
if (workspaceRoot && ws.uri === workspaceRoot) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
);
if (statusBarItems && statusBarItems["port"]) {
statusBarItems["port"].text =
"$(plug) " + idfConf.readParameter("idf.port", workspaceRoot);
}
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
break;
}
}
if (typeof workspaceRoot === undefined) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
);
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
}
const buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspaceRoot
) as string;
const projectName = await getProjectName(buildDirPath);
const projectElfFile = `${path.join(buildDirPath, projectName)}.elf`;
const debugAdapterConfig = {
currentWorkspace: workspaceRoot,
elfFile: projectElfFile,
} as IDebugAdapterConfig;
debugAdapterManager.configureAdapter(debugAdapterConfig);
const openOCDConfig: IOpenOCDConfig = {
workspace: workspaceRoot,
} as IOpenOCDConfig;
openOCDManager.configureServer(openOCDConfig);
qemuManager.configure({
workspaceFolder: workspaceRoot,
} as IQemuOptions);
}
ConfserverProcess.dispose();
});
vscode.debug.onDidTerminateDebugSession((e) => {
if (isOpenOCDLaunchedByDebug) {
isOpenOCDLaunchedByDebug = false;
openOCDManager.stop();
}
debugAdapterManager.stop();
if (isMonitorLaunchedByDebug) {
isMonitorLaunchedByDebug = false;
monitorTerminal.dispose();
}
});
const sdkconfigWatcher = vscode.workspace.createFileSystemWatcher(
"**/sdkconfig",
false,
false,
false
);
const updateGuiValues = (e: vscode.Uri) => {
if (ConfserverProcess.exists() && !ConfserverProcess.isSavedByUI()) {
ConfserverProcess.loadGuiConfigValues();
}
ConfserverProcess.resetSavedByUI();
};
const sdkCreateWatchDisposable = sdkconfigWatcher.onDidCreate(
updateGuiValues
);
context.subscriptions.push(sdkCreateWatchDisposable);
const sdkWatchDisposable = sdkconfigWatcher.onDidChange(updateGuiValues);
context.subscriptions.push(sdkWatchDisposable);
const sdkDeleteWatchDisposable = sdkconfigWatcher.onDidDelete(async () => {
ConfserverProcess.dispose();
});
context.subscriptions.push(sdkDeleteWatchDisposable);
vscode.window.onDidCloseTerminal(async (terminal: vscode.Terminal) => {});
registerIDFCommand("espIdf.createFiles", async () => {
const notificationMode = idfConf.readParameter(
"idf.notificationMode",
workspaceRoot
) as string;
const ProgressLocation =
notificationMode === idfConf.NotificationMode.All ||
notificationMode === idfConf.NotificationMode.Notifications
? vscode.ProgressLocation.Notification
: vscode.ProgressLocation.Window;
PreCheck.perform([openFolderCheck], async () => {
try {
vscode.window.withProgress(
{
cancellable: true,
location: ProgressLocation,
title: "ESP-IDF: Creating ESP-IDF project...",
},
async (
progress: vscode.Progress<{
message: string;
increment: number;
}>,
cancelToken: vscode.CancellationToken
) => {
const projectDirOption = await vscode.window.showQuickPick(
[
{
label: vscode.l10n.t("Use current folder: {workspace}", {
workspace: workspaceRoot.fsPath,
}),
target: "current",
},
{
label: vscode.l10n.t("Choose a container directory..."),
target: "another",
},
],
{ placeHolder: vscode.l10n.t("Select a directory to use") }
);
if (!projectDirOption) {
return;
}
let projectDirToUse: string;
if (projectDirOption.target === "another") {
const newFolder = await vscode.window.showOpenDialog({
canSelectFolders: true,
canSelectFiles: false,
canSelectMany: false,
});
if (!newFolder) {
return;
}
projectDirToUse = newFolder[0].fsPath;
} else {
projectDirToUse = workspaceRoot.fsPath;
}
const selectedTemplate = await vscode.window.showQuickPick(
utils.chooseTemplateDir(),
{ placeHolder: vscode.l10n.t("Select a template to use") }
);
if (!selectedTemplate) {
return;
}
const resultFolder = path.join(
projectDirToUse,
selectedTemplate.target
);
const doesProjectExists = await pathExists(resultFolder);
if (doesProjectExists) {
Logger.infoNotify(`${resultFolder} already exists.`);
return;
}
const projectPath = vscode.Uri.file(resultFolder);
await utils.createSkeleton(projectPath, selectedTemplate.target);
if (selectedTemplate.label === "arduino-as-component") {
const gitPath =
((await idfConf.readParameter(
"idf.gitPath",
workspaceRoot
)) as string) || "git";
const idfPath = idfConf.readParameter(
"idf.espIdfPath",
workspaceRoot
) as string;
const arduinoComponentManager = new ArduinoComponentInstaller(
idfPath,
resultFolder,
gitPath
);
cancelToken.onCancellationRequested(() => {
arduinoComponentManager.cancel();
});
await arduinoComponentManager.addArduinoAsComponent(idfPath);
}
vscode.commands.executeCommand(
"vscode.openFolder",
projectPath,
true
);
const defaultFoldersMsg = vscode.l10n.t(
"Template folders has been generated."
);
Logger.infoNotify(defaultFoldersMsg);
}
);
} catch (error) {
Logger.errorNotify(error.message, error);
}
});
});
registerIDFCommand("espIdf.fullClean", () => {
PreCheck.perform([openFolderCheck], async () => {
const buildDir = idfConf.readParameter(
"idf.buildPath",
workspaceRoot
) as string;
const buildDirExists = await utils.dirExistPromise(buildDir);
if (!buildDirExists) {
const errStr = vscode.l10n.t(
"There is no build directory to clean, exiting!"
);
OutputChannel.appendLineAndShow(errStr);
return Logger.warnNotify(errStr);
}
if (ConfserverProcess.exists()) {
const closingSDKConfigMsg = vscode.l10n.t(
`Trying to delete the build folder. Closing existing SDK Configuration editor process...`
);
OutputChannel.init().appendLine(closingSDKConfigMsg);
Logger.info(closingSDKConfigMsg);
ConfserverProcess.dispose();
}
const cmakeCacheFile = path.join(buildDir, "CMakeCache.txt");
const doesCmakeCacheExists = utils.canAccessFile(
cmakeCacheFile,
constants.R_OK
);
if (!doesCmakeCacheExists) {
const errStr = vscode.l10n.t(
`There is no CMakeCache.txt. Please try to delete the build directory manually.`
);
OutputChannel.appendLineAndShow(errStr);
return Logger.warnNotify(errStr);
}
if (BuildTask.isBuilding || FlashTask.isFlashing) {
const errStr = vscode.l10n.t(
`There is a build or flash task running. Wait for it to finish or cancel them before clean.`
);
OutputChannel.appendLineAndShow(errStr);
return Logger.warnNotify(errStr);
}
try {
await del(buildDir, { force: true });
const delComponentsOnFullClean = (await idfConf.readParameter(
"idf.deleteComponentsOnFullClean",
workspaceRoot
)) as boolean;
if (delComponentsOnFullClean) {
const managedComponents = path.join(
workspaceRoot.fsPath,
"managed_components"
);
const componentDirExists = await pathExists(managedComponents);
if (componentDirExists) {
await del(managedComponents, { force: true });
}
}
Logger.infoNotify(vscode.l10n.t("Build directory has been deleted."));
} catch (error) {
OutputChannel.appendLineAndShow(error.message);
Logger.errorNotify(error.message, error);
}
});
});
registerIDFCommand("espIdf.eraseFlash", async () => {
PreCheck.perform([webIdeCheck, openFolderCheck], async () => {
if (monitorTerminal) {
monitorTerminal.sendText(ESP.CTRL_RBRACKET);
}
const pythonBinPath = idfConf.readParameter(
"idf.pythonBinPath",
workspaceRoot
) as string;
const idfPathDir = idfConf.readParameter(
"idf.espIdfPath",
workspaceRoot
) as string;
const port = idfConf.readParameter("idf.port", workspaceRoot) as string;
const flashScriptPath = path.join(
idfPathDir,
"components",
"esptool_py",
"esptool",
"esptool.py"
);
const notificationMode = idfConf.readParameter(
"idf.notificationMode",
workspaceRoot
) as string;
const ProgressLocation =
notificationMode === idfConf.NotificationMode.All ||
notificationMode === idfConf.NotificationMode.Notifications
? vscode.ProgressLocation.Notification
: vscode.ProgressLocation.Window;
vscode.window.withProgress(
{
cancellable: true,
location: ProgressLocation,
title: vscode.l10n.t(
"ESP-IDF: Erasing device flash memory (erase_flash)"
),
},
async (
progress: vscode.Progress<{
message: string;
increment: number;
}>,
cancelToken: vscode.CancellationToken
) => {
try {
const result = await utils.execChildProcess(
`${pythonBinPath} ${flashScriptPath} -p ${port} erase_flash`,
process.cwd(),
OutputChannel.init(),
null,
cancelToken
);
OutputChannel.appendLine(result);
Logger.infoNotify("Flash memory content has been erased.");
} catch (error) {
Logger.errorNotify(error.message, error);
}
}
);
});
});
registerIDFCommand("espIdf.addArduinoAsComponentToCurFolder", () => {
PreCheck.perform([openFolderCheck], () => {
const notificationMode = idfConf.readParameter(
"idf.notificationMode",
workspaceRoot
) as string;
const ProgressLocation =
notificationMode === idfConf.NotificationMode.All ||
notificationMode === idfConf.NotificationMode.Notifications
? vscode.ProgressLocation.Notification
: vscode.ProgressLocation.Window;
vscode.window.withProgress(
{
cancellable: true,
location: ProgressLocation,
title: vscode.l10n.t("ESP-IDF: Arduino ESP32 as ESP-IDF component"),
},
async (
progress: vscode.Progress<{
message: string;
increment: number;
}>,
cancelToken: vscode.CancellationToken
) => {
try {
const gitPath =
(await idfConf.readParameter("idf.gitPath", workspaceRoot)) ||
"git";
const idfPath = idfConf.readParameter(
"idf.espIdfPath",
workspaceRoot
) as string;
const arduinoComponentManager = new ArduinoComponentInstaller(
idfPath,
workspaceRoot.fsPath,
gitPath
);
cancelToken.onCancellationRequested(() => {
arduinoComponentManager.cancel();
});
const arduinoDirPath = path.join(
workspaceRoot.fsPath,
"components",
"arduino"
);
const arduinoDirExists = await utils.dirExistPromise(
arduinoDirPath
);
if (arduinoDirExists) {
return Logger.infoNotify(
vscode.l10n.t(`{arduinoDirPath} already exists.`, {
arduinoDirPath,
})
);
}
await arduinoComponentManager.addArduinoAsComponent();
} catch (error) {
Logger.errorNotify(error.message, error);
}
}
);
});
});
registerIDFCommand("espIdf.getEspAdf", async () => getEspAdf(workspaceRoot));
registerIDFCommand("espIdf.getEspMdf", async () => getEspMdf(workspaceRoot));
registerIDFCommand("espIdf.getEspHomeKitSdk", async () =>
getEspHomeKitSdk(workspaceRoot)
);
registerIDFCommand("espIdf.getEspMatter", async () => {
if (process.platform === "win32") {
return vscode.window.showInformationMessage(
vscode.l10n.t(`ESP-Matter is not available for Windows.`)
);
}
getEspMatter(workspaceRoot);
});
registerIDFCommand("espIdf.getEspRainmaker", async () =>
getEspRainmaker(workspaceRoot)
);
registerIDFCommand("espIdf.setMatterDevicePath", async () => {
if (process.platform === "win32") {
return vscode.window.showInformationMessage(
vscode.l10n.t(`ESP-Matter is not available for Windows.`)
);
}
const configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder;
let workspaceFolder = await vscode.window.showWorkspaceFolderPick({
placeHolder: vscode.l10n.t(
`Pick Workspace Folder to which settings should be applied`
),
});
if (!workspaceFolder) {
return;
}
const customMatterDevicePath = await vscode.window.showInputBox({
placeHolder: vscode.l10n.t("Enter ESP_MATTER_DEVICE_PATH path"),
});
if (!customMatterDevicePath) {
return;
}
const customVarsString = idfConf.readParameter(
"idf.customExtraVars",
workspaceFolder
) as { [key: string]: string };
customVarsString["ESP_MATTER_DEVICE_PATH"] = customMatterDevicePath;
await idfConf.writeParameter(
"idf.customExtraVars",
customVarsString,
configurationTarget,
workspaceFolder.uri
);
return vscode.window.showInformationMessage(
vscode.l10n.t(
`ESP_MATTER_DEVICE_PATH has been set in idf.customExtraVars configuration setting.`
)
);
});
registerIDFCommand("espIdf.selectPort", () => {
PreCheck.perform([webIdeCheck, openFolderCheck], async () =>
SerialPort.shared().promptUserToSelect(workspaceRoot)
);
});
registerIDFCommand("espIdf.selectCurrentIdfVersion", () => {
PreCheck.perform([webIdeCheck, openFolderCheck], async () => {
const currentIdfSetup = await selectIdfSetup(
workspaceRoot,
statusBarItems["currentIdfVersion"]
);
});
});
registerIDFCommand("espIdf.customTask", async () => {
try {
const customTask = new CustomTask(workspaceRoot);
customTask.addCustomTask(CustomTaskType.Custom);
await TaskManager.runTasks();
} catch (error) {
const errMsg =
error && error.message ? error.message : "Error at custom task";
Logger.errorNotify(errMsg, error);
}
});
registerIDFCommand("espIdf.pickAWorkspaceFolder", () => {
PreCheck.perform([openFolderCheck], async () => {
const selectCurrentFolderMsg = vscode.l10n.t(
"Select your current folder"
);
try {
const option = await vscode.window.showWorkspaceFolderPick({
placeHolder: selectCurrentFolderMsg,
});
if (!option) {
const noFolderMsg = vscode.l10n.t("No workspace selected.");
Logger.infoNotify(noFolderMsg);
return;
}
workspaceRoot = option.uri;
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
);
if (statusBarItems && statusBarItems["port"]) {
statusBarItems["port"].text =
"$(plug) " + idfConf.readParameter("idf.port", workspaceRoot);
}
updateIdfComponentsTree(workspaceRoot);
const workspaceFolderInfo = {
clickCommand: "espIdf.pickAWorkspaceFolder",
currentWorkSpace: option.name,
tooltip: option.uri.fsPath,
};
utils.updateStatus(statusBarItems["workspace"], workspaceFolderInfo);
const debugAdapterConfig = {
currentWorkspace: workspaceRoot,
} as IDebugAdapterConfig;
debugAdapterManager.configureAdapter(debugAdapterConfig);
const openOCDConfig: IOpenOCDConfig = {
workspace: workspaceRoot,
} as IOpenOCDConfig;
openOCDManager.configureServer(openOCDConfig);
qemuManager.configure({
workspaceFolder: workspaceRoot,
} as IQemuOptions);
ConfserverProcess.dispose();
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
} catch (error) {
Logger.errorNotify(error.message, error);
}
});
});
registerIDFCommand("espIdf.selectConfTarget", async () => {
await idfConf.chooseConfigurationTarget();
});
registerIDFCommand("espIdf.selectNotificationMode", async () => {
const notificationTarget = await vscode.window.showQuickPick(
[
{
description: vscode.l10n.t(
"Show no notifications and do not focus tasks output."
),
label: "Silent",
target: "Silent",
},
{
description: vscode.l10n.t(
"Show notifications but do not focus tasks output."
),
label: "Notifications",
target: "Notifications",
},
{
description: vscode.l10n.t(
"Do not show notifications but focus tasks output."
),
label: "Output",
target: "Output",
},
{
description: vscode.l10n.t(
"Show notifications and focus tasks output."
),
label: "All",
target: "All",
},
],
{ placeHolder: vscode.l10n.t("Select the output and notification mode") }
);
if (!notificationTarget) {
return;
}
const saveScope = idfConf.readParameter("idf.saveScope");
await idfConf.writeParameter(
"idf.notificationMode",
notificationTarget.target,
saveScope,
workspaceRoot
);
Logger.infoNotify(
vscode.l10n.t(`Notification mode has changed to {mode}`, {
mode: notificationTarget.label,
})
);
});
registerIDFCommand("espIdf.clearSavedIdfSetups", async () => {
await clearPreviousIdfSetups();
});
registerIDFCommand("espIdf.setPath", () => {
PreCheck.perform([webIdeCheck], async () => {
const selectFrameworkMsg = vscode.l10n.t(
"Select framework to define its path:"
);
try {
const option = await vscode.window.showQuickPick(
[
{
description: vscode.l10n.t("IDF_PATH Path"),
label: "IDF_PATH",
target: "esp",
},
{
description: vscode.l10n.t("Set IDF_TOOLS_PATH Path"),
label: "IDF_TOOLS_PATH",
target: "idfTools",
},
{
description: vscode.l10n.t("Set paths to append to PATH"),
label: "Custom extra paths",
target: "customExtraPath",
},
],
{ placeHolder: selectFrameworkMsg }
);
if (!option) {
const noOptionMsg = vscode.l10n.t("No option selected.");
Logger.infoNotify(noOptionMsg);
return;
}
let currentValue;
let msg: string;
let paramName: string;
switch (option.target) {
case "esp":
msg = vscode.l10n.t("Enter IDF_PATH Path");
paramName = "idf.espIdfPath";
break;
case "idfTools":
msg = vscode.l10n.t("Enter IDF_TOOLS_PATH path");
paramName = "idf.toolsPath";