on master help sign in
Support templates in debug configurations
commitb001008a698881991d14f28c6f8980c7d83ce385 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateTue 24 Aug 2021, 20:04 (5 years ago) parent31212e1
3 files changed+27−8
helix-dap/src/types.rs+1−1 helix-term/src/commands.rs+24−5 languages.toml+2−2
helix-dap/src/types.rs+1−1
@@ -7,7 +7,7 @@ use std::{collections::HashMap, path::PathBuf};
77pub struct DebugTemplate {
88 pub name: String,
99 pub request: String,
10− pub args: HashMap<String, Value>,
10+ pub args: HashMap<String, String>,
1111}
1212
1313#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
helix-term/src/commands.rs+24−5
@@ -2027,8 +2027,12 @@ mod cmd {
20272027 args: &[&str],
20282028 _event: PromptEvent,
20292029 ) -> anyhow::Result<()> {
2030− dap_start_impl(&mut cx.editor, args.get(0).map(|name| name.to_string()));
2031− // TODO templating
2030+ let mut args = args.to_owned();
2031+ let name = match args.len() {
2032+ 0 => None,
2033+ _ => Some(args.remove(0)),
2034+ };
2035+ dap_start_impl(&mut cx.editor, name, Some(args));
20322036 Ok(())
20332037 }
20342038
@@ -4402,7 +4406,7 @@ fn suspend(_cx: &mut Context) {
44024406}
44034407
44044408// DAP
4405−fn dap_start_impl(editor: &mut Editor, name: Option<String>) {
4409+fn dap_start_impl(editor: &mut Editor, name: Option<&str>, params: Option<Vec<&str>>) {
44064410 use helix_dap::Client;
44074411 use helix_lsp::block_on;
44084412 use serde_json::to_value;
@@ -4449,7 +4453,22 @@ fn dap_start_impl(editor: &mut Editor, name: Option<String>) {
44494453 }
44504454 };
44514455
4452− let args = to_value(start_config.args.clone()).unwrap();
4456+ let template = start_config.args.clone();
4457+ let mut args = HashMap::new();
4458+
4459+ if let Some(params) = params {
4460+ for (k, t) in template {
4461+ let mut value = t;
4462+ for (i, x) in params.iter().enumerate() {
4463+ // For param #0 replace {0} in args
4464+ value = value.replace(format!("{{{}}}", i).as_str(), x);
4465+ }
4466+
4467+ args.insert(k, value);
4468+ }
4469+ }
4470+
4471+ let args = to_value(args).unwrap();
44534472
44544473 // TODO gracefully handle errors from debugger
44554474 match &start_config.request[..] {
@@ -4470,7 +4489,7 @@ fn dap_start_impl(editor: &mut Editor, name: Option<String>) {
44704489fn dap_start(cx: &mut Context) {
44714490 // TODO: check that first config does not have templates
44724491 // which cannot be handled with a shortcut
4473− dap_start_impl(&mut cx.editor, None);
4492+ dap_start_impl(&mut cx.editor, None, None);
44744493}
44754494
44764495fn dap_toggle_breakpoint(cx: &mut Context) {
languages.toml+2−2
@@ -30,7 +30,7 @@ port-arg = "-p {}"
3030[[language.debugger.templates]]
3131name = "binary"
3232request = "launch"
33−args = { console = "internalConsole", program = "target/debug/rustdebug" }
33+args = { console = "internalConsole", program = "{0}" }
3434
3535[[language]]
3636name = "toml"
@@ -150,7 +150,7 @@ args = { mode = "exec", program = "./main" }
150150[[language.debugger.templates]]
151151name = "test"
152152request = "launch"
153−args = { mode = "test", program = "." }
153+args = { mode = "test", program = "{0}" }
154154
155155[[language]]
156156name = "javascript"