use crate::persistence::DebuggerPaneItem;use crate::session::DebugSession;use crate::{ ClearAllBreakpoints, Continue, Detach, FocusBreakpointList, FocusConsole, FocusFrames, FocusLoadedSources, FocusModules, FocusTerminal, FocusVariables, Pause, Restart, StepBack, StepInto, StepOut, StepOver, Stop, ToggleIgnoreBreakpoints, persistence,};use anyhow::Result;use command_palette_hooks::CommandPaletteFilter;use dap::adapters::DebugAdapterName;use dap::debugger_settings::DebugPanelDockPosition;use dap::{ ContinuedEvent, LoadedSourceEvent, ModuleEvent, OutputEvent, StoppedEvent, ThreadEvent, client::SessionId, debugger_settings::DebuggerSettings,};use dap::{StartDebuggingRequestArguments, adapters::DebugTaskDefinition};use gpui::{ Action, App, AsyncWindowContext, Context, DismissEvent, Entity, EntityId, EventEmitter, FocusHandle, Focusable, MouseButton, MouseDownEvent, Point, Subscription, Task, WeakEntity, actions, anchored, deferred,}; use language::Buffer;use project::debugger::session::{Session, SessionStateEvent};use project::{Fs, WorktreeId};use project::{Project, debugger::session::ThreadStatus};use rpc::proto::{self};use settings::Settings;use std::any::TypeId;use std::sync::Arc;use task::{DebugScenario, TaskContext};use ui::{ContextMenu, Divider, DropdownMenu, Tooltip, prelude::*};use workspace::SplitDirection;use workspace::{ Pane, Workspace, dock::{DockPosition, Panel, PanelEvent},}; pub enum DebugPanelEvent { Exited(SessionId), Terminated(SessionId), Stopped { client_id: SessionId, event: StoppedEvent, go_to_stack_frame: bool, }, Thread((SessionId, ThreadEvent)), Continued((SessionId, ContinuedEvent)), Output((SessionId, OutputEvent)), Module((SessionId, ModuleEvent)), LoadedSource((SessionId, LoadedSourceEvent)), ClientShutdown(SessionId), CapabilitiesChanged(SessionId),} actions!(debug_panel, [ToggleFocus]);pub struct DebugPanel { size: Pixels, sessions: Vec<Entity<DebugSession>>, active_session: Option<Entity<DebugSession>>, /// This represents the last debug definition that was created in the new session modal pub(crate) past_debug_definition: Option<DebugTaskDefinition>, project: Entity<Project>, workspace: WeakEntity<Workspace>, focus_handle: FocusHandle, context_menu: Option<(Entity<ContextMenu>, Point<Pixels>, Subscription)>, fs: Arc<dyn Fs>,} impl DebugPanel { pub fn new( workspace: &Workspace, _window: &mut Window, cx: &mut Context<Workspace>, ) -> Entity<Self> { cx.new(|cx| { let project = workspace.project().clone(); let debug_panel = Self { size: px(300.), sessions: vec![], active_session: None, past_debug_definition: None, focus_handle: cx.focus_handle(), project, workspace: workspace.weak_handle(), context_menu: None, fs: workspace.app_state().fs.clone(), }; debug_panel }) } fn filter_action_types(&self, cx: &mut App) { let (has_active_session, supports_restart, support_step_back, status) = self .active_session() .map(|item| { let running = item.read(cx).running_state().clone(); let caps = running.read(cx).capabilities(cx); ( !running.read(cx).session().read(cx).is_terminated(), caps.supports_restart_request.unwrap_or_default(), caps.supports_step_back.unwrap_or_default(), running.read(cx).thread_status(cx), ) }) .unwrap_or((false, false, false, None)); let filter = CommandPaletteFilter::global_mut(cx); let debugger_action_types = [ TypeId::of::<Detach>(), TypeId::of::<Stop>(), TypeId::of::<ToggleIgnoreBreakpoints>(), ]; let running_action_types = [TypeId::of::<Pause>()]; let stopped_action_type = [ TypeId::of::<Continue>(), TypeId::of::<StepOver>(), TypeId::of::<StepInto>(), TypeId::of::<StepOut>(), TypeId::of::<editor::actions::DebuggerRunToCursor>(), TypeId::of::<editor::actions::DebuggerEvaluateSelectedText>(), ]; let step_back_action_type = [TypeId::of::<StepBack>()]; let restart_action_type = [TypeId::of::<Restart>()]; if has_active_session { filter.show_action_types(debugger_action_types.iter()); if supports_restart { filter.show_action_types(restart_action_type.iter()); } else { filter.hide_action_types(&restart_action_type); } if support_step_back { filter.show_action_types(step_back_action_type.iter()); } else { filter.hide_action_types(&step_back_action_type); } match status { Some(ThreadStatus::Running) => { filter.show_action_types(running_action_types.iter()); filter.hide_action_types(&stopped_action_type); } Some(ThreadStatus::Stopped) => { filter.show_action_types(stopped_action_type.iter()); filter.hide_action_types(&running_action_types); } _ => { filter.hide_action_types(&running_action_types); filter.hide_action_types(&stopped_action_type); } } } else { // show only the `debug: start` filter.hide_action_types(&debugger_action_types); filter.hide_action_types(&step_back_action_type); filter.hide_action_types(&restart_action_type); filter.hide_action_types(&running_action_types); filter.hide_action_types(&stopped_action_type); } } pub fn load( workspace: WeakEntity<Workspace>, cx: &mut AsyncWindowContext, ) -> Task<Result<Entity<Self>>> { cx.spawn(async move |cx| { workspace.update_in(cx, |workspace, window, cx| { let debug_panel = DebugPanel::new(workspace, window, cx); workspace.register_action(|workspace, _: &ClearAllBreakpoints, _, cx| { workspace.project().read(cx).breakpoint_store().update( cx, |breakpoint_store, cx| { breakpoint_store.clear_breakpoints(cx); }, ) }); cx.observe_new::<DebugPanel>(|debug_panel, _, cx| { Self::filter_action_types(debug_panel, cx); }) .detach(); cx.observe(&debug_panel, |_, debug_panel, cx| { debug_panel.update(cx, |debug_panel, cx| { Self::filter_action_types(debug_panel, cx); }); }) .detach(); workspace.set_debugger_provider(DebuggerProvider(debug_panel.clone())); debug_panel }) }) } pub fn start_session( &mut self, scenario: DebugScenario, task_context: TaskContext, active_buffer: Option<Entity<Buffer>>, worktree_id: Option<WorktreeId>, window: &mut Window, cx: &mut Context<Self>, ) { let dap_store = self.project.read(cx).dap_store(); let session = dap_store.update(cx, |dap_store, cx| { dap_store.new_session( scenario.label.clone(), DebugAdapterName(scenario.adapter.clone()), None, cx, ) }); let task = cx.spawn_in(window, { let session = session.clone(); async move |this, cx| { let debug_session = Self::register_session(this.clone(), session.clone(), cx).await?; let definition = debug_session .update_in(cx, |debug_session, window, cx| { debug_session.running_state().update(cx, |running, cx| { running.resolve_scenario( scenario, task_context, active_buffer, worktree_id, window, cx, ) }) })? .await?; dap_store .update(cx, |dap_store, cx| { dap_store.boot_session(session.clone(), definition, cx) })? .await } }); cx.spawn(async move |_, cx| { if let Err(error) = task.await { session .update(cx, |session, cx| { session .console_output(cx) .unbounded_send(format!("error: {}", error)) .ok(); session.shutdown(cx) })? .await; } anyhow::Ok(()) }) .detach_and_log_err(cx); } async fn register_session( this: WeakEntity<Self>, session: Entity<Session>, cx: &mut AsyncWindowContext, ) -> Result<Entity<DebugSession>> { let adapter_name = session.update(cx, |session, _| session.adapter())?; this.update_in(cx, |_, window, cx| { cx.subscribe_in( &session, window, move |this, session, event: &SessionStateEvent, window, cx| match event { SessionStateEvent::Restart => { this.handle_restart_request(session.clone(), window, cx); } SessionStateEvent::SpawnChildSession { request } => { this.handle_start_debugging_request(request, session.clone(), window, cx); } _ => {} }, ) .detach(); }) .ok(); let serialized_layout = persistence::get_serialized_layout(adapter_name).await; let (debug_session, workspace) = this.update_in(cx, |this, window, cx| { this.sessions.retain(|session| { session .read(cx) .running_state() .read(cx) .session() .read(cx) .is_terminated() }); let debug_session = DebugSession::running( this.project.clone(), this.workspace.clone(), session, cx.weak_entity(), serialized_layout, this.position(window, cx).axis(), window, cx, ); // 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 cx.observe( &debug_session.read(cx).running_state().clone(), |_, _, cx| cx.notify(), ) .detach(); this.sessions.push(debug_session.clone()); this.activate_session(debug_session.clone(), window, cx); (debug_session, this.workspace.clone()) })?; workspace.update_in(cx, |workspace, window, cx| { workspace.focus_panel::<Self>(window, cx); })?; Ok(debug_session) } fn handle_restart_request( &mut self, mut curr_session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>, ) { while let Some(parent_session) = curr_session.read_with(cx, |session, _| session.parent_session().cloned()) { curr_session = parent_session; } let Some(worktree) = curr_session.read(cx).worktree() else { log::error!("Attempted to start a child session from non local debug session"); return; }; let dap_store_handle = self.project.read(cx).dap_store().clone(); let label = curr_session.read(cx).label().clone(); let adapter = curr_session.read(cx).adapter().clone(); let binary = curr_session.read(cx).binary().clone(); let task = curr_session.update(cx, |session, cx| session.shutdown(cx)); cx.spawn_in(window, async move |this, cx| { task.await; let (session, task) = dap_store_handle.update(cx, |dap_store, cx| { let session = dap_store.new_session(label, adapter, None, cx); let task = session.update(cx, |session, cx| { session.boot(binary, worktree, dap_store_handle.downgrade(), cx) }); (session, task) })?; Self::register_session(this, session, cx).await?; task.await }) .detach_and_log_err(cx); } pub fn handle_start_debugging_request( &mut self, request: &StartDebuggingRequestArguments, parent_session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>, ) { let Some(worktree) = parent_session.read(cx).worktree() else { log::error!("Attempted to start a child session from non local debug session"); return; }; let dap_store_handle = self.project.read(cx).dap_store().clone(); let label = parent_session.read(cx).label().clone(); let adapter = parent_session.read(cx).adapter().clone(); let mut binary = parent_session.read(cx).binary().clone(); binary.request_args = request.clone(); cx.spawn_in(window, async move |this, cx| { let (session, task) = dap_store_handle.update(cx, |dap_store, cx| { let session = dap_store.new_session(label, adapter, Some(parent_session.clone()), cx); let task = session.update(cx, |session, cx| { session.boot(binary, worktree, dap_store_handle.downgrade(), cx) }); (session, task) })?; Self::register_session(this, session, cx).await?; task.await }) .detach_and_log_err(cx); } pub fn active_session(&self) -> Option<Entity<DebugSession>> { self.active_session.clone() } fn close_session(&mut self, entity_id: EntityId, window: &mut Window, cx: &mut Context<Self>) { let Some(session) = self .sessions .iter() .find(|other| entity_id == other.entity_id()) .cloned() else { return; }; session.update(cx, |this, cx| { this.running_state().update(cx, |this, cx| { this.serialize_layout(window, 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()) }) .unwrap_or_default(); 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) = this .active_session .as_ref() .map(|session| session.entity_id()) { if active_session_id == entity_id { this.active_session = this.sessions.first().cloned(); } } cx.notify() }) .ok(); }) .detach(); } fn sessions_drop_down_menu( &self, active_session: &Entity<DebugSession>, window: &mut Window, cx: &mut Context<Self>, ) -> DropdownMenu { let sessions = self.sessions.clone(); let weak = cx.weak_entity(); let label = active_session.read(cx).label_element(cx); DropdownMenu::new_with_element( "debugger-session-list", label, ContextMenu::build(window, cx, move |mut this, _, cx| { let context_menu = cx.weak_entity(); for session in sessions.into_iter() { let weak_session = session.downgrade(); let weak_session_id = weak_session.entity_id(); this = this.custom_entry( { let weak = weak.clone(); let context_menu = context_menu.clone(); move |_, cx| { weak_session .read_with(cx, |session, cx| { let context_menu = context_menu.clone(); let id: SharedString = format!("debug-session-{}", session.session_id(cx).0) .into(); h_flex() .w_full() .group(id.clone())Lines 1–500 of 1288. Load more
use crate::persistence::DebuggerPaneItem; use crate::session::DebugSession; use crate::{ ClearAllBreakpoints, Continue, Detach, FocusBreakpointList, FocusConsole, FocusFrames, FocusLoadedSources, FocusModules, FocusTerminal, FocusVariables, Pause, Restart, StepBack, StepInto, StepOut, StepOver, Stop, ToggleIgnoreBreakpoints, persistence, }; use anyhow::Result; use command_palette_hooks::CommandPaletteFilter; use dap::adapters::DebugAdapterName; use dap::debugger_settings::DebugPanelDockPosition; use dap::{ ContinuedEvent, LoadedSourceEvent, ModuleEvent, OutputEvent, StoppedEvent, ThreadEvent, client::SessionId, debugger_settings::DebuggerSettings, }; use dap::{StartDebuggingRequestArguments, adapters::DebugTaskDefinition}; use gpui::{ Action, App, AsyncWindowContext, Context, DismissEvent, Entity, EntityId, EventEmitter, FocusHandle, Focusable, MouseButton, MouseDownEvent, Point, Subscription, Task, WeakEntity, actions, anchored, deferred, }; use language::Buffer; use project::debugger::session::{Session, SessionStateEvent}; use project::{Fs, WorktreeId}; use project::{Project, debugger::session::ThreadStatus}; use rpc::proto::{self}; use settings::Settings; use std::any::TypeId; use std::sync::Arc; use task::{DebugScenario, TaskContext}; use ui::{ContextMenu, Divider, DropdownMenu, Tooltip, prelude::*}; use workspace::SplitDirection; use workspace::{ Pane, Workspace, dock::{DockPosition, Panel, PanelEvent}, }; pub enum DebugPanelEvent { Exited(SessionId), Terminated(SessionId), Stopped { client_id: SessionId, event: StoppedEvent, go_to_stack_frame: bool, }, Thread((SessionId, ThreadEvent)), Continued((SessionId, ContinuedEvent)), Output((SessionId, OutputEvent)), Module((SessionId, ModuleEvent)), LoadedSource((SessionId, LoadedSourceEvent)), ClientShutdown(SessionId), CapabilitiesChanged(SessionId), } actions!(debug_panel, [ToggleFocus]); pub struct DebugPanel { size: Pixels, sessions: Vec<Entity<DebugSession>>, active_session: Option<Entity<DebugSession>>, /// This represents the last debug definition that was created in the new session modal pub(crate) past_debug_definition: Option<DebugTaskDefinition>, project: Entity<Project>, workspace: WeakEntity<Workspace>, focus_handle: FocusHandle, context_menu: Option<(Entity<ContextMenu>, Point<Pixels>, Subscription)>, fs: Arc<dyn Fs>, } impl DebugPanel { pub fn new( workspace: &Workspace, _window: &mut Window, cx: &mut Context<Workspace>, ) -> Entity<Self> { cx.new(|cx| { let project = workspace.project().clone(); let debug_panel = Self { size: px(300.), sessions: vec![], active_session: None, past_debug_definition: None, focus_handle: cx.focus_handle(), project, workspace: workspace.weak_handle(), context_menu: None, fs: workspace.app_state().fs.clone(), }; debug_panel }) } fn filter_action_types(&self, cx: &mut App) { let (has_active_session, supports_restart, support_step_back, status) = self .active_session() .map(|item| { let running = item.read(cx).running_state().clone(); let caps = running.read(cx).capabilities(cx); ( !running.read(cx).session().read(cx).is_terminated(), caps.supports_restart_request.unwrap_or_default(), caps.supports_step_back.unwrap_or_default(), running.read(cx).thread_status(cx), ) }) .unwrap_or((false, false, false, None)); let filter = CommandPaletteFilter::global_mut(cx); let debugger_action_types = [ TypeId::of::<Detach>(), TypeId::of::<Stop>(), TypeId::of::<ToggleIgnoreBreakpoints>(), ]; let running_action_types = [TypeId::of::<Pause>()]; let stopped_action_type = [ TypeId::of::<Continue>(), TypeId::of::<StepOver>(), TypeId::of::<StepInto>(), TypeId::of::<StepOut>(), TypeId::of::<editor::actions::DebuggerRunToCursor>(), TypeId::of::<editor::actions::DebuggerEvaluateSelectedText>(), ]; let step_back_action_type = [TypeId::of::<StepBack>()]; let restart_action_type = [TypeId::of::<Restart>()]; if has_active_session { filter.show_action_types(debugger_action_types.iter()); if supports_restart { filter.show_action_types(restart_action_type.iter()); } else { filter.hide_action_types(&restart_action_type); } if support_step_back { filter.show_action_types(step_back_action_type.iter()); } else { filter.hide_action_types(&step_back_action_type); } match status { Some(ThreadStatus::Running) => { filter.show_action_types(running_action_types.iter()); filter.hide_action_types(&stopped_action_type); } Some(ThreadStatus::Stopped) => { filter.show_action_types(stopped_action_type.iter()); filter.hide_action_types(&running_action_types); } _ => { filter.hide_action_types(&running_action_types); filter.hide_action_types(&stopped_action_type); } } } else { // show only the `debug: start` filter.hide_action_types(&debugger_action_types); filter.hide_action_types(&step_back_action_type); filter.hide_action_types(&restart_action_type); filter.hide_action_types(&running_action_types); filter.hide_action_types(&stopped_action_type); } } pub fn load( workspace: WeakEntity<Workspace>, cx: &mut AsyncWindowContext, ) -> Task<Result<Entity<Self>>> { cx.spawn(async move |cx| { workspace.update_in(cx, |workspace, window, cx| { let debug_panel = DebugPanel::new(workspace, window, cx); workspace.register_action(|workspace, _: &ClearAllBreakpoints, _, cx| { workspace.project().read(cx).breakpoint_store().update( cx, |breakpoint_store, cx| { breakpoint_store.clear_breakpoints(cx); }, ) }); cx.observe_new::<DebugPanel>(|debug_panel, _, cx| { Self::filter_action_types(debug_panel, cx); }) .detach(); cx.observe(&debug_panel, |_, debug_panel, cx| { debug_panel.update(cx, |debug_panel, cx| { Self::filter_action_types(debug_panel, cx); }); }) .detach(); workspace.set_debugger_provider(DebuggerProvider(debug_panel.clone())); debug_panel }) }) } pub fn start_session( &mut self, scenario: DebugScenario, task_context: TaskContext, active_buffer: Option<Entity<Buffer>>, worktree_id: Option<WorktreeId>, window: &mut Window, cx: &mut Context<Self>, ) { let dap_store = self.project.read(cx).dap_store(); let session = dap_store.update(cx, |dap_store, cx| { dap_store.new_session( scenario.label.clone(), DebugAdapterName(scenario.adapter.clone()), None, cx, ) }); let task = cx.spawn_in(window, { let session = session.clone(); async move |this, cx| { let debug_session = Self::register_session(this.clone(), session.clone(), cx).await?; let definition = debug_session .update_in(cx, |debug_session, window, cx| { debug_session.running_state().update(cx, |running, cx| { running.resolve_scenario( scenario, task_context, active_buffer, worktree_id, window, cx, ) }) })? .await?; dap_store .update(cx, |dap_store, cx| { dap_store.boot_session(session.clone(), definition, cx) })? .await } }); cx.spawn(async move |_, cx| { if let Err(error) = task.await { session .update(cx, |session, cx| { session .console_output(cx) .unbounded_send(format!("error: {}", error)) .ok(); session.shutdown(cx) })? .await; } anyhow::Ok(()) }) .detach_and_log_err(cx); } async fn register_session( this: WeakEntity<Self>, session: Entity<Session>, cx: &mut AsyncWindowContext, ) -> Result<Entity<DebugSession>> { let adapter_name = session.update(cx, |session, _| session.adapter())?; this.update_in(cx, |_, window, cx| { cx.subscribe_in( &session, window, move |this, session, event: &SessionStateEvent, window, cx| match event { SessionStateEvent::Restart => { this.handle_restart_request(session.clone(), window, cx); } SessionStateEvent::SpawnChildSession { request } => { this.handle_start_debugging_request(request, session.clone(), window, cx); } _ => {} }, ) .detach(); }) .ok(); let serialized_layout = persistence::get_serialized_layout(adapter_name).await; let (debug_session, workspace) = this.update_in(cx, |this, window, cx| { this.sessions.retain(|session| { session .read(cx) .running_state() .read(cx) .session() .read(cx) .is_terminated() }); let debug_session = DebugSession::running( this.project.clone(), this.workspace.clone(), session, cx.weak_entity(), serialized_layout, this.position(window, cx).axis(), window, cx, ); // 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 cx.observe( &debug_session.read(cx).running_state().clone(), |_, _, cx| cx.notify(), ) .detach(); this.sessions.push(debug_session.clone()); this.activate_session(debug_session.clone(), window, cx); (debug_session, this.workspace.clone()) })?; workspace.update_in(cx, |workspace, window, cx| { workspace.focus_panel::<Self>(window, cx); })?; Ok(debug_session) } fn handle_restart_request( &mut self, mut curr_session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>, ) { while let Some(parent_session) = curr_session.read_with(cx, |session, _| session.parent_session().cloned()) { curr_session = parent_session; } let Some(worktree) = curr_session.read(cx).worktree() else { log::error!("Attempted to start a child session from non local debug session"); return; }; let dap_store_handle = self.project.read(cx).dap_store().clone(); let label = curr_session.read(cx).label().clone(); let adapter = curr_session.read(cx).adapter().clone(); let binary = curr_session.read(cx).binary().clone(); let task = curr_session.update(cx, |session, cx| session.shutdown(cx)); cx.spawn_in(window, async move |this, cx| { task.await; let (session, task) = dap_store_handle.update(cx, |dap_store, cx| { let session = dap_store.new_session(label, adapter, None, cx); let task = session.update(cx, |session, cx| { session.boot(binary, worktree, dap_store_handle.downgrade(), cx) }); (session, task) })?; Self::register_session(this, session, cx).await?; task.await }) .detach_and_log_err(cx); } pub fn handle_start_debugging_request( &mut self, request: &StartDebuggingRequestArguments, parent_session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>, ) { let Some(worktree) = parent_session.read(cx).worktree() else { log::error!("Attempted to start a child session from non local debug session"); return; }; let dap_store_handle = self.project.read(cx).dap_store().clone(); let label = parent_session.read(cx).label().clone(); let adapter = parent_session.read(cx).adapter().clone(); let mut binary = parent_session.read(cx).binary().clone(); binary.request_args = request.clone(); cx.spawn_in(window, async move |this, cx| { let (session, task) = dap_store_handle.update(cx, |dap_store, cx| { let session = dap_store.new_session(label, adapter, Some(parent_session.clone()), cx); let task = session.update(cx, |session, cx| { session.boot(binary, worktree, dap_store_handle.downgrade(), cx) }); (session, task) })?; Self::register_session(this, session, cx).await?; task.await }) .detach_and_log_err(cx); } pub fn active_session(&self) -> Option<Entity<DebugSession>> { self.active_session.clone() } fn close_session(&mut self, entity_id: EntityId, window: &mut Window, cx: &mut Context<Self>) { let Some(session) = self .sessions .iter() .find(|other| entity_id == other.entity_id()) .cloned() else { return; }; session.update(cx, |this, cx| { this.running_state().update(cx, |this, cx| { this.serialize_layout(window, 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()) }) .unwrap_or_default(); 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) = this .active_session .as_ref() .map(|session| session.entity_id()) { if active_session_id == entity_id { this.active_session = this.sessions.first().cloned(); } } cx.notify() }) .ok(); }) .detach(); } fn sessions_drop_down_menu( &self, active_session: &Entity<DebugSession>, window: &mut Window, cx: &mut Context<Self>, ) -> DropdownMenu { let sessions = self.sessions.clone(); let weak = cx.weak_entity(); let label = active_session.read(cx).label_element(cx); DropdownMenu::new_with_element( "debugger-session-list", label, ContextMenu::build(window, cx, move |mut this, _, cx| { let context_menu = cx.weak_entity(); for session in sessions.into_iter() { let weak_session = session.downgrade(); let weak_session_id = weak_session.entity_id(); this = this.custom_entry( { let weak = weak.clone(); let context_menu = context_menu.clone(); move |_, cx| { weak_session .read_with(cx, |session, cx| { let context_menu = context_menu.clone(); let id: SharedString = format!("debug-session-{}", session.session_id(cx).0) .into(); h_flex() .w_full() .group(id.clone())