debugger: Extract running state from DebugSession mode and remove mode field (#29646)

DebugSession.mode is no longer needed because project::debugger::Session
manages its own state now (booting, running, terminated), and removing
mode simplifies a lot of the code that uses running state.

I used Zed AI to do a good chunk of the refactor, but I doubled-checked
everything it did and changed a good amount of its updates.

Release Notes:

- N/A

Co-authored-by: Zed AI <ai@zed.dev>
This commit is contained in:
Anthony Eid 2025-04-30 01:57:53 -04:00 committed by GitHub
parent edf78e770d
commit 9767033985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 158 additions and 288 deletions

View file

@ -64,7 +64,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
active_item.update(cx, |item, cx| item.pause_thread(cx))
}
@ -75,7 +75,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
active_item.update(cx, |item, cx| item.restart_session(cx))
}
@ -86,7 +86,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
active_item.update(cx, |item, cx| item.step_in(cx))
}
@ -97,7 +97,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
active_item.update(cx, |item, cx| item.step_over(cx))
}
@ -108,7 +108,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
active_item.update(cx, |item, cx| item.step_back(cx))
}
@ -119,7 +119,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
cx.defer(move |cx| {
active_item.update(cx, |item, cx| item.stop_thread(cx))
@ -132,7 +132,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel
.active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned())
.map(|session| session.read(cx).running_state().clone())
}) {
active_item.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx))
}
@ -209,11 +209,8 @@ pub fn init(cx: &mut App) {
state: debugger::breakpoint_store::BreakpointState::Enabled,
};
active_session
.update(cx, |session_item, _| {
session_item.mode().as_running().cloned()
})?
.update(cx, |state, cx| {
active_session.update(cx, |session, cx| {
session.running_state().update(cx, |state, cx| {
if let Some(thread_id) = state.selected_thread_id() {
state.session().update(cx, |session, cx| {
session.run_to_position(
@ -224,6 +221,7 @@ pub fn init(cx: &mut App) {
})
}
});
});
Some(())
});
@ -246,17 +244,16 @@ pub fn init(cx: &mut App) {
cx,
)?;
active_session
.update(cx, |session_item, _| {
session_item.mode().as_running().cloned()
})?
.update(cx, |state, cx| {
active_session.update(cx, |session, cx| {
session.running_state().update(cx, |state, cx| {
let stack_id = state.selected_stack_frame_id(cx);
state.session().update(cx, |session, cx| {
session.evaluate(text, None, stack_id, None, cx).detach();
});
});
});
Some(())
});
},