Skip to content

Commit 43e3320

Browse files
committed
wip
1 parent 7c44b0c commit 43e3320

File tree

2 files changed

+134
-2
lines changed

2 files changed

+134
-2
lines changed

src/extension.ts

+132
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,138 @@ export async function activate(context: vscode.ExtensionContext) {
511511
});
512512
context.subscriptions.push(sdkDeleteWatchDisposable);
513513

514+
const projConfFilePath = vscode.Uri.joinPath(workspaceRoot, "esp_idf_project_configuration.json").fsPath;
515+
let previousConfigVersions = [];
516+
517+
const multiConfigWatcher = vscode.workspace.createFileSystemWatcher(
518+
projConfFilePath,
519+
false,
520+
false,
521+
false
522+
);
523+
524+
525+
const previousProjConf = ESP.ProjectConfiguration.store.get<string>(ESP.ProjectConfiguration.SELECTED_CONFIG);
526+
527+
// Initial read of the file
528+
try {
529+
const configData = JSON.parse(utils.readFileSync(projConfFilePath));
530+
previousConfigVersions = Object.keys(configData);
531+
vscode.window.showInformationMessage(`Loaded ${previousConfigVersions.length} versions: ${previousConfigVersions.join(', ')}`);
532+
} catch (error) {
533+
vscode.window.showErrorMessage(`Error parsing config file: ${error.message}`);
534+
}
535+
536+
const multiConfigWatchDisposable = multiConfigWatcher.onDidChange(
537+
async () => {
538+
try {
539+
const configData = JSON.parse(utils.readFileSync(projConfFilePath));
540+
const currentVersions = Object.keys(configData);
541+
542+
// Find added versions
543+
const addedVersions = currentVersions.filter(v => !previousConfigVersions.includes(v));
544+
// Find removed versions
545+
const removedVersions = previousConfigVersions.filter(v => !currentVersions.includes(v));
546+
547+
if (addedVersions.length > 0) {
548+
vscode.window.showInformationMessage(`New versions added: ${addedVersions.join(', ')}`);
549+
}
550+
if (removedVersions.length > 0) {
551+
vscode.window.showInformationMessage(`Versions removed: ${removedVersions.join(', ')}`);
552+
}
553+
554+
// Update previous versions for next comparison
555+
previousConfigVersions = currentVersions;
556+
557+
// Get the current selected configuration
558+
const currentSelectedConfig = ESP.ProjectConfiguration.store.get<string>(ESP.ProjectConfiguration.SELECTED_CONFIG);
559+
560+
// Important: Update the configuration object in the store if the selected config still exists
561+
if (currentSelectedConfig && currentVersions.includes(currentSelectedConfig)) {
562+
// Update the configuration data in the store
563+
ESP.ProjectConfiguration.store.set(
564+
currentSelectedConfig,
565+
configData[currentSelectedConfig]
566+
);
567+
568+
// Refresh UI and related settings
569+
if (statusBarItems["projectConf"]) {
570+
statusBarItems["projectConf"].dispose();
571+
}
572+
statusBarItems["projectConf"] = createStatusBarItem(
573+
`$(${
574+
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
575+
}) ${currentSelectedConfig}`,
576+
commandDictionary[CommandKeys.SelectProjectConfiguration].tooltip,
577+
CommandKeys.SelectProjectConfiguration,
578+
99,
579+
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
580+
);
581+
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
582+
await utils.setCCppPropertiesJsonCompileCommands(workspaceRoot);
583+
ConfserverProcess.dispose();
584+
} else if (!currentVersions.includes(currentSelectedConfig)) {
585+
// Handle the case where the selected config no longer exists
586+
let statusBarItemName = "Invalid Configuration";
587+
let statusBarItemTooltip =
588+
"Invalid configuration path. Click to modify project configuration";
589+
statusBarItems["projectConf"] = createStatusBarItem(
590+
`$(${
591+
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
592+
}) ${statusBarItemName}`,
593+
statusBarItemTooltip,
594+
"espIdf.projectConfigurationEditor",
595+
99,
596+
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
597+
);
598+
}
599+
} catch (error) {
600+
vscode.window.showErrorMessage(`Error parsing config file: ${error.message}`);
601+
}
602+
}
603+
);
604+
const multiConfigDeleteWatchDisposable = multiConfigWatcher.onDidDelete(
605+
() => {
606+
ESP.ProjectConfiguration.store.set(
607+
ESP.ProjectConfiguration.SELECTED_CONFIG,
608+
previousProjConf
609+
);
610+
if (statusBarItems["projectConf"]) {
611+
statusBarItems["projectConf"].dispose();
612+
}
613+
statusBarItems["projectConf"] = createStatusBarItem(
614+
`$(${
615+
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
616+
}) ${previousProjConf}`,
617+
commandDictionary[CommandKeys.SelectProjectConfiguration].tooltip,
618+
CommandKeys.SelectProjectConfiguration,
619+
99,
620+
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
621+
);
622+
}
623+
)
624+
const multiConfigCreateWatchDisposable = multiConfigWatcher.onDidCreate(
625+
() => {
626+
ESP.ProjectConfiguration.store.set(
627+
ESP.ProjectConfiguration.SELECTED_CONFIG,
628+
previousProjConf
629+
);
630+
if (statusBarItems["projectConf"]) {
631+
statusBarItems["projectConf"].dispose();
632+
}
633+
statusBarItems["projectConf"] = createStatusBarItem(
634+
`$(${
635+
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
636+
}) ${previousProjConf}`,
637+
commandDictionary[CommandKeys.SelectProjectConfiguration].tooltip,
638+
CommandKeys.SelectProjectConfiguration,
639+
99,
640+
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
641+
);
642+
}
643+
)
644+
context.subscriptions.push(multiConfigWatchDisposable, multiConfigDeleteWatchDisposable, multiConfigCreateWatchDisposable);
645+
514646
vscode.window.onDidCloseTerminal(async (terminal: vscode.Terminal) => {});
515647

516648
registerIDFCommand("espIdf.createFiles", async () => {

src/project-conf/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ export async function getProjectConfigurationElements(workspaceFolder: Uri) {
8080
compileArgs: buildConfig?.compileArgs,
8181
ninjaArgs: buildConfig?.ninjaArgs,
8282
buildDirectoryPath: buildDirPath,
83-
sdkconfigDefaults: (await resolveConfigPaths(
83+
sdkconfigDefaults: (resolveConfigPaths(
8484
workspaceFolder,
8585
buildConfig?.sdkconfigDefaults
8686
)) as string[],
87-
sdkconfigFilePath: (await resolveConfigPaths(
87+
sdkconfigFilePath: (resolveConfigPaths(
8888
workspaceFolder,
8989
buildConfig?.sdkconfigFilePath
9090
)) as string,

0 commit comments

Comments
 (0)