Skip to content

Commit 76f1854

Browse files
sdkconfig and workspace watcher fixes for gui menuconfig (#145)
* add create delete watch event * workspace and wsFolder update close guimenuconfig
1 parent 1eedb37 commit 76f1854

File tree

2 files changed

+86
-61
lines changed

2 files changed

+86
-61
lines changed

src/espIdf/menuconfig/confServerProcess.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ export class ConfserverProcess {
203203
ConfserverProcess.instance.confServerChannel = null;
204204
ConfserverProcess.instance = null;
205205
}
206+
if (MenuConfigPanel.currentPanel) {
207+
MenuConfigPanel.currentPanel.dispose();
208+
}
206209
}
207210

208211
private static instance: ConfserverProcess;

src/extension.ts

Lines changed: 83 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export async function activate(context: vscode.ExtensionContext) {
248248
} as IDebugAdapterConfig;
249249
debugAdapterManager.configureAdapter(debugAdapterConfig);
250250
}
251-
ConfserverProcess.resetSavedByUI();
251+
ConfserverProcess.dispose();
252252
});
253253

254254
vscode.debug.onDidTerminateDebugSession((e) => {
@@ -262,17 +262,26 @@ export async function activate(context: vscode.ExtensionContext) {
262262

263263
const sdkconfigWatcher = vscode.workspace.createFileSystemWatcher(
264264
"**/sdkconfig",
265-
true,
266265
false,
267-
true
266+
false,
267+
false
268268
);
269-
const sdkWatchDisposable = sdkconfigWatcher.onDidChange(async () => {
269+
const updateGuiValues = (e: vscode.Uri) => {
270270
if (ConfserverProcess.exists() && !ConfserverProcess.isSavedByUI()) {
271271
ConfserverProcess.loadGuiConfigValues();
272272
}
273273
ConfserverProcess.resetSavedByUI();
274-
});
274+
};
275+
const sdkCreateWatchDisposable = sdkconfigWatcher.onDidCreate(
276+
updateGuiValues
277+
);
278+
context.subscriptions.push(sdkCreateWatchDisposable);
279+
const sdkWatchDisposable = sdkconfigWatcher.onDidChange(updateGuiValues);
275280
context.subscriptions.push(sdkWatchDisposable);
281+
const sdkDeleteWatchDisposable = sdkconfigWatcher.onDidDelete(async () => {
282+
ConfserverProcess.dispose();
283+
});
284+
context.subscriptions.push(sdkDeleteWatchDisposable);
276285

277286
vscode.window.onDidCloseTerminal((terminal: vscode.Terminal) => {
278287
terminal.dispose();
@@ -439,6 +448,9 @@ export async function activate(context: vscode.ExtensionContext) {
439448
currentWorkspace: workspaceRoot,
440449
} as IDebugAdapterConfig;
441450
debugAdapterManager.configureAdapter(debugAdapterConfig);
451+
ConfserverProcess.dispose();
452+
const coverageOptions = getCoverageOptions();
453+
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
442454
}
443455
});
444456
});
@@ -802,68 +814,78 @@ export async function activate(context: vscode.ExtensionContext) {
802814
});
803815

