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

@ -92,10 +92,7 @@ impl DebugPanel {
let (has_active_session, supports_restart, support_step_back, status) = self let (has_active_session, supports_restart, support_step_back, status) = self
.active_session() .active_session()
.map(|item| { .map(|item| {
let running = item.read(cx).mode().as_running().cloned(); let running = item.read(cx).running_state().clone();
match running {
Some(running) => {
let caps = running.read(cx).capabilities(cx); let caps = running.read(cx).capabilities(cx);
( (
!running.read(cx).session().read(cx).is_terminated(), !running.read(cx).session().read(cx).is_terminated(),
@ -103,9 +100,6 @@ impl DebugPanel {
caps.supports_step_back.unwrap_or_default(), caps.supports_step_back.unwrap_or_default(),
running.read(cx).thread_status(cx), running.read(cx).thread_status(cx),
) )
}
None => (false, false, false, None),
}
}) })
.unwrap_or((false, false, false, None)); .unwrap_or((false, false, false, None));
@ -308,11 +302,11 @@ impl DebugPanel {
this.sessions.retain(|session| { this.sessions.retain(|session| {
session session
.read(cx) .read(cx)
.mode() .running_state()
.as_running() .read(cx)
.map_or(false, |running_state| { .session()
!running_state.read(cx).session().read(cx).is_terminated() .read(cx)
}) .is_terminated()
}); });
let session_item = DebugSession::running( let session_item = DebugSession::running(
@ -325,11 +319,13 @@ impl DebugPanel {
cx, cx,
); );
if let Some(running) = session_item.read(cx).mode().as_running().cloned() {
// We might want to make this an event subscription and only notify when a new thread is selected // We might want to make this an event subscription and only notify when a new thread is selected
// This is used to filter the command menu correctly // This is used to filter the command menu correctly
cx.observe(&running, |_, _, cx| cx.notify()).detach(); cx.observe(
} &session_item.read(cx).running_state().clone(),
|_, _, cx| cx.notify(),
)
.detach();
this.sessions.push(session_item.clone()); this.sessions.push(session_item.clone());
this.activate_session(session_item, window, cx); this.activate_session(session_item, window, cx);
@ -483,11 +479,9 @@ impl DebugPanel {
return; return;
}; };
session.update(cx, |this, cx| { session.update(cx, |this, cx| {
if let Some(running) = this.mode().as_running() { this.running_state().update(cx, |this, cx| {
running.update(cx, |this, cx| {
this.serialize_layout(window, cx); this.serialize_layout(window, cx);
}); });
}
}); });
let session_id = session.update(cx, |this, cx| this.session_id(cx)); let session_id = session.update(cx, |this, cx| this.session_id(cx));
let should_prompt = self let should_prompt = self
@ -624,7 +618,7 @@ impl DebugPanel {
if let Some(running_state) = self if let Some(running_state) = self
.active_session .active_session
.as_ref() .as_ref()
.and_then(|session| session.read(cx).mode().as_running().cloned()) .map(|session| session.read(cx).running_state().clone())
{ {
let pane_items_status = running_state.read(cx).pane_items_status(cx); let pane_items_status = running_state.read(cx).pane_items_status(cx);
let this = cx.weak_entity(); let this = cx.weak_entity();
@ -635,10 +629,10 @@ impl DebugPanel {
let this = this.clone(); let this = this.clone();
move |window, cx| { move |window, cx| {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
if let Some(running_state) = if let Some(running_state) = this
this.active_session.as_ref().and_then(|session| { .active_session
session.read(cx).mode().as_running().cloned() .as_ref()
}) .map(|session| session.read(cx).running_state().clone())
{ {
running_state.update(cx, |state, cx| { running_state.update(cx, |state, cx| {
if is_visible { if is_visible {
@ -681,7 +675,7 @@ impl DebugPanel {
h_flex().gap_2().w_full().when_some( h_flex().gap_2().w_full().when_some(
active_session active_session
.as_ref() .as_ref()
.and_then(|session| session.read(cx).mode().as_running()), .map(|session| session.read(cx).running_state()),
|this, running_session| { |this, running_session| {
let thread_status = running_session let thread_status = running_session
.read(cx) .read(cx)
@ -919,7 +913,7 @@ impl DebugPanel {
.when_some( .when_some(
active_session active_session
.as_ref() .as_ref()
.and_then(|session| session.read(cx).mode().as_running()) .map(|session| session.read(cx).running_state())
.cloned(), .cloned(),
|this, session| { |this, session| {
this.child( this.child(
@ -982,12 +976,10 @@ impl DebugPanel {
) { ) {
if let Some(session) = self.active_session() { if let Some(session) = self.active_session() {
session.update(cx, |session, cx| { session.update(cx, |session, cx| {
if let Some(running) = session.mode().as_running() { session.running_state().update(cx, |running, cx| {
running.update(cx, |running, cx| {
running.activate_pane_in_direction(direction, window, cx); running.activate_pane_in_direction(direction, window, cx);
}) })
} });
})
} }
} }
@ -999,12 +991,10 @@ impl DebugPanel {
) { ) {
if let Some(session) = self.active_session() { if let Some(session) = self.active_session() {
session.update(cx, |session, cx| { session.update(cx, |session, cx| {
if let Some(running) = session.mode().as_running() { session.running_state().update(cx, |running, cx| {
running.update(cx, |running, cx| {
running.activate_item(item, window, cx); running.activate_item(item, window, cx);
}) });
} });
})
} }
} }
@ -1017,11 +1007,9 @@ impl DebugPanel {
debug_assert!(self.sessions.contains(&session_item)); debug_assert!(self.sessions.contains(&session_item));
session_item.focus_handle(cx).focus(window); session_item.focus_handle(cx).focus(window);
session_item.update(cx, |this, cx| { session_item.update(cx, |this, cx| {
if let Some(running) = this.mode().as_running() { this.running_state().update(cx, |this, cx| {
running.update(cx, |this, cx| {
this.go_to_selected_stack_frame(window, cx); this.go_to_selected_stack_frame(window, cx);
}); });
}
}); });
self.active_session = Some(session_item); self.active_session = Some(session_item);
cx.notify(); cx.notify();
@ -1106,7 +1094,7 @@ impl Render for DebugPanel {
if self if self
.active_session .active_session
.as_ref() .as_ref()
.and_then(|session| session.read(cx).mode().as_running().cloned()) .map(|session| session.read(cx).running_state())
.map(|state| state.read(cx).has_open_context_menu(cx)) .map(|state| state.read(cx).has_open_context_menu(cx))
.unwrap_or(false) .unwrap_or(false)
{ {
@ -1224,11 +1212,10 @@ impl Render for DebugPanel {
if this if this
.active_session .active_session
.as_ref() .as_ref()
.and_then(|session| { .map(|session| {
session.read(cx).mode().as_running().map(|state| { let state = session.read(cx).running_state();
state.read(cx).has_pane_at_position(event.position) state.read(cx).has_pane_at_position(event.position)
}) })
})
.unwrap_or(false) .unwrap_or(false)
{ {
this.deploy_context_menu(event.position, window, cx); this.deploy_context_menu(event.position, window, cx);

View file

@ -64,7 +64,7 @@ pub fn init(cx: &mut App) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .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)) 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| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .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)) 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| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .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)) 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| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .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)) 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| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .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)) 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| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .active_session()
.and_then(|session| session.read(cx).mode().as_running().cloned()) .map(|session| session.read(cx).running_state().clone())
}) { }) {
cx.defer(move |cx| { cx.defer(move |cx| {
active_item.update(cx, |item, cx| item.stop_thread(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| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session() .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)) 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, state: debugger::breakpoint_store::BreakpointState::Enabled,
}; };
active_session active_session.update(cx, |session, cx| {
.update(cx, |session_item, _| { session.running_state().update(cx, |state, cx| {
session_item.mode().as_running().cloned()
})?
.update(cx, |state, cx| {
if let Some(thread_id) = state.selected_thread_id() { if let Some(thread_id) = state.selected_thread_id() {
state.session().update(cx, |session, cx| { state.session().update(cx, |session, cx| {
session.run_to_position( session.run_to_position(
@ -224,6 +221,7 @@ pub fn init(cx: &mut App) {
}) })
} }
}); });
});
Some(()) Some(())
}); });
@ -246,17 +244,16 @@ pub fn init(cx: &mut App) {
cx, cx,
)?; )?;
active_session active_session.update(cx, |session, cx| {
.update(cx, |session_item, _| { session.running_state().update(cx, |state, cx| {
session_item.mode().as_running().cloned()
})?
.update(cx, |state, cx| {
let stack_id = state.selected_stack_frame_id(cx); let stack_id = state.selected_stack_frame_id(cx);
state.session().update(cx, |session, cx| { state.session().update(cx, |session, cx| {
session.evaluate(text, None, stack_id, None, cx).detach(); session.evaluate(text, None, stack_id, None, cx).detach();
}); });
}); });
});
Some(()) Some(())
}); });
}, },

View file

@ -5,7 +5,7 @@ use std::sync::OnceLock;
use dap::client::SessionId; use dap::client::SessionId;
use gpui::{App, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Task, WeakEntity}; use gpui::{App, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Task, WeakEntity};
use project::Project; use project::Project;
use project::debugger::{dap_store::DapStore, session::Session}; use project::debugger::session::Session;
use project::worktree_store::WorktreeStore; use project::worktree_store::WorktreeStore;
use rpc::proto::{self, PeerId}; use rpc::proto::{self, PeerId};
use running::RunningState; use running::RunningState;
@ -18,23 +18,10 @@ use workspace::{
use crate::debugger_panel::DebugPanel; use crate::debugger_panel::DebugPanel;
use crate::persistence::SerializedPaneLayout; use crate::persistence::SerializedPaneLayout;
pub(crate) enum DebugSessionState {
Running(Entity<running::RunningState>),
}
impl DebugSessionState {
pub(crate) fn as_running(&self) -> Option<&Entity<running::RunningState>> {
match &self {
DebugSessionState::Running(entity) => Some(entity),
}
}
}
pub struct DebugSession { pub struct DebugSession {
remote_id: Option<workspace::ViewId>, remote_id: Option<workspace::ViewId>,
mode: DebugSessionState, running_state: Entity<RunningState>,
label: OnceLock<SharedString>, label: OnceLock<SharedString>,
dap_store: WeakEntity<DapStore>,
_debug_panel: WeakEntity<DebugPanel>, _debug_panel: WeakEntity<DebugPanel>,
_worktree_store: WeakEntity<WorktreeStore>, _worktree_store: WeakEntity<WorktreeStore>,
_workspace: WeakEntity<Workspace>, _workspace: WeakEntity<Workspace>,
@ -57,7 +44,7 @@ impl DebugSession {
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> Entity<Self> { ) -> Entity<Self> {
let mode = cx.new(|cx| { let running_state = cx.new(|cx| {
RunningState::new( RunningState::new(
session.clone(), session.clone(),
project.clone(), project.clone(),
@ -69,13 +56,12 @@ impl DebugSession {
}); });
cx.new(|cx| Self { cx.new(|cx| Self {
_subscriptions: [cx.subscribe(&mode, |_, _, _, cx| { _subscriptions: [cx.subscribe(&running_state, |_, _, _, cx| {
cx.notify(); cx.notify();
})], })],
remote_id: None, remote_id: None,
mode: DebugSessionState::Running(mode), running_state,
label: OnceLock::new(), label: OnceLock::new(),
dap_store: project.read(cx).dap_store().downgrade(),
_debug_panel, _debug_panel,
_worktree_store: project.read(cx).worktree_store().downgrade(), _worktree_store: project.read(cx).worktree_store().downgrade(),
_workspace: workspace, _workspace: workspace,
@ -83,25 +69,16 @@ impl DebugSession {
} }
pub(crate) fn session_id(&self, cx: &App) -> SessionId { pub(crate) fn session_id(&self, cx: &App) -> SessionId {
match &self.mode { self.running_state.read(cx).session_id()
DebugSessionState::Running(entity) => entity.read(cx).session_id(),
}
} }
pub fn session(&self, cx: &App) -> Entity<Session> { pub fn session(&self, cx: &App) -> Entity<Session> {
match &self.mode { self.running_state.read(cx).session().clone()
DebugSessionState::Running(entity) => entity.read(cx).session().clone(),
}
} }
pub(crate) fn shutdown(&mut self, cx: &mut Context<Self>) { pub(crate) fn shutdown(&mut self, cx: &mut Context<Self>) {
match &self.mode { self.running_state
DebugSessionState::Running(state) => state.update(cx, |state, cx| state.shutdown(cx)), .update(cx, |state, cx| state.shutdown(cx));
}
}
pub(crate) fn mode(&self) -> &DebugSessionState {
&self.mode
} }
pub(crate) fn label(&self, cx: &App) -> SharedString { pub(crate) fn label(&self, cx: &App) -> SharedString {
@ -109,45 +86,42 @@ impl DebugSession {
return label.clone(); return label.clone();
} }
let session_id = match &self.mode { let session = self.running_state.read(cx).session();
DebugSessionState::Running(running_state) => running_state.read(cx).session_id(),
};
let Ok(Some(session)) = self
.dap_store
.read_with(cx, |store, _| store.session_by_id(session_id))
else {
return "".into();
};
self.label self.label
.get_or_init(|| session.read(cx).label()) .get_or_init(|| session.read(cx).label())
.to_owned() .to_owned()
} }
#[allow(unused)] pub(crate) fn running_state(&self) -> &Entity<RunningState> {
pub(crate) fn running_state(&self) -> Entity<RunningState> { &self.running_state
match &self.mode {
DebugSessionState::Running(running_state) => running_state.clone(),
}
} }
pub(crate) fn label_element(&self, cx: &App) -> AnyElement { pub(crate) fn label_element(&self, cx: &App) -> AnyElement {
let label = self.label(cx); let label = self.label(cx);
let icon = match &self.mode { let icon = {
DebugSessionState::Running(state) => { if self
if state.read(cx).session().read(cx).is_terminated() { .running_state
.read(cx)
.session()
.read(cx)
.is_terminated()
{
Some(Indicator::dot().color(Color::Error)) Some(Indicator::dot().color(Color::Error))
} else { } else {
match state.read(cx).thread_status(cx).unwrap_or_default() { match self
.running_state
.read(cx)
.thread_status(cx)
.unwrap_or_default()
{
project::debugger::session::ThreadStatus::Stopped => { project::debugger::session::ThreadStatus::Stopped => {
Some(Indicator::dot().color(Color::Conflict)) Some(Indicator::dot().color(Color::Conflict))
} }
_ => Some(Indicator::dot().color(Color::Success)), _ => Some(Indicator::dot().color(Color::Success)),
} }
} }
}
}; };
h_flex() h_flex()
@ -163,9 +137,7 @@ impl EventEmitter<DebugPanelItemEvent> for DebugSession {}
impl Focusable for DebugSession { impl Focusable for DebugSession {
fn focus_handle(&self, cx: &App) -> FocusHandle { fn focus_handle(&self, cx: &App) -> FocusHandle {
match &self.mode { self.running_state.focus_handle(cx)
DebugSessionState::Running(running_state) => running_state.focus_handle(cx),
}
} }
} }
@ -244,10 +216,7 @@ impl FollowableItem for DebugSession {
impl Render for DebugSession { impl Render for DebugSession {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
match &self.mode { self.running_state
DebugSessionState::Running(running_state) => { .update(cx, |this, cx| this.render(window, cx).into_any_element())
running_state.update(cx, |this, cx| this.render(window, cx).into_any_element())
}
}
} }
} }

View file

@ -118,8 +118,8 @@ pub fn start_debug_session_with<T: Fn(&Arc<DebugAdapterClient>) + 'static>(
workspace workspace
.panel::<DebugPanel>(cx) .panel::<DebugPanel>(cx)
.and_then(|panel| panel.read(cx).active_session()) .and_then(|panel| panel.read(cx).active_session())
.and_then(|session| session.read(cx).mode().as_running().cloned()) .map(|session| session.read(cx).running_state().read(cx).session())
.map(|running| running.read(cx).session().clone()) .cloned()
.ok_or_else(|| anyhow!("Failed to get active session")) .ok_or_else(|| anyhow!("Failed to get active session"))
})??; })??;

View file

@ -87,10 +87,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp
let running_state = let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window); cx.focus_self(window);
item.mode() item.running_state().clone()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
cx.run_until_parked(); cx.run_until_parked();
@ -105,7 +102,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp
assert_eq!( assert_eq!(
"First console output line before thread stopped!\nFirst output line before thread stopped!\n", "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(); .unwrap();
@ -154,7 +151,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp
assert_eq!( 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", "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(); .unwrap();

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()); debug_panel.update(cx, |debug_panel, _| debug_panel.active_session().unwrap());
let running_state = active_session.update(cx, |active_session, _| { let running_state = active_session.update(cx, |active_session, _| {
active_session active_session.running_state().clone()
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
debug_panel.update(cx, |this, cx| { debug_panel.update(cx, |this, cx| {
@ -120,11 +116,7 @@ async fn test_basic_show_debug_panel(executor: BackgroundExecutor, cx: &mut Test
.unwrap(); .unwrap();
let running_state = active_session.update(cx, |active_session, _| { let running_state = active_session.update(cx, |active_session, _| {
active_session active_session.running_state().clone()
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
assert_eq!(client.id(), running_state.read(cx).session_id()); 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(); .unwrap();
let running_state = active_session.update(cx, |active_session, _| { let running_state = active_session.update(cx, |active_session, _| {
active_session active_session.running_state().clone()
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
debug_panel.update(cx, |this, cx| { debug_panel.update(cx, |this, cx| {
@ -247,11 +235,7 @@ async fn test_we_can_only_have_one_panel_per_debug_session(
.unwrap(); .unwrap();
let running_state = active_session.update(cx, |active_session, _| { let running_state = active_session.update(cx, |active_session, _| {
active_session active_session.running_state().clone()
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
assert_eq!(client.id(), active_session.read(cx).session_id(cx)); 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(); .unwrap();
let running_state = active_session.update(cx, |active_session, _| { let running_state = active_session.update(cx, |active_session, _| {
active_session active_session.running_state().clone()
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
assert_eq!(client.id(), active_session.read(cx).session_id(cx)); 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(); .unwrap();
let running_state = active_session.update(cx, |active_session, _| { let running_state = active_session.update(cx, |active_session, _| {
active_session active_session.running_state().clone()
.mode()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
debug_panel.update(cx, |this, cx| { 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(); cx.run_until_parked();
let running_state = active_debug_session_panel(workspace, cx).update_in(cx, |item, _, _| { let running_state = active_debug_session_panel(workspace, cx)
item.mode() .update(cx, |item, _| item.running_state().clone());
.as_running()
.expect("Session should be running by this point")
.clone()
});
cx.run_until_parked(); cx.run_until_parked();
let thread_id = ThreadId(1); let thread_id = ThreadId(1);

View file

@ -106,10 +106,7 @@ async fn test_module_list(executor: BackgroundExecutor, cx: &mut TestAppContext)
let running_state = let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window); cx.focus_self(window);
item.mode() item.running_state().clone()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
running_state.update_in(cx, |this, window, cx| { running_state.update_in(cx, |this, window, cx| {

View file

@ -138,11 +138,7 @@ async fn test_fetch_initial_stack_frames_and_go_to_stack_frame(
// trigger to load threads // trigger to load threads
active_debug_session_panel(workspace, cx).update(cx, |session, cx| { active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
session session.running_state().update(cx, |running_state, cx| {
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state running_state
.session() .session()
.update(cx, |session, cx| session.threads(cx)); .update(cx, |session, cx| session.threads(cx));
@ -153,11 +149,7 @@ async fn test_fetch_initial_stack_frames_and_go_to_stack_frame(
// select first thread // select first thread
active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| {
session session.running_state().update(cx, |running_state, cx| {
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state.select_current_thread( running_state.select_current_thread(
&running_state &running_state
.session() .session()
@ -172,9 +164,7 @@ async fn test_fetch_initial_stack_frames_and_go_to_stack_frame(
active_debug_session_panel(workspace, cx).update(cx, |session, cx| { active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
let stack_frame_list = session let stack_frame_list = session
.mode() .running_state()
.as_running()
.unwrap()
.update(cx, |state, _| state.stack_frame_list().clone()); .update(cx, |state, _| state.stack_frame_list().clone());
stack_frame_list.update(cx, |stack_frame_list, cx| { stack_frame_list.update(cx, |stack_frame_list, cx| {
@ -309,11 +299,7 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
// trigger threads to load // trigger threads to load
active_debug_session_panel(workspace, cx).update(cx, |session, cx| { active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
session session.running_state().update(cx, |running_state, cx| {
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state running_state
.session() .session()
.update(cx, |session, cx| session.threads(cx)); .update(cx, |session, cx| session.threads(cx));
@ -324,11 +310,7 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
// select first thread // select first thread
active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| {
session session.running_state().update(cx, |running_state, cx| {
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state.select_current_thread( running_state.select_current_thread(
&running_state &running_state
.session() .session()
@ -383,9 +365,7 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
active_debug_panel_item active_debug_panel_item
.read(cx) .read(cx)
.mode() .running_state()
.as_running()
.unwrap()
.read(cx) .read(cx)
.stack_frame_list() .stack_frame_list()
.clone() .clone()
@ -676,11 +656,7 @@ async fn test_collapsed_entries(executor: BackgroundExecutor, cx: &mut TestAppCo
// trigger threads to load // trigger threads to load
active_debug_session_panel(workspace, cx).update(cx, |session, cx| { active_debug_session_panel(workspace, cx).update(cx, |session, cx| {
session session.running_state().update(cx, |running_state, cx| {
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state running_state
.session() .session()
.update(cx, |session, cx| session.threads(cx)); .update(cx, |session, cx| session.threads(cx));
@ -691,11 +667,7 @@ async fn test_collapsed_entries(executor: BackgroundExecutor, cx: &mut TestAppCo
// select first thread // select first thread
active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |session, window, cx| {
session session.running_state().update(cx, |running_state, cx| {
.mode()
.as_running()
.unwrap()
.update(cx, |running_state, cx| {
running_state.select_current_thread( running_state.select_current_thread(
&running_state &running_state
.session() .session()
@ -711,9 +683,7 @@ async fn test_collapsed_entries(executor: BackgroundExecutor, cx: &mut TestAppCo
// trigger stack frames to loaded // trigger stack frames to loaded
active_debug_session_panel(workspace, cx).update(cx, |debug_panel_item, cx| { active_debug_session_panel(workspace, cx).update(cx, |debug_panel_item, cx| {
let stack_frame_list = debug_panel_item let stack_frame_list = debug_panel_item
.mode() .running_state()
.as_running()
.unwrap()
.update(cx, |state, _| state.stack_frame_list().clone()); .update(cx, |state, _| state.stack_frame_list().clone());
stack_frame_list.update(cx, |stack_frame_list, cx| { 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| { active_debug_session_panel(workspace, cx).update_in(cx, |debug_panel_item, window, cx| {
let stack_frame_list = debug_panel_item let stack_frame_list = debug_panel_item
.mode() .running_state()
.as_running()
.unwrap()
.update(cx, |state, _| state.stack_frame_list().clone()); .update(cx, |state, _| state.stack_frame_list().clone());
stack_frame_list.update(cx, |stack_frame_list, cx| { stack_frame_list.update(cx, |stack_frame_list, cx| {

View file

@ -183,10 +183,7 @@ async fn test_basic_fetch_initial_scope_and_variables(
let running_state = let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window); cx.focus_self(window);
item.mode() item.running_state().clone()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
cx.run_until_parked(); cx.run_until_parked();
@ -427,10 +424,7 @@ async fn test_fetch_variables_for_multiple_scopes(
let running_state = let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window); cx.focus_self(window);
item.mode() item.running_state().clone()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
cx.run_until_parked(); cx.run_until_parked();
@ -710,11 +704,7 @@ async fn test_keyboard_navigation(executor: BackgroundExecutor, cx: &mut TestApp
let running_state = let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window); cx.focus_self(window);
let running = item let running = item.running_state().clone();
.mode()
.as_running()
.expect("Session should be running by this point")
.clone();
let variable_list = running.read_with(cx, |state, _| state.variable_list().clone()); let variable_list = running.read_with(cx, |state, _| state.variable_list().clone());
variable_list.update(cx, |_, cx| cx.focus_self(window)); 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(); cx.run_until_parked();
let running_state = active_debug_session_panel(workspace, cx).update_in(cx, |item, _, _| { let running_state = active_debug_session_panel(workspace, cx).update_in(cx, |item, _, _| {
let state = item let state = item.running_state().clone();
.mode()
.as_running()
.expect("Session should be running by this point")
.clone();
state state
}); });
@ -1742,10 +1728,7 @@ async fn test_it_fetches_scopes_variables_when_you_select_a_stack_frame(
let running_state = let running_state =
active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| { active_debug_session_panel(workspace, cx).update_in(cx, |item, window, cx| {
cx.focus_self(window); cx.focus_self(window);
item.mode() item.running_state().clone()
.as_running()
.expect("Session should be running by this point")
.clone()
}); });
running_state.update(cx, |running_state, cx| { running_state.update(cx, |running_state, cx| {