diff options
author | Dmitry Sharshakov | 2021-08-24 17:04:14 +0000 |
---|---|---|
committer | Dmitry Sharshakov | 2021-08-24 17:04:14 +0000 |
commit | b001008a698881991d14f28c6f8980c7d83ce385 (patch) | |
tree | a31b2ab8d72c99502fd74de8e90e4001946a0126 | |
parent | 31212e133dd00900fc1da6eeff97c6691212d789 (diff) |
Support templates in debug configurations
-rw-r--r-- | helix-dap/src/types.rs | 2 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 29 | ||||
-rw-r--r-- | languages.toml | 4 |
3 files changed, 27 insertions, 8 deletions
diff --git a/helix-dap/src/types.rs b/helix-dap/src/types.rs index dfc25b1b..03f22e4d 100644 --- a/helix-dap/src/types.rs +++ b/helix-dap/src/types.rs @@ -7,7 +7,7 @@ use std::{collections::HashMap, path::PathBuf}; pub struct DebugTemplate { pub name: String, pub request: String, - pub args: HashMap<String, Value>, + pub args: HashMap<String, String>, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b48681cc..7d3fafe6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2027,8 +2027,12 @@ mod cmd { args: &[&str], _event: PromptEvent, ) -> anyhow::Result<()> { - dap_start_impl(&mut cx.editor, args.get(0).map(|name| name.to_string())); - // TODO templating + let mut args = args.to_owned(); + let name = match args.len() { + 0 => None, + _ => Some(args.remove(0)), + }; + dap_start_impl(&mut cx.editor, name, Some(args)); Ok(()) } @@ -4402,7 +4406,7 @@ fn suspend(_cx: &mut Context) { } // DAP -fn dap_start_impl(editor: &mut Editor, name: Option<String>) { +fn dap_start_impl(editor: &mut Editor, name: Option<&str>, params: Option<Vec<&str>>) { use helix_dap::Client; use helix_lsp::block_on; use serde_json::to_value; @@ -4449,7 +4453,22 @@ fn dap_start_impl(editor: &mut Editor, name: Option<String>) { } }; - let args = to_value(start_config.args.clone()).unwrap(); + let template = start_config.args.clone(); + let mut args = HashMap::new(); + + if let Some(params) = params { + for (k, t) in template { + let mut value = t; + for (i, x) in params.iter().enumerate() { + // For param #0 replace {0} in args + value = value.replace(format!("{{{}}}", i).as_str(), x); + } + + args.insert(k, value); + } + } + + let args = to_value(args).unwrap(); // TODO gracefully handle errors from debugger match &start_config.request[..] { @@ -4470,7 +4489,7 @@ fn dap_start_impl(editor: &mut Editor, name: Option<String>) { fn dap_start(cx: &mut Context) { // TODO: check that first config does not have templates // which cannot be handled with a shortcut - dap_start_impl(&mut cx.editor, None); + dap_start_impl(&mut cx.editor, None, None); } fn dap_toggle_breakpoint(cx: &mut Context) { diff --git a/languages.toml b/languages.toml index 416aa802..291202c1 100644 --- a/languages.toml +++ b/languages.toml @@ -30,7 +30,7 @@ port-arg = "-p {}" [[language.debugger.templates]] name = "binary" request = "launch" -args = { console = "internalConsole", program = "target/debug/rustdebug" } +args = { console = "internalConsole", program = "{0}" } [[language]] name = "toml" @@ -150,7 +150,7 @@ args = { mode = "exec", program = "./main" } [[language.debugger.templates]] name = "test" request = "launch" -args = { mode = "test", program = "." } +args = { mode = "test", program = "{0}" } [[language]] name = "javascript" |