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
28 changes: 24 additions & 4 deletions debug_adapter_schemas/Java.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,32 @@
"description": "The fully qualified name of the class containing the main method. If not specified, the debugger automatically resolves the possible main class from the current project."
},
"args": {
"type": "string",
"description": "The command line arguments passed to the program."
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"description": "The command line arguments passed to the program. Can be a single string or an array of strings."
},
"vmArgs": {
"type": "string",
"description": "The extra options and system properties for the JVM (e.g., -Xms<size> -Xmx<size> -D<name>=<value>)."
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"description": "The extra options and system properties for the JVM (e.g., -Xms<size> -Xmx<size> -D<name>=<value>). Can be a single string or an array of strings."
},
"encoding": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
config::get_java_debug_jar,
lsp::LspWrapper,
util::{
create_path_if_not_exists, get_curr_dir, mark_checked_once, path_to_string,
should_use_local_or_download,
ArgsStringOrList, create_path_if_not_exists, get_curr_dir, mark_checked_once,
path_to_string, should_use_local_or_download,
},
};

Expand All @@ -27,9 +27,9 @@ struct JavaDebugLaunchConfig {
#[serde(skip_serializing_if = "Option::is_none")]
main_class: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
args: Option<String>,
args: Option<ArgsStringOrList>,
#[serde(skip_serializing_if = "Option::is_none")]
vm_args: Option<String>,
vm_args: Option<ArgsStringOrList>,
#[serde(skip_serializing_if = "Option::is_none")]
encoding: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
24 changes: 24 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use regex::Regex;
use serde::{Deserialize, Serialize, Serializer};
use std::{
env::current_dir,
fs,
Expand Down Expand Up @@ -401,3 +402,26 @@ pub fn should_use_local_or_download(
CheckUpdates::Always => Ok(None),
}
}

/// A type that can be deserialized from either a single string or a list of strings.
///
/// When serialized, it always produces a single string. If it was a list,
/// the elements are joined with a space.
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum ArgsStringOrList {
String(String),
List(Vec<String>),
}
Comment on lines +406 to +415
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice touch for adopting the multiple args while maintaining compatibility


impl Serialize for ArgsStringOrList {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
ArgsStringOrList::String(s) => serializer.serialize_str(s),
ArgsStringOrList::List(l) => serializer.serialize_str(&l.join(" ")),
Comment on lines +423 to +424
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we consider trimming the string or single elements in the list before joining?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, we could but I don't really see how that gives us anything. Command-line-args are generally separated by "any amount of whitespace" and if users have trailing and/or leading spaces they work just as well. Personally I'd keep the Serializer as stupid as possible so nobody needs to think twice about what it's doing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good, if things are going to work regardless of whitespaces there's not reason not to merge this

}
}
}