debugger: Add args argument to debugger launch config (#27953)

This also fixes a bug where debug cargo test code actions would debug
all tests in a mod instead of a specific test

Release Notes:

- N/A
This commit is contained in:
Anthony Eid 2025-04-02 15:37:12 -04:00 committed by GitHub
parent 500964a6fa
commit 108ae0b5b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 42 additions and 17 deletions

View file

@ -79,7 +79,7 @@ impl DebugAdapter for GdbDebugAdapter {
json!({"pid": attach_config.process_id})
}
dap::DebugRequestType::Launch(launch_config) => {
json!({"program": launch_config.program, "cwd": launch_config.cwd, "stopOnEntry": config.stop_on_entry})
json!({"program": launch_config.program, "cwd": launch_config.cwd, "stopOnEntry": config.stop_on_entry, "args": launch_config.args.clone()})
}
}
}

View file

@ -94,6 +94,7 @@ impl DebugAdapter for GoDebugAdapter {
"program": launch_config.program,
"cwd": launch_config.cwd,
"stopOnEntry": config.stop_on_entry,
"args": launch_config.args
}),
}
}

View file

@ -135,6 +135,7 @@ impl DebugAdapter for JsDebugAdapter {
}
DebugRequestType::Launch(launch) => {
map.insert("program".into(), launch.program.clone().into());
map.insert("args".into(), launch.args.clone().into());
map.insert(
"cwd".into(),
launch

View file

@ -82,6 +82,7 @@ impl DebugAdapter for LldbDebugAdapter {
}
DebugRequestType::Launch(launch) => {
map.insert("program".into(), launch.program.clone().into());
map.insert("args".into(), launch.args.clone().into());
map.insert(
"cwd".into(),
launch

View file

@ -118,6 +118,7 @@ impl DebugAdapter for PhpDebugAdapter {
json!({
"program": launch_config.program,
"cwd": launch_config.cwd,
"args": launch_config.args,
"stopOnEntry": config.stop_on_entry,
})
}

View file

@ -130,6 +130,7 @@ impl DebugAdapter for PythonDebugAdapter {
DebugRequestType::Launch(launch_config) => {
json!({
"program": launch_config.program,
"args": launch_config.args,
"subProcess": true,
"cwd": launch_config.cwd,
"redirectOutput": true,

View file

@ -156,10 +156,10 @@ impl Render for InertState {
request: DebugRequestType::Launch(LaunchConfig {
program,
cwd: Some(cwd),
args: Default::default(),
}),
tcp_connection: Some(TCPHost::default()),
initialize_args: None,
args: Default::default(),
locator: None,
stop_on_entry: None,
},
@ -322,7 +322,6 @@ impl InertState {
adapter: kind,
request: DebugRequestType::Attach(task::AttachConfig { process_id: None }),
initialize_args: None,
args: Default::default(),
locator: None,
tcp_connection: Some(TCPHost::default()),
stop_on_entry: None,

View file

@ -91,7 +91,6 @@ async fn test_show_attach_modal_and_select_process(
tcp_connection: Some(TCPHost::default()),
locator: None,
stop_on_entry: None,
args: Default::default(),
},
vec![
Candidate {

View file

@ -729,7 +729,12 @@ impl ContextProvider for RustContextProvider {
..TaskTemplate::default()
},
TaskTemplate {
label: "Debug".into(),
label: format!(
"Debug {} {} (package: {})",
RUST_BIN_KIND_TASK_VARIABLE.template_value(),
RUST_BIN_NAME_TASK_VARIABLE.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(),
),
cwd: Some("$ZED_DIRNAME".to_owned()),
command: "cargo".into(),
task_type: TaskType::Debug(task::DebugArgs {

View file

@ -471,7 +471,6 @@ impl DapStore {
initialize_args: config.initialize_args.clone(),
tcp_connection: config.tcp_connection.clone(),
locator: None,
args: Default::default(),
stop_on_entry: config.stop_on_entry,
};

View file

@ -29,7 +29,7 @@ impl DapLocator for CargoLocator {
};
let mut child = Command::new("cargo")
.args(&debug_config.args)
.args(&launch_config.args)
.arg("--message-format=json")
.current_dir(cwd)
.stdout(Stdio::piped())
@ -59,7 +59,30 @@ impl DapLocator for CargoLocator {
};
launch_config.program = executable;
debug_config.args.clear();
let mut test_name = None;
if launch_config
.args
.first()
.map_or(false, |arg| arg == "test")
{
if let Some(package_index) = launch_config
.args
.iter()
.position(|arg| arg == "-p" || arg == "--package")
{
test_name = launch_config
.args
.get(package_index + 2)
.filter(|name| !name.starts_with("--"))
.cloned();
}
}
launch_config.args.clear();
if let Some(test_name) = test_name {
launch_config.args.push(test_name);
}
Ok(())
}
}

View file

@ -225,6 +225,7 @@ impl LocalMode {
DebugRequestType::Launch(task::LaunchConfig {
program: "".to_owned(),
cwd: None,
args: Default::default(),
})
}
dap::StartDebuggingRequestArgumentsRequest::Attach => {

View file

@ -1489,7 +1489,6 @@ impl Project {
initialize_args: None,
tcp_connection: None,
locator: None,
args: Default::default(),
stop_on_entry: None,
};
let caps = caps.unwrap_or(Capabilities {

View file

@ -52,6 +52,8 @@ pub struct LaunchConfig {
pub program: String,
/// The current working directory of your project
pub cwd: Option<PathBuf>,
/// Args to pass to a debuggee
pub args: Vec<String>,
}
/// Represents the type that will determine which request to call on the debug adapter
@ -104,8 +106,6 @@ pub struct DebugAdapterConfig {
pub tcp_connection: Option<TCPHost>,
/// What Locator to use to configure the debug task
pub locator: Option<String>,
/// Args to pass to a debug adapter (only used in locator right now)
pub args: Vec<String>,
/// Whether to tell the debug adapter to stop on entry
pub stop_on_entry: Option<bool>,
}
@ -119,7 +119,6 @@ impl From<DebugTaskDefinition> for DebugAdapterConfig {
initialize_args: def.initialize_args,
tcp_connection: def.tcp_connection,
locator: def.locator,
args: def.args,
stop_on_entry: def.stop_on_entry,
}
}
@ -140,7 +139,6 @@ impl TryFrom<DebugAdapterConfig> for DebugTaskDefinition {
initialize_args: def.initialize_args,
tcp_connection: def.tcp_connection,
locator: def.locator,
args: def.args,
stop_on_entry: def.stop_on_entry,
})
}
@ -217,9 +215,6 @@ pub struct DebugTaskDefinition {
/// Locator to use
/// -- cargo
pub locator: Option<String>,
/// Args to pass to a debug adapter (only used in locator right now)
#[serde(skip)]
pub args: Vec<String>,
/// Whether to tell the debug adapter to stop on entry
pub stop_on_entry: Option<bool>,
}

View file

@ -134,6 +134,7 @@ impl ResolvedTask {
DebugRequestType::Launch(LaunchConfig {
program: resolved.command.clone(),
cwd: resolved.cwd.clone(),
args,
})
}
crate::task_template::DebugArgsRequest::Attach(attach_config) => {
@ -142,7 +143,6 @@ impl ResolvedTask {
}),
initialize_args: debug_args.initialize_args,
tcp_connection: debug_args.tcp_connection,
args,
locator: debug_args.locator.clone(),
stop_on_entry: debug_args.stop_on_entry,
})