Fix manually restarting a debug session

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Anthony
2025-04-22 11:24:48 -04:00
parent 88a0aec2f3
commit dbbbb1a3b0
3 changed files with 41 additions and 29 deletions

View File

@@ -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| {

View File

@@ -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));
}

View File

@@ -814,6 +814,10 @@ impl Session {
.map(|session| session.read(cx).id)
}
pub fn parent_session(&self) -> Option<&Entity<Self>> {
self.parent_session.as_ref()
}
pub fn capabilities(&self) -> &Capabilities {
&self.capabilities
}