dap: Clean up dap_start_impl, no need to clone arg keys

imgbot
Blaž Hrastnik 3 years ago
parent 9963a5614d
commit 3042ff3e5a

@ -207,27 +207,26 @@ pub fn dap_start_impl(
debugger.quirks = config.quirks.clone(); debugger.quirks = config.quirks.clone();
// TODO: avoid refetching all of this... pass a config in // TODO: avoid refetching all of this... pass a config in
let start_config = match name { let template = match name {
Some(name) => config.templates.iter().find(|t| t.name == name), Some(name) => config.templates.iter().find(|t| t.name == name),
None => config.templates.get(0), None => config.templates.get(0),
}; };
let start_config = match start_config { let template = match template {
Some(c) => c, Some(template) => template,
None => { None => {
editor.set_error("No debug config with given name".to_string()); editor.set_error("No debug config with given name".to_string());
return; return;
} }
}; };
let template = start_config.args.clone(); let mut args: HashMap<&str, Value> = HashMap::new();
let mut args: HashMap<String, Value> = HashMap::new();
if let Some(params) = params { if let Some(params) = params {
for (k, t) in template { for (k, t) in &template.args {
let mut value = t; let mut value = t.clone();
for (i, x) in params.iter().enumerate() { for (i, x) in params.iter().enumerate() {
let mut param = x.to_string(); let mut param = x.to_string();
if let Some(DebugConfigCompletion::Advanced(cfg)) = start_config.completion.get(i) { if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) {
if cfg.completion == Some("filename".to_owned()) if cfg.completion == Some("filename".to_owned())
|| cfg.completion == Some("directory".to_owned()) || cfg.completion == Some("directory".to_owned())
{ {
@ -238,14 +237,13 @@ pub fn dap_start_impl(
} }
} }
// For param #0 replace {0} in args // For param #0 replace {0} in args
let pattern = format!("{{{}}}", i);
value = match value { value = match value {
DebugArgumentValue::String(v) => { DebugArgumentValue::String(v) => {
DebugArgumentValue::String(v.replace(format!("{{{}}}", i).as_str(), &param)) DebugArgumentValue::String(v.replace(&pattern, &param))
} }
DebugArgumentValue::Array(arr) => DebugArgumentValue::Array( DebugArgumentValue::Array(arr) => DebugArgumentValue::Array(
arr.iter() arr.iter().map(|v| v.replace(&pattern, &param)).collect(),
.map(|v| v.replace(format!("{{{}}}", i).as_str(), &param))
.collect(),
), ),
}; };
} }
@ -264,7 +262,7 @@ pub fn dap_start_impl(
let args = to_value(args).unwrap(); let args = to_value(args).unwrap();
let result = match &start_config.request[..] { let result = match &template.request[..] {
"launch" => block_on(debugger.launch(args)), "launch" => block_on(debugger.launch(args)),
"attach" => block_on(debugger.attach(args)), "attach" => block_on(debugger.attach(args)),
_ => { _ => {
@ -273,7 +271,7 @@ pub fn dap_start_impl(
} }
}; };
if let Err(e) = result { if let Err(e) = result {
let msg = format!("Failed {} target: {}", start_config.request, e); let msg = format!("Failed {} target: {}", template.request, e);
editor.set_error(msg); editor.set_error(msg);
return; return;
} }

Loading…
Cancel
Save