Skip to content

Commit 075038f

Browse files
authored
feat(rdbg): support attach requests for rdbg debugger (#124)
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" } } ``` <!-- GitButler Footer Boundary Top --> --- This is **part 2 of 2 in a stack** made with GitButler: - <kbd>&nbsp;2&nbsp;</kbd> #124 👈 - <kbd>&nbsp;1&nbsp;</kbd> #123 <!-- GitButler Footer Boundary Bottom -->
1 parent d937b31 commit 075038f

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

src/ruby.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,25 @@ impl zed::Extension for RubyExtension {
192192
arguments.push(format!("--port={}", connection.port));
193193
}
194194

195-
if let Some(script) = &ruby_config.script {
196-
arguments.push(script.clone());
197-
} else if let Some(command) = &ruby_config.command {
198-
arguments.push("--command".to_string());
199-
arguments.push(command.clone());
200-
} else if let Some(command_or_script) = &ruby_config.script_or_command {
201-
if worktree.which(command_or_script).is_some() {
202-
arguments.push("--command".to_string());
195+
match self.dap_request_kind(adapter_name, configuration.clone())? {
196+
StartDebuggingRequestArgumentsRequest::Launch => {
197+
if let Some(script) = &ruby_config.script {
198+
arguments.push(script.clone());
199+
} else if let Some(command) = &ruby_config.command {
200+
arguments.push("--command".to_string());
201+
arguments.push(command.clone());
202+
} else if let Some(command_or_script) = &ruby_config.script_or_command {
203+
if worktree.which(command_or_script).is_some() {
204+
arguments.push("--command".to_string());
205+
}
206+
arguments.push(command_or_script.clone());
207+
} else {
208+
return Err("Ruby debug config must have 'script' or 'command' args".into());
209+
}
210+
}
211+
StartDebuggingRequestArgumentsRequest::Attach => {
212+
// Do nothing
203213
}
204-
arguments.push(command_or_script.clone());
205-
} else {
206-
return Err("Ruby debug config must have 'script' or 'command' args".into());
207214
}
208215

209216
if let Some(configuration) = configuration.as_object_mut() {
@@ -276,7 +283,28 @@ impl zed::Extension for RubyExtension {
276283
build: None,
277284
})
278285
}
279-
DebugRequest::Attach(_) => Err("Attach requests are unsupported".into()),
286+
DebugRequest::Attach(_) => {
287+
let config = RubyDebugConfig {
288+
script_or_command: None,
289+
script: None,
290+
command: None,
291+
args: vec![],
292+
env: Default::default(),
293+
cwd: None,
294+
};
295+
296+
let config = serde_json::to_value(config)
297+
.map_err(|e| e.to_string())?
298+
.to_string();
299+
300+
Ok(DebugScenario {
301+
adapter: zed_scenario.adapter,
302+
label: zed_scenario.label,
303+
config,
304+
tcp_connection: None,
305+
build: None,
306+
})
307+
}
280308
}
281309
}
282310
}

0 commit comments

Comments
 (0)