on master help sign in
dap: support arrays as arguments
commit6aa9838ea6c4c4a355796ef6dcc4dd28f2035c38 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 24 Oct 2021, 17:24 (5 years ago) parentd6e8a44
2 files changed+30−7
helix-core/src/syntax.rs+8−1 helix-term/src/commands/dap.rs+22−6
helix-core/src/syntax.rs+8−1
@@ -104,13 +104,20 @@ pub enum DebugConfigCompletion {
104104 Advanced(AdvancedCompletion),
105105}
106106
107+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
108+#[serde(untagged)]
109+pub enum DebugArgumentValue {
110+ String(String),
111+ Array(Vec<String>),
112+}
113+
107114#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
108115#[serde(rename_all = "kebab-case")]
109116pub struct DebugTemplate {
110117 pub name: String,
111118 pub request: String,
112119 pub completion: Vec<DebugConfigCompletion>,
113− pub args: HashMap<String, String>,
120+ pub args: HashMap<String, DebugArgumentValue>,
114121}
115122
116123#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
helix-term/src/commands/dap.rs+22−6
@@ -5,7 +5,10 @@ use crate::{
55 job::Callback,
66 ui::{FilePicker, Prompt, PromptEvent},
77};
8−use helix_core::{syntax::DebugConfigCompletion, Selection};
8+use helix_core::{
9+ syntax::{DebugArgumentValue, DebugConfigCompletion},
10+ Selection,
11+};
912use helix_dap::{self as dap, Client, ThreadId};
1013use helix_lsp::block_on;
1114
@@ -239,13 +242,26 @@ pub fn dap_start_impl(
239242 }
240243 }
241244 // For param #0 replace {0} in args
242− value = value.replace(format!("{{{}}}", i).as_str(), &param);
245+ value = match value {
246+ DebugArgumentValue::String(v) => {
247+ DebugArgumentValue::String(v.replace(format!("{{{}}}", i).as_str(), &param))
248+ }
249+ DebugArgumentValue::Array(arr) => DebugArgumentValue::Array(
250+ arr.iter()
251+ .map(|v| v.replace(format!("{{{}}}", i).as_str(), &param))
252+ .collect(),
253+ ),
254+ };
243255 }
244256
245− if let Ok(integer) = value.parse::<usize>() {
246− args.insert(k, Value::Number(serde_json::Number::from(integer)));
247− } else {
248− args.insert(k, Value::String(value));
257+ if let DebugArgumentValue::String(string) = value {
258+ if let Ok(integer) = string.parse::<usize>() {
259+ args.insert(k, to_value(integer).unwrap());
260+ } else {
261+ args.insert(k, to_value(string).unwrap());
262+ }
263+ } else if let DebugArgumentValue::Array(arr) = value {
264+ args.insert(k, to_value(arr).unwrap());
249265 }
250266 }
251267 }