From 5545f8ebb5585c59981f1d09add9bd747b143ba2 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 3 Dec 2021 16:09:28 +0900 Subject: dap: Add RunInTerminal reverse request, support replying to requests --- helix-dap/src/client.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'helix-dap/src/client.rs') diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 7c18ec53..c3840007 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -1,5 +1,5 @@ use crate::{ - transport::{Payload, Request, Transport}, + transport::{Payload, Request, Response, Transport}, types::*, Error, Result, ThreadId, }; @@ -29,7 +29,7 @@ use tokio::{ pub struct Client { id: usize, _process: Option, - server_tx: UnboundedSender, + server_tx: UnboundedSender, request_counter: AtomicU64, pub caps: Option, // thread_id -> frames @@ -234,7 +234,9 @@ impl Client { arguments, }; - server_tx.send(req).map_err(|e| Error::Other(e.into()))?; + server_tx + .send(Payload::Request(req)) + .map_err(|e| Error::Other(e.into()))?; // TODO: specifiable timeout, delay other calls until initialize success timeout(Duration::from_secs(20), callback_rx.recv()) @@ -257,6 +259,40 @@ impl Client { Ok(response) } + pub fn reply( + &self, + request_seq: u64, + command: String, + result: core::result::Result, + ) -> impl Future> { + let server_tx = self.server_tx.clone(); + + async move { + let response = match result { + Ok(result) => Response { + request_seq, + command, + success: true, + message: None, + body: Some(result), + }, + Err(error) => Response { + request_seq, + command, + success: false, + message: Some(error.to_string()), + body: None, + }, + }; + + server_tx + .send(Payload::Response(response)) + .map_err(|e| Error::Other(e.into()))?; + + Ok(()) + } + } + pub fn capabilities(&self) -> &DebuggerCapabilities { self.caps.as_ref().expect("debugger not yet initialized!") } -- cgit v1.2.3-70-g09d2