From 276aee65423a7556081e0f289dcbcddfd69a568e Mon Sep 17 00:00:00 2001 From: Karl-Erik Enkelmann Date: Sun, 15 Feb 2026 21:08:20 +0100 Subject: [PATCH] Accept both simple string and list of strings in args fields for debug config --- debug_adapter_schemas/Java.json | 28 ++++++++++++++++++++++++---- src/debugger.rs | 8 ++++---- src/util.rs | 24 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/debug_adapter_schemas/Java.json b/debug_adapter_schemas/Java.json index 896a3b9..e36b5bf 100644 --- a/debug_adapter_schemas/Java.json +++ b/debug_adapter_schemas/Java.json @@ -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 -Xmx -D=)." + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ], + "description": "The extra options and system properties for the JVM (e.g., -Xms -Xmx -D=). Can be a single string or an array of strings." }, "encoding": { "type": "string", diff --git a/src/debugger.rs b/src/debugger.rs index 4b46492..d5eded2 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -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, }, }; @@ -27,9 +27,9 @@ struct JavaDebugLaunchConfig { #[serde(skip_serializing_if = "Option::is_none")] main_class: Option, #[serde(skip_serializing_if = "Option::is_none")] - args: Option, + args: Option, #[serde(skip_serializing_if = "Option::is_none")] - vm_args: Option, + vm_args: Option, #[serde(skip_serializing_if = "Option::is_none")] encoding: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/util.rs b/src/util.rs index 152de2e..37d8603 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,5 @@ use regex::Regex; +use serde::{Deserialize, Serialize, Serializer}; use std::{ env::current_dir, fs, @@ -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), +} + +impl Serialize for ArgsStringOrList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + ArgsStringOrList::String(s) => serializer.serialize_str(s), + ArgsStringOrList::List(l) => serializer.serialize_str(&l.join(" ")), + } + } +}