Skip to content

Commit 82ee084

Browse files
authored
Accept both simple string and list of strings in args fields for debug config (#191)
Fixes #190 Adds a new type for leniently deserialized argument-lists. Users can supply either a single string (with whitespace-separated args) or a list of strings (commonly this would be an element for each argument, but mix and match will work as well). Since we only pass these on we simply join them by space upon serializing them back to a string.
1 parent e82bc49 commit 82ee084

3 files changed

Lines changed: 52 additions & 8 deletions

File tree

debug_adapter_schemas/Java.json

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,32 @@
1919
"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."
2020
},
2121
"args": {
22-
"type": "string",
23-
"description": "The command line arguments passed to the program."
22+
"oneOf": [
23+
{
24+
"type": "string"
25+
},
26+
{
27+
"type": "array",
28+
"items": {
29+
"type": "string"
30+
}
31+
}
32+
],
33+
"description": "The command line arguments passed to the program. Can be a single string or an array of strings."
2434
},
2535
"vmArgs": {
26-
"type": "string",
27-
"description": "The extra options and system properties for the JVM (e.g., -Xms<size> -Xmx<size> -D<name>=<value>)."
36+
"oneOf": [
37+
{
38+
"type": "string"
39+
},
40+
{
41+
"type": "array",
42+
"items": {
43+
"type": "string"
44+
}
45+
}
46+
],
47+
"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."
2848
},
2949
"encoding": {
3050
"type": "string",

src/debugger.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
config::get_java_debug_jar,
1414
lsp::LspWrapper,
1515
util::{
16-
create_path_if_not_exists, get_curr_dir, mark_checked_once, path_to_string,
17-
should_use_local_or_download,
16+
ArgsStringOrList, create_path_if_not_exists, get_curr_dir, mark_checked_once,
17+
path_to_string, should_use_local_or_download,
1818
},
1919
};
2020

@@ -27,9 +27,9 @@ struct JavaDebugLaunchConfig {
2727
#[serde(skip_serializing_if = "Option::is_none")]
2828
main_class: Option<String>,
2929
#[serde(skip_serializing_if = "Option::is_none")]
30-
args: Option<String>,
30+
args: Option<ArgsStringOrList>,
3131
#[serde(skip_serializing_if = "Option::is_none")]
32-
vm_args: Option<String>,
32+
vm_args: Option<ArgsStringOrList>,
3333
#[serde(skip_serializing_if = "Option::is_none")]
3434
encoding: Option<String>,
3535
#[serde(skip_serializing_if = "Option::is_none")]

src/util.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use regex::Regex;
2+
use serde::{Deserialize, Serialize, Serializer};
23
use std::{
34
env::current_dir,
45
fs,
@@ -409,3 +410,26 @@ pub fn should_use_local_or_download(
409410
CheckUpdates::Always => Ok(None),
410411
}
411412
}
413+
414+
/// A type that can be deserialized from either a single string or a list of strings.
415+
///
416+
/// When serialized, it always produces a single string. If it was a list,
417+
/// the elements are joined with a space.
418+
#[derive(Deserialize, Debug, Clone)]
419+
#[serde(untagged)]
420+
pub enum ArgsStringOrList {
421+
String(String),
422+
List(Vec<String>),
423+
}
424+
425+
impl Serialize for ArgsStringOrList {
426+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
427+
where
428+
S: Serializer,
429+
{
430+
match self {
431+
ArgsStringOrList::String(s) => serializer.serialize_str(s),
432+
ArgsStringOrList::List(l) => serializer.serialize_str(&l.join(" ")),
433+
}
434+
}
435+
}

0 commit comments

Comments
 (0)