on master help sign in
Support templates in debug configurations
b001008Dmitry Sharshakov
helix-dap/src/types.rs+1−1
@@ -7,7 +7,7 @@ use std::{collections::HashMap, path::PathBuf};
7pub struct DebugTemplate {
7pub struct DebugTemplate {
8 pub name: String,
8 pub name: String,
9 pub request: String,
9 pub request: String,
10− pub args: HashMap<String, Value>,
10+ pub args: HashMap<String, String>,
11}
11}
12
12
13#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
13#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
helix-term/src/commands.rs+24−5
@@ -2027,8 +2027,12 @@ mod cmd {
2027 args: &[&str],
2027 args: &[&str],
2028 _event: PromptEvent,
2028 _event: PromptEvent,
2029 ) -> anyhow::Result<()> {
2029 ) -> anyhow::Result<()> {
2030+ let mut args = args.to_owned();
2031+ let name = match args.len() {
2032+ 0 => None,
2033+ _ => Some(args.remove(0)),
2034+ };
2030− dap_start_impl(&mut cx.editor, args.get(0).map(|name| name.to_string()));
2035+ dap_start_impl(&mut cx.editor, name, Some(args));
2031− // TODO templating
2032 Ok(())
2036 Ok(())
2033 }
2037 }
2034
2038
@@ -4402,7 +4406,7 @@ fn suspend(_cx: &mut Context) {
4402}
4406}
4403
4407
4404// DAP
4408// 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>>) {
4406 use helix_dap::Client;
4410 use helix_dap::Client;
4407 use helix_lsp::block_on;
4411 use helix_lsp::block_on;
4408 use serde_json::to_value;
4412 use serde_json::to_value;
@@ -4449,7 +4453,22 @@ fn dap_start_impl(editor: &mut Editor, name: Option<String>) {
4449 }
4453 }
4450 };
4454 };
4451
4455
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();
4453
4472
4454 // TODO gracefully handle errors from debugger
4473 // TODO gracefully handle errors from debugger
4455 match &start_config.request[..] {
4474 match &start_config.request[..] {
@@ -4470,7 +4489,7 @@ fn dap_start_impl(editor: &mut Editor, name: Option<String>) {
4470fn dap_start(cx: &mut Context) {
4489fn dap_start(cx: &mut Context) {
4471 // TODO: check that first config does not have templates
4490 // TODO: check that first config does not have templates
4472 // which cannot be handled with a shortcut
4491 // which cannot be handled with a shortcut
4473− dap_start_impl(&mut cx.editor, None);
4492+ dap_start_impl(&mut cx.editor, None, None);
4474}
4493}
4475
4494
4476fn dap_toggle_breakpoint(cx: &mut Context) {
4495fn dap_toggle_breakpoint(cx: &mut Context) {
languages.toml+2−2
@@ -30,7 +30,7 @@ port-arg = "-p {}"
30[[language.debugger.templates]]
30[[language.debugger.templates]]
31name = "binary"
31name = "binary"
32request = "launch"
32request = "launch"
33−args = { console = "internalConsole", program = "target/debug/rustdebug" }
33+args = { console = "internalConsole", program = "{0}" }
34
34
35[[language]]
35[[language]]
36name = "toml"
36name = "toml"
@@ -150,7 +150,7 @@ args = { mode = "exec", program = "./main" }
150[[language.debugger.templates]]
150[[language.debugger.templates]]
151name = "test"
151name = "test"
152request = "launch"
152request = "launch"
153−args = { mode = "test", program = "." }
153+args = { mode = "test", program = "{0}" }
154
154
155[[language]]
155[[language]]
156name = "javascript"
156name = "javascript"