Skip to content

Commit 276aee6

Browse files
committed
Accept both simple string and list of strings in args fields for debug
config
1 parent f5d1c7f commit 276aee6

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,
@@ -401,3 +402,26 @@ pub fn should_use_local_or_download(
401402
CheckUpdates::Always => Ok(None),
402403
}
403404
}
405+
406+
/// A type that can be deserialized from either a single string or a list of strings.
407+
///
408+
/// When serialized, it always produces a single string. If it was a list,
409+
/// the elements are joined with a space.
410+
#[derive(Deserialize, Debug, Clone)]
411+
#[serde(untagged)]
412+
pub enum ArgsStringOrList {
413+
String(String),
414+
List(Vec<String>),
415+
}
416+
417+
impl Serialize for ArgsStringOrList {
418+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
419+
where
420+
S: Serializer,
421+
{
422+
match self {
423+
ArgsStringOrList::String(s) => serializer.serialize_str(s),
424+
ArgsStringOrList::List(l) => serializer.serialize_str(&l.join(" ")),
425+
}
426+
}
427+
}

0 commit comments

Comments
 (0)