@@ -1,4 +1,5 @@
11use crate::{
2+ requests::DisconnectArguments,
23 transport::{Payload, Request, Response, Transport},
34 types::*,
45 Error, Result, ThreadId,
@@ -31,6 +32,7 @@ pub struct Client {
3132 _process: Option<Child>,
3233 server_tx: UnboundedSender<Payload>,
3334 request_counter: AtomicU64,
35+ connection_type: Option<ConnectionType>,
3436 pub caps: Option<DebuggerCapabilities>,
3537 // thread_id -> frames
3638 pub stack_frames: HashMap<ThreadId, Vec<StackFrame>>,
@@ -41,6 +43,12 @@ pub struct Client {
4143 pub quirks: DebuggerQuirks,
4244}
4345
46+#[derive(Clone, Copy, Debug)]
47+pub enum ConnectionType {
48+ Launch,
49+ Attach,
50+}
51+
4452impl Client {
4553 // Spawn a process and communicate with it by either TCP or stdio
4654 pub async fn process(
@@ -78,7 +86,7 @@ impl Client {
7886 server_tx,
7987 request_counter: AtomicU64::new(0),
8088 caps: None,
81− //
89+ connection_type: None,
8290 stack_frames: HashMap::new(),
8391 thread_states: HashMap::new(),
8492 thread_id: None,
@@ -207,6 +215,10 @@ impl Client {
207215 self.id
208216 }
209217
218+ pub fn connection_type(&self) -> Option<ConnectionType> {
219+ self.connection_type
220+ }
221+
210222 fn next_request_id(&self) -> u64 {
211223 self.request_counter.fetch_add(1, Ordering::Relaxed)
212224 }
@@ -334,15 +346,21 @@ impl Client {
334346 Ok(())
335347 }
336348
337− pub fn disconnect(&self) -> impl Future<Output = Result<Value>> {
338− self.call::<requests::Disconnect>(())
349+ pub fn disconnect(
350+ &mut self,
351+ args: Option<DisconnectArguments>,
352+ ) -> impl Future<Output = Result<Value>> {
353+ self.connection_type = None;
354+ self.call::<requests::Disconnect>(args)
339355 }
340356
341− pub fn launch(&self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
357+ pub fn launch(&mut self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
358+ self.connection_type = Some(ConnectionType::Launch);
342359 self.call::<requests::Launch>(args)
343360 }
344361
345− pub fn attach(&self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
362+ pub fn attach(&mut self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
363+ self.connection_type = Some(ConnectionType::Attach);
346364 self.call::<requests::Attach>(args)
347365 }
348366