@@ -176,10 +176,6 @@ impl zed::Extension for RubyExtension {
176
176
. map_err ( |e| format ! ( "`config` is not a valid rdbg config: {e}" ) ) ?;
177
177
let mut arguments = vec ! [ ] ;
178
178
179
- if !ruby_config. env . contains_key ( "RUBY_DEBUG_OPEN" ) {
180
- arguments. push ( "--open" . to_string ( ) ) ;
181
- }
182
-
183
179
if let Some ( host) = ruby_config. env . get ( "RUBY_DEBUG_HOST" ) {
184
180
connection. host = host
185
181
. parse :: < std:: net:: Ipv4Addr > ( )
@@ -197,36 +193,41 @@ impl zed::Extension for RubyExtension {
197
193
arguments. push ( format ! ( "--port={}" , connection. port) ) ;
198
194
}
199
195
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 {
201
198
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 ( ) )
204
206
} else if let Some ( command) = & ruby_config. command {
205
- arguments . extend ( [ "--command" . into ( ) , "--" . into ( ) , command. clone ( ) ] ) ;
207
+ ( true , command. clone ( ) )
206
208
} 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
+ )
216
213
} 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 ( ) ) ;
218
222
}
223
+ arguments. push ( program) ;
224
+ arguments. push ( "--" . to_string ( ) ) ;
225
+ arguments. extend ( ruby_config. args ) ;
219
226
}
220
227
StartDebuggingRequestArgumentsRequest :: Attach => {
221
- // Do nothing
228
+ arguments . push ( "--attach" . to_string ( ) ) ;
222
229
}
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
+ } ;
230
231
231
232
if use_bundler {
232
233
arguments. splice ( 0 ..0 , vec ! [ "exec" . to_string( ) , "rdbg" . to_string( ) ] ) ;
@@ -240,7 +241,7 @@ impl zed::Extension for RubyExtension {
240
241
envs : ruby_config. env . into_iter ( ) . collect ( ) ,
241
242
request_args : StartDebuggingRequestArguments {
242
243
configuration : configuration. to_string ( ) ,
243
- request : StartDebuggingRequestArgumentsRequest :: Launch ,
244
+ request : request_type ,
244
245
} ,
245
246
} )
246
247
}
@@ -332,7 +333,7 @@ impl zed::Extension for RubyExtension {
332
333
script : None ,
333
334
command : Some ( build_task. command ) ,
334
335
args : build_task. args ,
335
- env : HashMap :: from_iter ( build_task. env ) ,
336
+ env : build_task. env . into_iter ( ) . collect ( ) ,
336
337
cwd : build_task. cwd ,
337
338
} ;
338
339
0 commit comments