Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
### Launch

- `mainClass` (required) - The main class of the program (fully qualified name, e.g. [mymodule/]com.xyz.MainClass).
- `args` - The command line arguments passed to the program.
- `args` - The command line arguments passed to the program. Use `"${command:SpecifyProgramArgs}"` to prompt for program arguments.
- `sourcePaths` - The extra source directories of the program. The debugger looks for source code from project settings by default. This option allows the debugger to look for source code in extra directories.
- `modulePaths` - The modulepaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.
- `classPaths` - The classpaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.
Expand Down
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"activationEvents": [
"onLanguage:java",
"onDebugInitialConfigurations",
"onDebugResolve:java"
"onDebugResolve:java",
"onCommand:JavaDebug.SpecifyProgramArgs"
],
"main": "./out/src/extension",
"contributes": {
Expand All @@ -48,6 +49,9 @@
"java"
]
},
"variables": {
"SpecifyProgramArgs": "JavaDebug.SpecifyProgramArgs"
},
"configurationAttributes": {
"launch": {
"required": [
Expand Down Expand Up @@ -284,6 +288,20 @@
"args": ""
}
},
{
"label": "Java: Launch Program with Arguments Prompt",
"description": "Add a new configuration for launching a java program with arguments prompt.",
"body": {
"type": "java",
"name": "Debug (Launch) with Arguments Prompt",
"request": "launch",
"cwd": "^\"\\${workspaceFolder}\"",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "",
"args": "^\"\\${command:SpecifyProgramArgs}\""
}
},
{
"label": "Java: Attach to Remote Program",
"description": "Add a new configuration for attaching to a running java program.",
Expand Down
26 changes: 26 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export function activate(context: vscode.ExtensionContext) {
}
}
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider(reporter)));
context.subscriptions.push(vscode.commands.registerCommand("JavaDebug.SpecifyProgramArgs", async () => {
return specifyProgramArguments(context);
}));
initializeHotCodeReplace(context);
}

Expand All @@ -55,3 +58,26 @@ export function deactivate() {
function fetchUsageData() {
return commands.executeJavaLanguageServerCommand(commands.JAVA_FETCH_USAGE_DATA);
}

function specifyProgramArguments(context: vscode.ExtensionContext): Thenable<string> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add readme instructions.

const javaDebugProgramArgsKey = "JavaDebugProgramArgs";

const options: vscode.InputBoxOptions = {
ignoreFocusOut: true,
placeHolder: "Enter program arguments or leave empty to pass no args",
};

const prevArgs = context.workspaceState.get(javaDebugProgramArgsKey, "");
if (prevArgs.length > 0) {
options.value = prevArgs;
}

return vscode.window.showInputBox(options).then((text) => {
// When user cancels the input box (by pressing Esc), the text value is undefined.
if (text !== undefined) {
context.workspaceState.update(javaDebugProgramArgsKey, text);
}

return text || " ";
});
}