804816
registerIDFCommand("espIdf.setTarget", () => {
805-
PreCheck.perform([openFolderCheck], () => {
817+
PreCheck.perform([openFolderCheck], async () => {
806818
const enterDeviceTargetMsg = locDic.localize(
807819
"extension.enterDeviceTargetMessage",
808820
"Enter device target name"
809821
);
810-
vscode.window
811-
.showQuickPick(
812-
[
813-
{ description: "ESP32", label: "ESP32", target: "esp32" },
814-
{ description: "ESP32-S2", label: "ESP32-S2", target: "esp32s2" },
815-
],
816-
{ placeHolder: enterDeviceTargetMsg }
817-
)
818-
.then(async (selected) => {
819-
if (typeof selected === "undefined") {
820-
return;
821-
}
822-
const configurationTarget = idfConf.readParameter("idf.saveScope");
823-
await idfConf.writeParameter(
824-
"idf.adapterTargetName",
825-
selected.target,
826-
configurationTarget
827-
);
828-
if (selected.target === "esp32") {
829-
await idfConf.writeParameter(
830-
"idf.openOcdConfigs",
831-
["interface/ftdi/esp32_devkitj_v1.cfg", "board/esp32-wrover.cfg"],
832-
configurationTarget
833-
);
834-
}
835-
if (selected.target === "esp32s2") {
836-
await idfConf.writeParameter(
837-
"idf.openOcdConfigs",
838-
["interface/ftdi/esp32_devkitj_v1.cfg", "target/esp32s2.cfg"],
839-
configurationTarget
822+
const selectedTarget = await vscode.window.showQuickPick(
823+
[
824+
{ description: "ESP32", label: "ESP32", target: "esp32" },
825+
{ description: "ESP32-S2", label: "ESP32-S2", target: "esp32s2" },
826+
],
827+
{ placeHolder: enterDeviceTargetMsg }
828+
);
829+
if (!selectedTarget) {
830+
return;
831+
}
832+
const configurationTarget = idfConf.readParameter("idf.saveScope");
833+
await idfConf.writeParameter(
834+
"idf.adapterTargetName",
835+
selectedTarget.target,
836+
configurationTarget
837+
);
838+
if (selectedTarget.target === "esp32") {
839+
await idfConf.writeParameter(
840+
"idf.openOcdConfigs",
841+
["interface/ftdi/esp32_devkitj_v1.cfg", "board/esp32-wrover.cfg"],
842+
configurationTarget
843+
);
844+
}
845+
if (selectedTarget.target === "esp32s2") {
846+
await idfConf.writeParameter(
847+
"idf.openOcdConfigs",
848+
["interface/ftdi/esp32_devkitj_v1.cfg", "target/esp32s2.cfg"],
849+
configurationTarget
850+
);
851+
}
852+
await vscode.window.withProgress(
853+
{
854+
cancellable: false,
855+
location: vscode.ProgressLocation.Notification,
856+
title: "ESP-IDF: Setting device target...",
857+
},
858+
async (
859+
progress: vscode.Progress<{ message: string; increment: number }>
860+
) => {
861+
try {
862+
const idfPathDir = idfConf.readParameter("idf.espIdfPath");
863+
const idfPy = path.join(idfPathDir, "tools", "idf.py");
864+
const modifiedEnv = utils.appendIdfAndToolsToPath();
865+
const pythonBinPath = idfConf.readParameter(
866+
"idf.pythonBinPath"
867+
) as string;
868+
const setTargetResult = await utils.spawn(
869+
pythonBinPath,
870+
[idfPy, "set-target", selectedTarget.target],
871+
{
872+
cwd: workspaceRoot.fsPath,
873+
env: modifiedEnv,
874+
}
840875
);
876+
Logger.info(setTargetResult.toString());
877+
OutputChannel.append(setTargetResult.toString());
878+
} catch (err) {
879+
if (err.message && err.message.indexOf("are satisfied") > -1) {
880+
Logger.info(err.message.toString());
881+
OutputChannel.append(err.message.toString());
882+
} else {
883+
Logger.errorNotify(err, err);
884+
OutputChannel.append(err);
885+
}
841886
}
842-
const idfPathDir = idfConf.readParameter("idf.espIdfPath");
843-
const idfPy = path.join(idfPathDir, "tools", "idf.py");
844-
const modifiedEnv = utils.appendIdfAndToolsToPath();
845-
const pythonBinPath = idfConf.readParameter(
846-
"idf.pythonBinPath"
847-
) as string;
848-
await utils
849-
.spawn(pythonBinPath, [idfPy, "set-target", selected.target], {
850-
cwd: workspaceRoot.fsPath,
851-
env: modifiedEnv,
852-
})
853-
.then((result) => {
854-
Logger.info(result.toString());
855-
OutputChannel.append(result.toString());
856-
})
857-
.catch((err) => {
858-
if (err.message && err.message.indexOf("are satisfied") > -1) {
859-
Logger.info(err.message.toString());
860-
OutputChannel.append(err.message.toString());
861-
} else {
862-
Logger.errorNotify(err, err);
863-
OutputChannel.append(err);
864-
}
865-
});
866-
});
887+
}
888+
);
867889
});
868890
});
869891

0 commit comments

Comments
 (0)