1use dap::debugger_settings::DebuggerSettings;
2use debugger_panel::{DebugPanel, ToggleFocus};
3use feature_flags::{Debugger, FeatureFlagViewExt};
4use gpui::App;
5use session::DebugSession;
6use settings::Settings;
7use workspace::{
8 Pause, Restart, ShutdownDebugAdapters, StepBack, StepInto, StepOver, Stop,
9 ToggleIgnoreBreakpoints, Workspace,
10};
11
12pub mod attach_modal;
13pub mod debugger_panel;
14pub mod session;
15
16#[cfg(test)]
17mod tests;
18
19pub fn init(cx: &mut App) {
20 DebuggerSettings::register(cx);
21 workspace::FollowableViewRegistry::register::<DebugSession>(cx);
22
23 cx.observe_new(|_: &mut Workspace, window, cx| {
24 let Some(window) = window else {
25 return;
26 };
27
28 cx.when_flag_enabled::<Debugger>(window, |workspace, _, _| {
29 workspace
30 .register_action(|workspace, _: &ToggleFocus, window, cx| {
31 workspace.toggle_panel_focus::<DebugPanel>(window, cx);
32 })
33 .register_action(|workspace, _: &Pause, _, cx| {
34 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
35
36 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
37 panel
38 .active_session(cx)
39 .and_then(|session| session.read(cx).mode().as_running().cloned())
40 }) {
41 active_item.update(cx, |item, cx| item.pause_thread(cx))
42 }
43 })
44 .register_action(|workspace, _: &Restart, _, cx| {
45 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
46
47 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
48 panel
49 .active_session(cx)
50 .and_then(|session| session.read(cx).mode().as_running().cloned())
51 }) {
52 active_item.update(cx, |item, cx| item.restart_session(cx))
53 }
54 })
55 .register_action(|workspace, _: &StepInto, _, cx| {
56 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
57
58 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
59 panel
60 .active_session(cx)
61 .and_then(|session| session.read(cx).mode().as_running().cloned())
62 }) {
63 active_item.update(cx, |item, cx| item.step_in(cx))
64 }
65 })
66 .register_action(|workspace, _: &StepOver, _, cx| {
67 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
68
69 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
70 panel
71 .active_session(cx)
72 .and_then(|session| session.read(cx).mode().as_running().cloned())
73 }) {
74 active_item.update(cx, |item, cx| item.step_over(cx))
75 }
76 })
77 .register_action(|workspace, _: &StepBack, _, cx| {
78 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
79
80 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
81 panel
82 .active_session(cx)
83 .and_then(|session| session.read(cx).mode().as_running().cloned())
84 }) {
85 active_item.update(cx, |item, cx| item.step_back(cx))
86 }
87 })
88 .register_action(|workspace, _: &Stop, _, cx| {
89 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
90
91 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
92 panel
93 .active_session(cx)
94 .and_then(|session| session.read(cx).mode().as_running().cloned())
95 }) {
96 active_item.update(cx, |item, cx| item.stop_thread(cx))
97 }
98 })
99 .register_action(|workspace, _: &ToggleIgnoreBreakpoints, _, cx| {
100 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
101
102 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
103 panel
104 .active_session(cx)
105 .and_then(|session| session.read(cx).mode().as_running().cloned())
106 }) {
107 active_item.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx))
108 }
109 })
110 .register_action(
111 |workspace: &mut Workspace, _: &ShutdownDebugAdapters, _window, cx| {
112 workspace.project().update(cx, |project, cx| {
113 project.dap_store().update(cx, |store, cx| {
114 store.shutdown_sessions(cx).detach();
115 })
116 })
117 },
118 );
119 })
120 })
121 .detach();
122}