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 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
53
54 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
55 panel
56 .active_session(cx)
57 .and_then(|session| session.read(cx).mode().as_running().cloned())
58 }) {
59 active_item.update(cx, |item, cx| item.pause_thread(cx))
60 }
61 })
62 .register_action(|workspace, _: &Restart, _, cx| {
63 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
64
65 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
66 panel
67 .active_session(cx)
68 .and_then(|session| session.read(cx).mode().as_running().cloned())
69 }) {
70 active_item.update(cx, |item, cx| item.restart_session(cx))
71 }
72 })
73 .register_action(|workspace, _: &StepInto, _, cx| {
74 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
75
76 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
77 panel
78 .active_session(cx)
79 .and_then(|session| session.read(cx).mode().as_running().cloned())
80 }) {
81 active_item.update(cx, |item, cx| item.step_in(cx))
82 }
83 })
84 .register_action(|workspace, _: &StepOver, _, cx| {
85 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
86
87 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
88 panel
89 .active_session(cx)
90 .and_then(|session| session.read(cx).mode().as_running().cloned())
91 }) {
92 active_item.update(cx, |item, cx| item.step_over(cx))
93 }
94 })
95 .register_action(|workspace, _: &StepBack, _, cx| {
96 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
97
98 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
99 panel
100 .active_session(cx)
101 .and_then(|session| session.read(cx).mode().as_running().cloned())
102 }) {
103 active_item.update(cx, |item, cx| item.step_back(cx))
104 }
105 })
106 .register_action(|workspace, _: &Stop, _, cx| {
107 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
108
109 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
110 panel
111 .active_session(cx)
112 .and_then(|session| session.read(cx).mode().as_running().cloned())
113 }) {
114 active_item.update(cx, |item, cx| item.stop_thread(cx))
115 }
116 })
117 .register_action(|workspace, _: &ToggleIgnoreBreakpoints, _, cx| {
118 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
119
120 if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
121 panel
122 .active_session(cx)
123 .and_then(|session| session.read(cx).mode().as_running().cloned())
124 }) {
125 active_item.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx))
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 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
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 .detach();
157}