Skip to content

Commit f12cabe

Browse files
authored
fix(rdbg): Improve debugger argument handling (#136)
* Add `--stop-at-load` flag for Launch requests * Add proper `--attach` flag for Attach requests * Fix positioning of "--" separators for each command type * Correctly pass request_type to StartDebuggingRequestArguments * Move `--open` argument inside Launch case where it belongs
1 parent d42b759 commit f12cabe

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

src/ruby.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ impl zed::Extension for RubyExtension {
176176
.map_err(|e| format!("`config` is not a valid rdbg config: {e}"))?;
177177
let mut arguments = vec![];
178178

179-
if !ruby_config.env.contains_key("RUBY_DEBUG_OPEN") {
180-
arguments.push("--open".to_string());
181-
}
182-
183179
if let Some(host) = ruby_config.env.get("RUBY_DEBUG_HOST") {
184180
connection.host = host
185181
.parse::<std::net::Ipv4Addr>()
@@ -197,36 +193,41 @@ impl zed::Extension for RubyExtension {
197193
arguments.push(format!("--port={}", connection.port));
198194
}
199195

200-
match self.dap_request_kind(adapter_name, configuration.clone())? {
196+
let request_type = self.dap_request_kind(adapter_name.clone(), configuration.clone())?;
197+
match request_type {
201198
StartDebuggingRequestArgumentsRequest::Launch => {
202-
if let Some(script) = &ruby_config.script {
203-
arguments.push(script.clone());
199+
if !ruby_config.env.contains_key("RUBY_DEBUG_OPEN") {
200+
arguments.push("--open".to_string());
201+
}
202+
arguments.push("--stop-at-load".to_string());
203+
204+
let (is_command, program) = if let Some(script) = &ruby_config.script {
205+
(false, script.clone())
204206
} else if let Some(command) = &ruby_config.command {
205-
arguments.extend(["--command".into(), "--".into(), command.clone()]);
207+
(true, command.clone())
206208
} else if let Some(command_or_script) = &ruby_config.script_or_command {
207-
if worktree.which(command_or_script).is_some() {
208-
arguments.extend([
209-
"--command".into(),
210-
"--".into(),
211-
command_or_script.clone(),
212-
]);
213-
} else {
214-
arguments.push(command_or_script.clone());
215-
}
209+
(
210+
worktree.which(command_or_script).is_some(),
211+
command_or_script.clone(),
212+
)
216213
} else {
217-
return Err("Ruby debug config must have 'script' or 'command' args".into());
214+
return Err(
215+
"Ruby debug config must have 'script', 'command', or 'script_or_command' arg"
216+
.into(),
217+
);
218+
};
219+
220+
if is_command {
221+
arguments.push("--command".to_string());
218222
}
223+
arguments.push(program);
224+
arguments.push("--".to_string());
225+
arguments.extend(ruby_config.args);
219226
}
220227
StartDebuggingRequestArgumentsRequest::Attach => {
221-
// Do nothing
228+
arguments.push("--attach".to_string());
222229
}
223-
}
224-
225-
if !arguments.contains(&"--command".to_string()) {
226-
// Ensure that all arguments are passed after a "--", as required by rdbg.
227-
arguments.push("--".into());
228-
}
229-
arguments.extend(ruby_config.args);
230+
};
230231

231232
if use_bundler {
232233
arguments.splice(0..0, vec!["exec".to_string(), "rdbg".to_string()]);
@@ -240,7 +241,7 @@ impl zed::Extension for RubyExtension {
240241
envs: ruby_config.env.into_iter().collect(),
241242
request_args: StartDebuggingRequestArguments {
242243
configuration: configuration.to_string(),
243-
request: StartDebuggingRequestArgumentsRequest::Launch,
244+
request: request_type,
244245
},
245246
})
246247
}
@@ -332,7 +333,7 @@ impl zed::Extension for RubyExtension {
332333
script: None,
333334
command: Some(build_task.command),
334335
args: build_task.args,
335-
env: HashMap::from_iter(build_task.env),
336+
env: build_task.env.into_iter().collect(),
336337
cwd: build_task.cwd,
337338
};
338339

0 commit comments

Comments
 (0)