Skip to content

Commit e3bad18

Browse files
committed
fix(vscode): drop selected profiles that no longer exist in the config
When a profile was selected and then removed from robot.toml — for example after switching git branches — the selection stayed active. This produced a "profile not found" error on every test run, and the profile could not be deselected because the selection menu refused to open when no profiles were left to choose from. Now opening "Select Configuration Profiles" removes any selected profile that is no longer defined in the configuration and shows a message listing which profiles were removed. If the available profiles cannot be determined (e.g. an invalid environment), the current selection is left untouched. Fixes #498
1 parent 0b6baeb commit e3bad18

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

vscode-client/extension/testcontrollermanager.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,13 +587,32 @@ export class TestControllerManager {
587587
}
588588
try {
589589
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
590-
const result = await this.getRobotCodeProfiles(folder, config.get("profiles", undefined));
591-
592-
if (result.profiles.length === 0 && result.messages) {
593-
await vscode.window.showWarningMessage(result.messages.join("\n"));
594-
return;
590+
const selectedProfiles = config.get<string[]>("profiles", []);
591+
const result = await this.getRobotCodeProfiles(folder, selectedProfiles.length ? selectedProfiles : undefined);
592+
593+
// Drop configured profiles that are no longer defined in the configuration so they don't
594+
// linger as an unselectable, active selection. Skip this when the available profiles could
595+
// not be determined (e.g. invalid environment) to avoid clearing a still-valid selection.
596+
const couldNotDetermine = result.profiles.length === 0 && !result.messages?.length;
597+
const availableNames = new Set(result.profiles.map((p) => p.name));
598+
const removedProfiles = couldNotDetermine ? [] : selectedProfiles.filter((name) => !availableNames.has(name));
599+
if (removedProfiles.length > 0) {
600+
await config.update(
601+
"profiles",
602+
selectedProfiles.filter((name) => availableNames.has(name)),
603+
vscode.ConfigurationTarget.WorkspaceFolder,
604+
);
595605
}
596606

607+
const removedMessage =
608+
removedProfiles.length === 0
609+
? undefined
610+
: removedProfiles.length === 1
611+
? `The selected profile "${removedProfiles[0]}" was removed because it is no longer defined in the configuration.`
612+
: `The selected profiles ${removedProfiles
613+
.map((p) => `"${p}"`)
614+
.join(", ")} were removed because they are no longer defined in the configuration.`;
615+
597616
const options = result.profiles.map((p) => {
598617
return {
599618
label: truncateAndReplaceNewlines(p.name.trim()),
@@ -602,6 +621,18 @@ export class TestControllerManager {
602621
};
603622
});
604623

624+
if (options.length === 0) {
625+
const baseMessage = result.messages?.length
626+
? result.messages.join("\n")
627+
: "No configuration profiles available.";
628+
await vscode.window.showWarningMessage(removedMessage ? `${removedMessage}\n${baseMessage}` : baseMessage);
629+
return;
630+
}
631+
632+
if (removedMessage) {
633+
vscode.window.showWarningMessage(removedMessage);
634+
}
635+
605636
const profiles = await vscode.window.showQuickPick([...options], {
606637
title: `Select Configuration Profiles for folder "${folder.name}"`,
607638
canPickMany: true,

0 commit comments

Comments
 (0)