From f86f350d5d3d30c49224ef696bac1d624930d184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Mon, 6 May 2024 17:37:04 +0200 Subject: [PATCH] Debugger template: allow missing or empty completion list (#10332) It can be convenient to define project specific debugger templates, some of which might not necessitate prompting the user to define completion. This commit makes completion optional for debugger templates and starts the dap immediately if undefined or empty. --- helix-core/src/syntax.rs | 1 + helix-term/src/commands/dap.rs | 60 +++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 3cf818f60..bbea9bbe7 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -510,6 +510,7 @@ pub enum DebugArgumentValue { pub struct DebugTemplate { pub name: String, pub request: String, + #[serde(default)] pub completion: Vec, pub args: HashMap, } diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index eda94c44f..0e50377ac 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -172,9 +172,9 @@ pub fn dap_start_impl( let mut args: HashMap<&str, Value> = HashMap::new(); - if let Some(params) = params { - for (k, t) in &template.args { - let mut value = t.clone(); + for (k, t) in &template.args { + let mut value = t.clone(); + if let Some(ref params) = params { for (i, x) in params.iter().enumerate() { let mut param = x.to_string(); if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) { @@ -198,22 +198,22 @@ pub fn dap_start_impl( DebugArgumentValue::Boolean(_) => value, }; } + } - match value { - DebugArgumentValue::String(string) => { - if let Ok(integer) = string.parse::() { - args.insert(k, to_value(integer).unwrap()); - } else { - args.insert(k, to_value(string).unwrap()); - } - } - DebugArgumentValue::Array(arr) => { - args.insert(k, to_value(arr).unwrap()); - } - DebugArgumentValue::Boolean(bool) => { - args.insert(k, to_value(bool).unwrap()); + match value { + DebugArgumentValue::String(string) => { + if let Ok(integer) = string.parse::() { + args.insert(k, to_value(integer).unwrap()); + } else { + args.insert(k, to_value(string).unwrap()); } } + DebugArgumentValue::Array(arr) => { + args.insert(k, to_value(arr).unwrap()); + } + DebugArgumentValue::Boolean(bool) => { + args.insert(k, to_value(bool).unwrap()); + } } } @@ -272,17 +272,23 @@ pub fn dap_launch(cx: &mut Context) { templates, (), |cx, template, _action| { - let completions = template.completion.clone(); - let name = template.name.clone(); - let callback = Box::pin(async move { - let call: Callback = - Callback::EditorCompositor(Box::new(move |_editor, compositor| { - let prompt = debug_parameter_prompt(completions, name, Vec::new()); - compositor.push(Box::new(prompt)); - })); - Ok(call) - }); - cx.jobs.callback(callback); + if template.completion.is_empty() { + if let Err(err) = dap_start_impl(cx, Some(&template.name), None, None) { + cx.editor.set_error(err.to_string()); + } + } else { + let completions = template.completion.clone(); + let name = template.name.clone(); + let callback = Box::pin(async move { + let call: Callback = + Callback::EditorCompositor(Box::new(move |_editor, compositor| { + let prompt = debug_parameter_prompt(completions, name, Vec::new()); + compositor.push(Box::new(prompt)); + })); + Ok(call) + }); + cx.jobs.callback(callback); + } }, )))); }