From 6bb653f820998a9a33db3dabf815a761b1c97bfa Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Fri, 13 Aug 2021 20:24:27 +0300 Subject: [PATCH] dap: move launch request argumets outside of client --- helix-dap/examples/dap-basic.rs | 16 +++++++++++++++- helix-dap/src/client.rs | 18 ++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/helix-dap/examples/dap-basic.rs b/helix-dap/examples/dap-basic.rs index 2e4ff2b19..35664458d 100644 --- a/helix-dap/examples/dap-basic.rs +++ b/helix-dap/examples/dap-basic.rs @@ -1,4 +1,12 @@ use helix_dap::{Client, Result, SourceBreakpoint}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +struct LaunchArguments { + mode: String, + program: String, +} #[tokio::main] pub async fn main() -> Result<()> { @@ -19,9 +27,15 @@ pub async fn main() -> Result<()> { println!("init: {:?}", client.initialize("go".to_owned()).await); println!("caps: {:#?}", client.capabilities()); + + let args = LaunchArguments { + mode: "exec".to_owned(), + program: "/tmp/godebug/main".to_owned(), + }; + println!( "launch: {:?}", - client.launch("/tmp/godebug/main".to_owned()).await + client.launch(serde_json::to_value(args)?).await ); println!( diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 41e7dca63..7971dc54d 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -45,14 +45,6 @@ struct InitializeArguments { supports_invalidated_event: bool, } -// TODO: split out, as it's a debugger-specific payload not covered by standard -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -struct LaunchArguments { - mode: String, - program: String, -} - #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Checksum { @@ -380,14 +372,8 @@ impl Client { Ok(()) } - pub async fn launch(&mut self, executable: String) -> Result<()> { - let args = LaunchArguments { - mode: "exec".to_owned(), - program: executable, - }; - - self.request("launch".to_owned(), to_value(args).ok()) - .await?; + pub async fn launch(&mut self, args: Value) -> Result<()> { + self.request("launch".to_owned(), Some(args)).await?; match self .server_rx