aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 0b222a2a..b463da2a 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -24,6 +24,7 @@ use helix_lsp::{
};
use insert::*;
use movement::Movement;
+use tokio::sync::{mpsc::Receiver, Mutex};
use crate::{
compositor::{self, Component, Compositor},
@@ -32,8 +33,8 @@ use crate::{
use crate::job::{self, Job, Jobs};
use futures_util::FutureExt;
-use std::num::NonZeroUsize;
use std::{collections::HashMap, fmt, future::Future};
+use std::{num::NonZeroUsize, sync::Arc};
use std::{
borrow::Cow,
@@ -4267,11 +4268,34 @@ fn dap_start(cx: &mut Context) {
let request = debugger.launch(to_value(args).unwrap());
let _ = block_on(request).unwrap();
- // TODO: either await "initialized" or buffer commands until event is received
+ let stopped = block_on(debugger.listen_for_event("stopped".to_owned()));
+ let debugger = Arc::new(Mutex::new(debugger));
+ tokio::spawn(dap_listen_stopped(stopped, Arc::clone(&debugger)));
+ // TODO: either await "initialized" or buffer commands until event is received
cx.editor.debugger = Some(debugger);
}
+async fn dap_listen_stopped(
+ mut stopped: Receiver<helix_dap::Event>,
+ debugger: Arc<Mutex<helix_dap::Client>>,
+) {
+ loop {
+ stopped.recv().await;
+
+ let mut dbg = debugger.lock().await;
+ let main = dbg
+ .threads()
+ .await
+ .ok()
+ .and_then(|threads| threads.get(0).and_then(|x| Some(x.clone())));
+ if let Some(main) = main {
+ let (a, _) = dbg.stack_trace(main.id).await.unwrap();
+ dbg.stack_pointer = a.get(0).and_then(|x| Some(x.clone()));
+ }
+ }
+}
+
fn dap_toggle_breakpoint(cx: &mut Context) {
use helix_lsp::block_on;
@@ -4297,6 +4321,7 @@ fn dap_toggle_breakpoint(cx: &mut Context) {
// we shouldn't really allow editing while debug is running though
if let Some(debugger) = &mut cx.editor.debugger {
+ let mut debugger = block_on(debugger.lock());
let breakpoints = debugger.breakpoints.entry(path.clone()).or_default();
if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
breakpoints.remove(pos);
@@ -4315,6 +4340,7 @@ fn dap_run(cx: &mut Context) {
use helix_lsp::block_on;
if let Some(debugger) = &mut cx.editor.debugger {
+ let mut debugger = block_on(debugger.lock());
let request = debugger.configuration_done();
let _ = block_on(request).unwrap();
}