on master help sign in
working lldb example
f92fb96Dmitry Sharshakov
helix-dap/examples/dap-lldb.rs+3−3
@@ -57,7 +57,7 @@ pub async fn main() -> Result<()> {
57 "/tmp/cdebug/main.c".to_owned(),
57 "/tmp/cdebug/main.c".to_owned(),
58 vec![SourceBreakpoint {
58 vec![SourceBreakpoint {
59 line: 6,
59 line: 6,
60− column: Some(4),
60+ column: Some(2),
61 condition: None,
61 condition: None,
62 hit_condition: None,
62 hit_condition: None,
63 log_message: None,
63 log_message: None,
@@ -82,7 +82,7 @@ pub async fn main() -> Result<()> {
82 let threads = client.threads().await?;
82 let threads = client.threads().await?;
83 println!("threads: {:#?}", threads);
83 println!("threads: {:#?}", threads);
84 let bt = client
84 let bt = client
85− .stack_trace(threads[2].id)
85+ .stack_trace(threads[0].id)
86 .await
86 .await
87 .expect("expected stack trace");
87 .expect("expected stack trace");
88 println!("stack trace: {:#?}", bt);
88 println!("stack trace: {:#?}", bt);
@@ -93,7 +93,7 @@ pub async fn main() -> Result<()> {
93 println!("scopes: {:#?}", scopes);
93 println!("scopes: {:#?}", scopes);
94 println!(
94 println!(
95 "vars: {:#?}",
95 "vars: {:#?}",
96− client.variables(scopes[1].variables_reference).await
96+ client.variables(scopes[0].variables_reference).await
97 );
97 );
98
98
99 let mut _in = String::new();
99 let mut _in = String::new();
helix-dap/src/client.rs+43−28
@@ -12,6 +12,7 @@ use std::sync::{
12use std::{collections::HashMap, process::Stdio};
12use std::{collections::HashMap, process::Stdio};
13use tokio::{
13use tokio::{
14 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
14 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
15+ join,
15 net::TcpStream,
16 net::TcpStream,
16 process::{Child, Command},
17 process::{Child, Command},
17 sync::{
18 sync::{
@@ -449,7 +450,12 @@ impl Client {
449 self.request_counter.fetch_add(1, Ordering::Relaxed)
450 self.request_counter.fetch_add(1, Ordering::Relaxed)
450 }
451 }
451
452
453+ async fn request(
454+ &self,
455+ command: String,
452− async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
456+ arguments: Option<Value>,
457+ response: bool,
458+ ) -> Result<Option<Response>> {
453 let (callback_rx, mut callback_tx) = channel(1);
459 let (callback_rx, mut callback_tx) = channel(1);
454
460
455 let req = Request {
461 let req = Request {
@@ -464,10 +470,11 @@ impl Client {
464 .send(req)
470 .send(req)
465 .expect("Failed to send request to debugger");
471 .expect("Failed to send request to debugger");
466
472
473+ if response {
467− callback_tx
474+ Ok(Some(callback_tx.recv().await.unwrap()?))
468− .recv()
475+ } else {
469− .await
476+ Ok(None)
470− .expect("Failed to receive response")
477+ }
471 }
478 }
472
479
473 pub fn capabilities(&self) -> &DebuggerCapabilities {
480 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -494,25 +501,25 @@ impl Client {
494 };
501 };
495
502
496 let response = self
503 let response = self
497− .request("initialize".to_owned(), to_value(args).ok())
504+ .request("initialize".to_owned(), to_value(args).ok(), true)
498− .await?;
505+ .await?
506+ .unwrap();
499 self.capabilities = from_value(response.body.unwrap()).ok();
507 self.capabilities = from_value(response.body.unwrap()).ok();
500
508
501 Ok(())
509 Ok(())
502 }
510 }
503
511
504 pub async fn disconnect(&mut self) -> Result<()> {
512 pub async fn disconnect(&mut self) -> Result<()> {
505− self.request("disconnect".to_owned(), None).await?;
513+ self.request("disconnect".to_owned(), None, true).await?;
506 Ok(())
514 Ok(())
507 }
515 }
508
516
509 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
517 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
510 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
518 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
511
519
512− self.request("launch".to_owned(), to_value(args).ok())
520+ let res = self.request("launch".to_owned(), to_value(args).ok(), true);
513− .await?;
514−
515− initialized.recv().await;
521+ let ev = initialized.recv();
522+ join!(res, ev).0?;
516
523
517 Ok(())
524 Ok(())
518 }
525 }
@@ -520,10 +527,9 @@ impl Client {
520 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
527 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
521 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
528 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
522
529
523− self.request("attach".to_owned(), to_value(args).ok())
530+ let res = self.request("attach".to_owned(), to_value(args).ok(), false);
524− .await?;
525−
526− initialized.recv().await;
531+ let ev = initialized.recv();
532+ join!(res, ev).0?;
527
533
528 Ok(())
534 Ok(())
529 }
535 }
@@ -549,15 +555,17 @@ impl Client {
549 };
555 };
550
556
551 let response = self
557 let response = self
552− .request("setBreakpoints".to_owned(), to_value(args).ok())
558+ .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
553− .await?;
559+ .await?
560+ .unwrap();
554 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
561 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
555
562
556 Ok(body.map(|b| b.breakpoints).unwrap())
563 Ok(body.map(|b| b.breakpoints).unwrap())
557 }
564 }
558
565
559 pub async fn configuration_done(&mut self) -> Result<()> {
566 pub async fn configuration_done(&mut self) -> Result<()> {
560− self.request("configurationDone".to_owned(), None).await?;
567+ self.request("configurationDone".to_owned(), None, true)
568+ .await?;
561 Ok(())
569 Ok(())
562 }
570 }
563
571
@@ -565,8 +573,9 @@ impl Client {
565 let args = ContinueArguments { thread_id };
573 let args = ContinueArguments { thread_id };
566
574
567 let response = self
575 let response = self
568− .request("continue".to_owned(), to_value(args).ok())
576+ .request("continue".to_owned(), to_value(args).ok(), true)
569− .await?;
577+ .await?
578+ .unwrap();
570
579
571 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
580 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
572
581
@@ -585,8 +594,9 @@ impl Client {
585 };
594 };
586
595
587 let response = self
596 let response = self
588− .request("stackTrace".to_owned(), to_value(args).ok())
597+ .request("stackTrace".to_owned(), to_value(args).ok(), true)
589− .await?;
598+ .await?
599+ .unwrap();
590
600
591 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
601 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
592
602
@@ -594,7 +604,10 @@ impl Client {
594 }
604 }
595
605
596 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
606 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
607+ let response = self
597− let response = self.request("threads".to_owned(), None).await?;
608+ .request("threads".to_owned(), None, true)
609+ .await?
610+ .unwrap();
598
611
599 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
612 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
600
613
@@ -605,8 +618,9 @@ impl Client {
605 let args = ScopesArguments { frame_id };
618 let args = ScopesArguments { frame_id };
606
619
607 let response = self
620 let response = self
608− .request("scopes".to_owned(), to_value(args).ok())
621+ .request("scopes".to_owned(), to_value(args).ok(), true)
609− .await?;
622+ .await?
623+ .unwrap();
610
624
611 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
625 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
612
626
@@ -623,8 +637,9 @@ impl Client {
623 };
637 };
624
638
625 let response = self
639 let response = self
626− .request("variables".to_owned(), to_value(args).ok())
640+ .request("variables".to_owned(), to_value(args).ok(), true)
627− .await?;
641+ .await?
642+ .unwrap();
628
643
629 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
644 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
630
645