on master help sign in
dap: Simplify debug_parameter_prompt
c39d9f4Blaž Hrastnik
helix-term/src/commands/dap.rs+11−17
@@ -227,9 +227,7 @@ pub fn dap_start_impl(
227 for (i, x) in params.iter().enumerate() {
227 for (i, x) in params.iter().enumerate() {
228 let mut param = x.to_string();
228 let mut param = x.to_string();
229 if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) {
229 if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) {
230− if cfg.completion == Some("filename".to_owned())
230+ if matches!(cfg.completion.as_deref(), Some("filename" | "directory")) {
231− || cfg.completion == Some("directory".to_owned())
232− {
233 param = std::fs::canonicalize(x)
231 param = std::fs::canonicalize(x)
234 .ok()
232 .ok()
235 .and_then(|pb| pb.into_os_string().into_string().ok())
233 .and_then(|pb| pb.into_os_string().into_string().ok())
@@ -330,27 +328,23 @@ fn debug_parameter_prompt(
330 config_name: String,
328 config_name: String,
331 mut params: Vec<String>,
329 mut params: Vec<String>,
332) -> Prompt {
330) -> Prompt {
333− let i = params.len();
334− let completion = completions.get(i).unwrap();
331+ let completion = completions.get(params.len()).unwrap();
335 let field_type = if let DebugConfigCompletion::Advanced(cfg) = completion {
332 let field_type = if let DebugConfigCompletion::Advanced(cfg) = completion {
336− cfg.completion.clone().unwrap_or_else(|| "".to_owned())
333+ cfg.completion.as_deref().unwrap_or("")
337 } else {
334 } else {
338− "".to_owned()
335+ ""
339 };
336 };
340 let name = match completion {
337 let name = match completion {
341− DebugConfigCompletion::Advanced(cfg) => {
338+ DebugConfigCompletion::Advanced(cfg) => cfg.name.as_deref().unwrap_or(field_type),
342− cfg.name.clone().unwrap_or_else(|| field_type.to_owned())
343− }
344− DebugConfigCompletion::Named(name) => name.clone(),
339+ DebugConfigCompletion::Named(name) => name.as_str(),
345 };
340 };
346 let default_val = match completion {
341 let default_val = match completion {
347− DebugConfigCompletion::Advanced(cfg) => {
342+ DebugConfigCompletion::Advanced(cfg) => cfg.default.as_deref().unwrap_or(""),
348− cfg.default.clone().unwrap_or_else(|| "".to_owned())
343+ _ => "",
349− }
344+ }
350− _ => "".to_owned(),
345+ .to_owned();
351− };
352
346
353− let completer = match &field_type[..] {
347+ let completer = match field_type {
354 "filename" => ui::completers::filename,
348 "filename" => ui::completers::filename,
355 "directory" => ui::completers::directory,
349 "directory" => ui::completers::directory,
356 _ => |_input: &str| Vec::new(),
350 _ => |_input: &str| Vec::new(),