debugger_ui.rs

  1use dap::debugger_settings::DebuggerSettings;
  2use debugger_panel::{DebugPanel, ToggleFocus};
  3use feature_flags::{Debugger, FeatureFlagViewExt};
  4use gpui::{App, actions};
  5use new_session_modal::NewSessionModal;
  6use session::DebugSession;
  7use settings::Settings;
  8use workspace::{ShutdownDebugAdapters, Workspace};
  9
 10pub mod attach_modal;
 11pub mod debugger_panel;
 12mod new_session_modal;
 13pub(crate) mod session;
 14
 15#[cfg(test)]
 16pub mod tests;
 17
 18actions!(
 19    debugger,
 20    [
 21        Start,
 22        Continue,
 23        Disconnect,
 24        Pause,
 25        Restart,
 26        StepInto,
 27        StepOver,
 28        StepOut,
 29        StepBack,
 30        Stop,
 31        ToggleIgnoreBreakpoints,
 32        ClearAllBreakpoints,
 33        CreateDebuggingSession,
 34    ]
 35);
 36
 37pub fn init(cx: &mut App) {
 38    DebuggerSettings::register(cx);
 39    workspace::FollowableViewRegistry::register::<DebugSession>(cx);
 40
 41    cx.observe_new(|_: &mut Workspace, window, cx| {
 42        let Some(window) = window else {
 43            return;
 44        };
 45
 46        cx.when_flag_enabled::<Debugger>(window, |workspace, _, _| {
 47            workspace
 48                .register_action(|workspace, _: &ToggleFocus, window, cx| {
 49                    workspace.toggle_panel_focus::<DebugPanel>(window, cx);
 50                })
 51                .register_action(|workspace, _: &Pause, _, cx| {
 52                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
 53                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
 54                            panel
 55                                .active_session(cx)
 56                                .and_then(|session| session.read(cx).mode().as_running().cloned())
 57                        }) {
 58                            active_item.update(cx, |item, cx| item.pause_thread(cx))
 59                        }
 60                    }
 61                })
 62                .register_action(|workspace, _: &Restart, _, cx| {
 63                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
 64                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
 65                            panel
 66                                .active_session(cx)
 67                                .and_then(|session| session.read(cx).mode().as_running().cloned())
 68                        }) {
 69                            active_item.update(cx, |item, cx| item.restart_session(cx))
 70                        }
 71                    }
 72                })
 73                .register_action(|workspace, _: &StepInto, _, cx| {
 74                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
 75                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
 76                            panel
 77                                .active_session(cx)
 78                                .and_then(|session| session.read(cx).mode().as_running().cloned())
 79                        }) {
 80                            active_item.update(cx, |item, cx| item.step_in(cx))
 81                        }
 82                    }
 83                })
 84                .register_action(|workspace, _: &StepOver, _, cx| {
 85                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
 86                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
 87                            panel
 88                                .active_session(cx)
 89                                .and_then(|session| session.read(cx).mode().as_running().cloned())
 90                        }) {
 91                            active_item.update(cx, |item, cx| item.step_over(cx))
 92                        }
 93                    }
 94                })
 95                .register_action(|workspace, _: &StepBack, _, cx| {
 96                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
 97                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
 98                            panel
 99                                .active_session(cx)
100                                .and_then(|session| session.read(cx).mode().as_running().cloned())
101                        }) {
102                            active_item.update(cx, |item, cx| item.step_back(cx))
103                        }
104                    }
105                })
106                .register_action(|workspace, _: &Stop, _, cx| {
107                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
108                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
109                            panel
110                                .active_session(cx)
111                                .and_then(|session| session.read(cx).mode().as_running().cloned())
112                        }) {
113                            active_item.update(cx, |item, cx| item.stop_thread(cx))
114                        }
115                    }
116                })
117                .register_action(|workspace, _: &ToggleIgnoreBreakpoints, _, cx| {
118                    if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
119                        if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
120                            panel
121                                .active_session(cx)
122                                .and_then(|session| session.read(cx).mode().as_running().cloned())
123                        }) {
124                            active_item.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx))
125                        }
126                    }
127                })
128                .register_action(
129                    |workspace: &mut Workspace, _: &ShutdownDebugAdapters, _window, cx| {
130                        workspace.project().update(cx, |project, cx| {
131                            project.dap_store().update(cx, |store, cx| {
132                                store.shutdown_sessions(cx).detach();
133                            })
134                        })
135                    },
136                )
137                .register_action(
138                    |workspace: &mut Workspace, _: &CreateDebuggingSession, window, cx| {
139                        if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
140                            let weak_panel = debug_panel.downgrade();
141                            let weak_workspace = cx.weak_entity();
142
143                            workspace.toggle_modal(window, cx, |window, cx| {
144                                NewSessionModal::new(
145                                    debug_panel.read(cx).past_debug_definition.clone(),
146                                    weak_panel,
147                                    weak_workspace,
148                                    window,
149                                    cx,
150                                )
151                            });
152                        }
153                    },
154                );
155        })
156    })
157    .detach();
158}