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 05:57:53 +00:00
committed by GitHub
co-authored by Zed AI
parent edf78e770d
commit 9767033985
9 changed files with 158 additions and 288 deletions
+3 -6
View File
@@ -87,10 +87,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp
let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window);
item.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
item.running_state().clone()
});
cx.run_until_parked();
@@ -105,7 +102,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp
assert_eq!(
"First console output line before thread stopped!\nFirst output line before thread stopped!\n",
active_debug_session_panel.read(cx).mode().as_running().unwrap().read(cx).console().read(cx).editor().read(cx).text(cx).as_str()
active_debug_session_panel.read(cx).running_state().read(cx).console().read(cx).editor().read(cx).text(cx).as_str()
);
})
.unwrap();
@@ -154,7 +151,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp
assert_eq!(
"First console output line before thread stopped!\nFirst output line before thread stopped!\nSecond output line after thread stopped!\nSecond console output line after thread stopped!\n",
active_session_panel.read(cx).mode().as_running().unwrap().read(cx).console().read(cx).editor().read(cx).text(cx).as_str()
active_session_panel.read(cx).running_state().read(cx).console().read(cx).editor().read(cx).text(cx).as_str()
);
})
.unwrap();
+8 -36
View File
@@ -84,11 +84,7 @@ async fn test_basic_show_debug_panel(executor: BackgroundExecutor, cx: &mut Test
debug_panel.update(cx, |debug_panel, _| debug_panel.active_session().unwrap());
let running_state = active_session.update(cx, |active_session, _| {
active_session
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
active_session.running_state().clone()
});
debug_panel.update(cx, |this, cx| {
@@ -120,11 +116,7 @@ async fn test_basic_show_debug_panel(executor: BackgroundExecutor, cx: &mut Test
.unwrap();
let running_state = active_session.update(cx, |active_session, _| {
active_session
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
active_session.running_state().clone()
});
assert_eq!(client.id(), running_state.read(cx).session_id());
@@ -153,11 +145,7 @@ async fn test_basic_show_debug_panel(executor: BackgroundExecutor, cx: &mut Test
.unwrap();
let running_state = active_session.update(cx, |active_session, _| {
active_session
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
active_session.running_state().clone()
});
debug_panel.update(cx, |this, cx| {
@@ -247,11 +235,7 @@ async fn test_we_can_only_have_one_panel_per_debug_session(
.unwrap();
let running_state = active_session.update(cx, |active_session, _| {
active_session
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
active_session.running_state().clone()
});
assert_eq!(client.id(), active_session.read(cx).session_id(cx));
@@ -284,11 +268,7 @@ async fn test_we_can_only_have_one_panel_per_debug_session(
.unwrap();
let running_state = active_session.update(cx, |active_session, _| {
active_session
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
active_session.running_state().clone()
});
assert_eq!(client.id(), active_session.read(cx).session_id(cx));
@@ -316,11 +296,7 @@ async fn test_we_can_only_have_one_panel_per_debug_session(
.unwrap();
let running_state = active_session.update(cx, |active_session, _| {
active_session
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
active_session.running_state().clone()
});
debug_panel.update(cx, |this, cx| {
@@ -1009,12 +985,8 @@ async fn test_debug_panel_item_thread_status_reset_on_failure(
cx.run_until_parked();
let running_state = active_debug_session_panel(workspace, cx).update_in(cx, |item, _, _| {
item.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
});
let running_state = active_debug_session_panel(workspace, cx)
.update(cx, |item, _| item.running_state().clone());
cx.run_until_parked();
let thread_id = ThreadId(1);
+1 -4
View File
@@ -106,10 +106,7 @@ async fn test_module_list(executor: BackgroundExecutor, cx: &mut TestAppContext)
let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window);
item.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
item.running_state().clone()
});
running_state.update_in(cx, |this, window, cx| {
@@ -138,43 +138,33 @@ async fn test_fetch_initial_stack_frames_and_go_to_stack_frame(
// trigger to load threads
active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
session
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state
.session()
.update(cx, |session, cx| session.threads(cx));
});
session.running_state().update(cx, |running_state, cx| {
running_state
.session()
.update(cx, |session, cx| session.threads(cx));
});
});
cx.run_until_parked();
// select first thread
active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| {
session
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state.select_current_thread(
&running_state
.session()
.update(cx, |session, cx| session.threads(cx)),
window,
cx,
);
});
session.running_state().update(cx, |running_state, cx| {
running_state.select_current_thread(
&running_state
.session()
.update(cx, |session, cx| session.threads(cx)),
window,
cx,
);
});
});
cx.run_until_parked();
active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
let stack_frame_list = session
.mode()
.as_running()
.unwrap()
.running_state()
.update(cx, |state, _| state.stack_frame_list().clone());
stack_frame_list.update(cx, |stack_frame_list, cx| {
@@ -309,34 +299,26 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
// trigger threads to load
active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
session
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state
.session()
.update(cx, |session, cx| session.threads(cx));
});
session.running_state().update(cx, |running_state, cx| {
running_state
.session()
.update(cx, |session, cx| session.threads(cx));
});
});
cx.run_until_parked();
// select first thread
active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| {
session
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state.select_current_thread(
&running_state
.session()
.update(cx, |session, cx| session.threads(cx)),
window,
cx,
);
});
session.running_state().update(cx, |running_state, cx| {
running_state.select_current_thread(
&running_state
.session()
.update(cx, |session, cx| session.threads(cx)),
window,
cx,
);
});
});
cx.run_until_parked();
@@ -383,9 +365,7 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
active_debug_panel_item
.read(cx)
.mode()
.as_running()
.unwrap()
.running_state()
.read(cx)
.stack_frame_list()
.clone()
@@ -676,34 +656,26 @@ async fn test_collapsed_entries(executor: BackgroundExecutor, cx: &mut TestAppCo
// trigger threads to load
active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
session
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state
.session()
.update(cx, |session, cx| session.threads(cx));
});
session.running_state().update(cx, |running_state, cx| {
running_state
.session()
.update(cx, |session, cx| session.threads(cx));
});
});
cx.run_until_parked();
// select first thread
active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| {
session
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state.select_current_thread(
&running_state
.session()
.update(cx, |session, cx| session.threads(cx)),
window,
cx,
);
});
session.running_state().update(cx, |running_state, cx| {
running_state.select_current_thread(
&running_state
.session()
.update(cx, |session, cx| session.threads(cx)),
window,
cx,
);
});
});
cx.run_until_parked();
@@ -711,9 +683,7 @@ async fn test_collapsed_entries(executor: BackgroundExecutor, cx: &mut TestAppCo
// trigger stack frames to loaded
active_debug_session_panel(workspace, cx).update(cx, |debug_panel_item, cx| {
let stack_frame_list = debug_panel_item
.mode()
.as_running()
.unwrap()
.running_state()
.update(cx, |state, _| state.stack_frame_list().clone());
stack_frame_list.update(cx, |stack_frame_list, cx| {
@@ -725,9 +695,7 @@ async fn test_collapsed_entries(executor: BackgroundExecutor, cx: &mut TestAppCo
active_debug_session_panel(workspace, cx).update_in(cx, |debug_panel_item, window, cx| {
let stack_frame_list = debug_panel_item
.mode()
.as_running()
.unwrap()
.running_state()
.update(cx, |state, _| state.stack_frame_list().clone());
stack_frame_list.update(cx, |stack_frame_list, cx| {
+5 -22
View File
@@ -183,10 +183,7 @@ async fn test_basic_fetch_initial_scope_and_variables(
let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window);
item.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
item.running_state().clone()
});
cx.run_until_parked();
@@ -427,10 +424,7 @@ async fn test_fetch_variables_for_multiple_scopes(
let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window);
item.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
item.running_state().clone()
});
cx.run_until_parked();
@@ -710,11 +704,7 @@ async fn test_keyboard_navigation(executor: BackgroundExecutor, cx: &mut TestApp
let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window);
let running = item
.mode()
.as_running()
.expect("Session should be running by this point")
.clone();
let running = item.running_state().clone();
let variable_list = running.read_with(cx, |state, _| state.variable_list().clone());
variable_list.update(cx, |_, cx| cx.focus_self(window));
@@ -1440,11 +1430,7 @@ async fn test_variable_list_only_sends_requests_when_rendering(
cx.run_until_parked();
let running_state = active_debug_session_panel(workspace, cx).update_in(cx, |item, _, _| {
let state = item
.mode()
.as_running()
.expect("Session should be running by this point")
.clone();
let state = item.running_state().clone();
state
});
@@ -1742,10 +1728,7 @@ async fn test_it_fetches_scopes_variables_when_you_select_a_stack_frame(
let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window);
item.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
item.running_state().clone()
});
running_state.update(cx, |running_state, cx| {