Skip to content

Commit b0ac00f

Browse files
committed
Addressing more review comments.
Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
1 parent cbe1b37 commit b0ac00f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/javaRuntimes.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@ export namespace JavaRuntimes {
3737
if (runtime) {
3838
const config = vscode.workspace.getConfiguration('java.configuration').get('runtimes');
3939
if (Array.isArray(config)) {
40-
const candidates = getSupportedJreNames().filter(name => !config.some(r => r.name === name) && compatible(runtime, name));
40+
const candidates = getSupportedJreNames().filter(name => compatible(runtime, name)).reverse();
4141
if (candidates.length > 0) {
4242
const name = await vscode.window.showQuickPick(candidates, {
4343
title: 'Select Java Runtime',
4444
});
4545
if (name) {
46-
config.push({
46+
const newConfig = {
4747
name: name,
4848
path: directory[0].fsPath,
49-
});
49+
};
50+
const index = config.findIndex(r => r.name === name);
51+
if (index >= 0) {
52+
config[index] = newConfig;
53+
} else {
54+
config.push(newConfig);
55+
}
5056
vscode.workspace.getConfiguration('java.configuration').update('runtimes', config, vscode.ConfigurationTarget.Global);
5157
vscode.window.showInformationMessage(`JDK Directory ${directory[0].fsPath} added`);
5258
}

0 commit comments

Comments
 (0)