-
Notifications
You must be signed in to change notification settings - Fork 493
Add command to add JDK to settings #4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getRuntime } from "jdk-utils"; | ||
import * as vscode from "vscode"; | ||
import { getSupportedJreNames } from "./jdkUtils"; | ||
|
||
|
||
export namespace JavaRuntimes { | ||
export async function initialize(context: vscode.ExtensionContext): Promise<void> { | ||
context.subscriptions.push(vscode.commands.registerCommand('java.runtimes.add', async () => { | ||
const directory = await vscode.window.showOpenDialog({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe default to parent folder of last selected JDK (just to make my testing easier) |
||
canSelectFiles: false, | ||
canSelectFolders: true, | ||
canSelectMany: false, | ||
title: 'Select JDK Directory', | ||
}); | ||
if (directory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth validating the directory by at least checking |
||
const runtime = await getRuntime(directory[0].fsPath); | ||
if (runtime) { | ||
const config = vscode.workspace.getConfiguration('java.configuration').get('runtimes'); | ||
if (Array.isArray(config)) { | ||
if (config.some(r => r.path === directory[0].fsPath)) { | ||
vscode.window.showErrorMessage(`JDK Directory ${directory[0].fsPath} already configured`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} else { | ||
const name = await vscode.window.showQuickPick(getSupportedJreNames(), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would improve it by:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also pre Java 8 support has been dropped over a year ago. Can you remove the J2SE-1.5 ... JavaSE-7 values in package.json |
||
title: 'Select Java Runtime', | ||
}); | ||
if (name) { | ||
config.push({ | ||
name: name, | ||
path: directory[0].fsPath, | ||
}); | ||
} | ||
vscode.workspace.getConfiguration('java.configuration').update('runtimes', config, vscode.ConfigurationTarget.Global); | ||
vscode.window.showInformationMessage(`JDK Directory ${directory[0].fsPath} added`); | ||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be executed only if the quickpick was complete. If I press ESC while the wizard is open, I see the "...added" message. |
||
} | ||
} | ||
} else { | ||
vscode.window.showErrorMessage(`Invalid JDK Directory ${directory[0].fsPath}`); | ||
} | ||
} | ||
})); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably add "java.runtimes.add" to
Commands
.