From 7ae9937f2d62f7a7777657cb82ef70c81c502307 Mon Sep 17 00:00:00 2001 From: Vitaly Slobodin Date: Sat, 28 Jun 2025 08:12:29 +0200 Subject: [PATCH] feat(rdbg): support attach requests for `rdbg` debugger Implement support for attach debugging requests in the Ruby debugger. Previously, attach requests were unsupported and would return an error. Now, we support the default `rdbg` configuration: ```json { "label": "Attach to Rails server", "adapter": "rdbg", "request": "attach", "cwd": "$ZED_WORKTREE_ROOT", "env": { "RUBY_DEBUG_PORT": "52203" } } ``` --- src/ruby.rs | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/src/ruby.rs b/src/ruby.rs index 616df31..de1a4b0 100644 --- a/src/ruby.rs +++ b/src/ruby.rs @@ -192,18 +192,25 @@ impl zed::Extension for RubyExtension { arguments.push(format!("--port={}", connection.port)); } - if let Some(script) = &ruby_config.script { - arguments.push(script.clone()); - } else if let Some(command) = &ruby_config.command { - arguments.push("--command".to_string()); - arguments.push(command.clone()); - } else if let Some(command_or_script) = &ruby_config.script_or_command { - if worktree.which(command_or_script).is_some() { - arguments.push("--command".to_string()); + match self.dap_request_kind(adapter_name, configuration.clone())? { + StartDebuggingRequestArgumentsRequest::Launch => { + if let Some(script) = &ruby_config.script { + arguments.push(script.clone()); + } else if let Some(command) = &ruby_config.command { + arguments.push("--command".to_string()); + arguments.push(command.clone()); + } else if let Some(command_or_script) = &ruby_config.script_or_command { + if worktree.which(command_or_script).is_some() { + arguments.push("--command".to_string()); + } + arguments.push(command_or_script.clone()); + } else { + return Err("Ruby debug config must have 'script' or 'command' args".into()); + } + } + StartDebuggingRequestArgumentsRequest::Attach => { + // Do nothing } - arguments.push(command_or_script.clone()); - } else { - return Err("Ruby debug config must have 'script' or 'command' args".into()); } if let Some(configuration) = configuration.as_object_mut() { @@ -276,7 +283,28 @@ impl zed::Extension for RubyExtension { build: None, }) } - DebugRequest::Attach(_) => Err("Attach requests are unsupported".into()), + DebugRequest::Attach(_) => { + let config = RubyDebugConfig { + script_or_command: None, + script: None, + command: None, + args: vec![], + env: Default::default(), + cwd: None, + }; + + let config = serde_json::to_value(config) + .map_err(|e| e.to_string())? + .to_string(); + + Ok(DebugScenario { + adapter: zed_scenario.adapter, + label: zed_scenario.label, + config, + tcp_connection: None, + build: None, + }) + } } } }