on master help sign in
dap: Clean up dap_start_impl, no need to clone arg keys
3042ff3Blaž Hrastnik
helix-term/src/commands/dap.rs+12−14
@@ -207,27 +207,26 @@ pub fn dap_start_impl(
207 debugger.quirks = config.quirks.clone();
207 debugger.quirks = config.quirks.clone();
208
208
209 // TODO: avoid refetching all of this... pass a config in
209 // TODO: avoid refetching all of this... pass a config in
210− let start_config = match name {
210+ let template = match name {
211 Some(name) => config.templates.iter().find(|t| t.name == name),
211 Some(name) => config.templates.iter().find(|t| t.name == name),
212 None => config.templates.get(0),
212 None => config.templates.get(0),
213 };
213 };
214− let start_config = match start_config {
214+ let template = match template {
215− Some(c) => c,
215+ Some(template) => template,
216 None => {
216 None => {
217 editor.set_error("No debug config with given name".to_string());
217 editor.set_error("No debug config with given name".to_string());
218 return;
218 return;
219 }
219 }
220 };
220 };
221
221
222− let template = start_config.args.clone();
223− let mut args: HashMap<String, Value> = HashMap::new();
222+ let mut args: HashMap<&str, Value> = HashMap::new();
224
223
225 if let Some(params) = params {
224 if let Some(params) = params {
226− for (k, t) in template {
225+ for (k, t) in &template.args {
227− let mut value = t;
226+ let mut value = t.clone();
228 for (i, x) in params.iter().enumerate() {
227 for (i, x) in params.iter().enumerate() {
229 let mut param = x.to_string();
228 let mut param = x.to_string();
230− if let Some(DebugConfigCompletion::Advanced(cfg)) = start_config.completion.get(i) {
229+ if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) {
231 if cfg.completion == Some("filename".to_owned())
230 if cfg.completion == Some("filename".to_owned())
232 || cfg.completion == Some("directory".to_owned())
231 || cfg.completion == Some("directory".to_owned())
233 {
232 {
@@ -238,14 +237,13 @@ pub fn dap_start_impl(
238 }
237 }
239 }
238 }
240 // For param #0 replace {0} in args
239 // For param #0 replace {0} in args
240+ let pattern = format!("{{{}}}", i);
241 value = match value {
241 value = match value {
242 DebugArgumentValue::String(v) => {
242 DebugArgumentValue::String(v) => {
243− DebugArgumentValue::String(v.replace(format!("{{{}}}", i).as_str(), &param))
243+ DebugArgumentValue::String(v.replace(&pattern, &param))
244 }
244 }
245 DebugArgumentValue::Array(arr) => DebugArgumentValue::Array(
245 DebugArgumentValue::Array(arr) => DebugArgumentValue::Array(
246− arr.iter()
247− .map(|v| v.replace(format!("{{{}}}", i).as_str(), &param))
246+ arr.iter().map(|v| v.replace(&pattern, &param)).collect(),
248− .collect(),
249 ),
247 ),
250 };
248 };
251 }
249 }
@@ -264,7 +262,7 @@ pub fn dap_start_impl(
264
262
265 let args = to_value(args).unwrap();
263 let args = to_value(args).unwrap();
266
264
267− let result = match &start_config.request[..] {
265+ let result = match &template.request[..] {
268 "launch" => block_on(debugger.launch(args)),
266 "launch" => block_on(debugger.launch(args)),
269 "attach" => block_on(debugger.attach(args)),
267 "attach" => block_on(debugger.attach(args)),
270 _ => {
268 _ => {
@@ -273,7 +271,7 @@ pub fn dap_start_impl(
273 }
271 }
274 };
272 };
275 if let Err(e) = result {
273 if let Err(e) = result {
276− let msg = format!("Failed {} target: {}", start_config.request, e);
274+ let msg = format!("Failed {} target: {}", template.request, e);
277 editor.set_error(msg);
275 editor.set_error(msg);
278 return;
276 return;
279 }
277 }