diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index d0c77aa579..8668fd6d7a 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -17,6 +17,7 @@ use gpui::{ actions, anchored, deferred, }; +use project::debugger::session::SessionStateEvent; use project::{ Project, debugger::{ @@ -290,10 +291,43 @@ impl DebugPanel { { dap_store.start_session(debug_config.definition, None, cx) } else { - dap_store.start_session(definition, None, cx) + dap_store.start_session(definition.clone(), None, cx) } })??; + this.update_in(cx, |_, window, cx| { + let definition = definition.clone(); + cx.subscribe_in( + &session, + window, + move |_, session, event: &SessionStateEvent, window, cx| match event { + SessionStateEvent::Restart => { + let mut curr_session = session.clone(); + while let Some(parent_session) = curr_session + .read_with(cx, |session, _| session.parent_session().cloned()) + { + curr_session = parent_session; + } + + let task = curr_session.update(cx, |session, cx| session.shutdown(cx)); + + let definition = definition.clone(); + cx.spawn_in(window, async move |this, cx| { + task.await; + + this.update_in(cx, |this, window, cx| { + this.start_session(definition, window, cx) + }) + }) + .detach_and_log_err(cx); + } + _ => {} + }, + ) + .detach(); + }) + .ok(); + let serialized_layout = persistence::get_serialized_pane_layout(adapter_name).await; let workspace = this.update_in(cx, |this, window, cx| { diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rs index e20bdf0d3c..9d8447ab71 100644 --- a/crates/project/src/debugger/dap_store.rs +++ b/crates/project/src/debugger/dap_store.rs @@ -347,37 +347,11 @@ impl DapStore { cx.notify(); cx.subscribe(&session, { - let template = template.clone(); - move |this: &mut DapStore, session, event: &SessionStateEvent, cx| match event { + move |this: &mut DapStore, _, event: &SessionStateEvent, cx| match event { SessionStateEvent::Shutdown => { this.shutdown_session(session_id, cx).detach_and_log_err(cx); } - SessionStateEvent::Restart => { - let mut curr_session = session; - while let Some(parent_id) = curr_session.read(cx).parent_id(cx) { - if let Some(parent_session) = this.sessions.get(&parent_id).cloned() { - curr_session = parent_session; - } else { - log::error!("Failed to get parent session from parent session id"); - break; - } - } - - let session_id = curr_session.read(cx).session_id(); - - let task = curr_session.update(cx, |session, cx| session.shutdown(cx)); - - let template = template.clone(); - cx.spawn(async move |this, cx| { - task.await; - - this.update(cx, |this, cx| { - this.sessions.remove(&session_id); - this.start_session(template, None, cx) - }) - }) - .detach_and_log_err(cx); - } + SessionStateEvent::Restart => {} SessionStateEvent::Running => { cx.emit(DapStoreEvent::DebugClientStarted(session_id)); } diff --git a/crates/project/src/debugger/session.rs b/crates/project/src/debugger/session.rs index 4edfdef7bb..946a950a8c 100644 --- a/crates/project/src/debugger/session.rs +++ b/crates/project/src/debugger/session.rs @@ -814,6 +814,10 @@ impl Session { .map(|session| session.read(cx).id) } + pub fn parent_session(&self) -> Option<&Entity> { + self.parent_session.as_ref() + } + pub fn capabilities(&self) -> &Capabilities { &self.capabilities }