debugger: Prompt user when they try to close a running debug session (#28584)
Closes #ISSUE Release Notes: - N/A
This commit is contained in:
parent
08ce230bae
commit
7caa2c2ea0
1 changed files with 45 additions and 16 deletions
|
@ -415,32 +415,58 @@ impl DebugPanel {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_session(&mut self, entity_id: EntityId, cx: &mut Context<Self>) {
|
fn close_session(&mut self, entity_id: EntityId, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let Some(session) = self
|
let Some(session) = self
|
||||||
.sessions
|
.sessions
|
||||||
.iter()
|
.iter()
|
||||||
.find(|other| entity_id == other.entity_id())
|
.find(|other| entity_id == other.entity_id())
|
||||||
|
.cloned()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
session.update(cx, |session, cx| session.shutdown(cx));
|
let session_id = session.update(cx, |this, cx| this.session_id(cx));
|
||||||
|
let should_prompt = self
|
||||||
|
.project
|
||||||
|
.update(cx, |this, cx| {
|
||||||
|
let session = this.dap_store().read(cx).session_by_id(session_id);
|
||||||
|
session.map(|session| !session.read(cx).is_terminated())
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
self.sessions.retain(|other| entity_id != other.entity_id());
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
if should_prompt {
|
||||||
|
let response = cx.prompt(
|
||||||
|
gpui::PromptLevel::Warning,
|
||||||
|
"This Debug Session is still running. Are you sure you want to terminate it?",
|
||||||
|
None,
|
||||||
|
&["Yes", "No"],
|
||||||
|
);
|
||||||
|
if response.await == Ok(1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.update(cx, |session, cx| session.shutdown(cx)).ok();
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.sessions.retain(|other| entity_id != other.entity_id());
|
||||||
|
|
||||||
if let Some(active_session_id) = self
|
if let Some(active_session_id) = this
|
||||||
.active_session
|
.active_session
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|session| session.entity_id())
|
.map(|session| session.entity_id())
|
||||||
{
|
{
|
||||||
if active_session_id == entity_id {
|
if active_session_id == entity_id {
|
||||||
self.active_session = self.sessions.first().cloned();
|
this.active_session = this.sessions.first().cloned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cx.notify()
|
||||||
cx.notify();
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sessions_drop_down_menu(
|
fn sessions_drop_down_menu(
|
||||||
&self,
|
&self,
|
||||||
active_session: &Entity<DebugSession>,
|
active_session: &Entity<DebugSession>,
|
||||||
|
@ -487,8 +513,11 @@ impl DebugPanel {
|
||||||
let weak = weak.clone();
|
let weak = weak.clone();
|
||||||
move |_, window, cx| {
|
move |_, window, cx| {
|
||||||
weak.update(cx, |panel, cx| {
|
weak.update(cx, |panel, cx| {
|
||||||
panel
|
panel.close_session(
|
||||||
.close_session(weak_session_id, cx);
|
weak_session_id,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
context_menu
|
context_menu
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue