diff options
author | Dmitry Sharshakov | 2021-10-24 14:24:18 +0000 |
---|---|---|
committer | Dmitry Sharshakov | 2021-10-24 14:24:18 +0000 |
commit | 6aa9838ea6c4c4a355796ef6dcc4dd28f2035c38 (patch) | |
tree | 8e701200b8e54aa6dae7ccf67b76beabd4991f23 | |
parent | d6e8a44d8510b2ae75d660a5f260d97e6dc7e797 (diff) |
dap: support arrays as arguments
-rw-r--r-- | helix-core/src/syntax.rs | 9 | ||||
-rw-r--r-- | helix-term/src/commands/dap.rs | 28 |
2 files changed, 30 insertions, 7 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 822d3181..441802a5 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -105,12 +105,19 @@ pub enum DebugConfigCompletion { } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(untagged)] +pub enum DebugArgumentValue { + String(String), + Array(Vec<String>), +} + +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] pub struct DebugTemplate { pub name: String, pub request: String, pub completion: Vec<DebugConfigCompletion>, - pub args: HashMap<String, String>, + pub args: HashMap<String, DebugArgumentValue>, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 6df9be22..566730e1 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -5,7 +5,10 @@ use crate::{ job::Callback, ui::{FilePicker, Prompt, PromptEvent}, }; -use helix_core::{syntax::DebugConfigCompletion, Selection}; +use helix_core::{ + syntax::{DebugArgumentValue, DebugConfigCompletion}, + Selection, +}; use helix_dap::{self as dap, Client, ThreadId}; use helix_lsp::block_on; @@ -239,13 +242,26 @@ pub fn dap_start_impl( } } // For param #0 replace {0} in args - value = value.replace(format!("{{{}}}", i).as_str(), ¶m); + value = match value { + DebugArgumentValue::String(v) => { + DebugArgumentValue::String(v.replace(format!("{{{}}}", i).as_str(), ¶m)) + } + DebugArgumentValue::Array(arr) => DebugArgumentValue::Array( + arr.iter() + .map(|v| v.replace(format!("{{{}}}", i).as_str(), ¶m)) + .collect(), + ), + }; } - if let Ok(integer) = value.parse::<usize>() { - args.insert(k, Value::Number(serde_json::Number::from(integer))); - } else { - args.insert(k, Value::String(value)); + if let DebugArgumentValue::String(string) = value { + if let Ok(integer) = string.parse::<usize>() { + args.insert(k, to_value(integer).unwrap()); + } else { + args.insert(k, to_value(string).unwrap()); + } + } else if let DebugArgumentValue::Array(arr) = value { + args.insert(k, to_value(arr).unwrap()); } } } |