1pub(crate) mod breakpoint_list;
2pub(crate) mod console;
3pub(crate) mod loaded_source_list;
4pub(crate) mod module_list;
5pub mod stack_frame_list;
6pub mod variable_list;
7
8use std::{any::Any, ops::ControlFlow, path::PathBuf, sync::Arc, time::Duration};
9
10use crate::persistence::{self, DebuggerPaneItem, SerializedLayout};
11
12use super::DebugPanelItemEvent;
13use anyhow::{Result, anyhow};
14use breakpoint_list::BreakpointList;
15use collections::{HashMap, IndexMap};
16use console::Console;
17use dap::{
18 Capabilities, RunInTerminalRequestArguments, Thread,
19 adapters::{DebugAdapterName, DebugTaskDefinition},
20 client::SessionId,
21 debugger_settings::DebuggerSettings,
22};
23use futures::{SinkExt, channel::mpsc};
24use gpui::{
25 Action as _, AnyView, AppContext, Axis, Entity, EntityId, EventEmitter, FocusHandle, Focusable,
26 NoAction, Pixels, Point, Subscription, Task, WeakEntity,
27};
28use language::Buffer;
29use loaded_source_list::LoadedSourceList;
30use module_list::ModuleList;
31use project::{
32 Project, WorktreeId,
33 debugger::session::{Session, SessionEvent, ThreadId, ThreadStatus},
34 terminals::TerminalKind,
35};
36use rpc::proto::ViewId;
37use serde_json::Value;
38use settings::Settings;
39use stack_frame_list::StackFrameList;
40use task::{
41 BuildTaskDefinition, DebugScenario, LaunchRequest, ShellBuilder, SpawnInTerminal, TaskContext,
42 substitute_variables_in_map, substitute_variables_in_str,
43};
44use terminal_view::TerminalView;
45use ui::{
46 ActiveTheme, AnyElement, App, ButtonCommon as _, Clickable as _, Context, ContextMenu,
47 Disableable, DropdownMenu, FluentBuilder, IconButton, IconName, IconSize, InteractiveElement,
48 IntoElement, Label, LabelCommon as _, ParentElement, Render, SharedString,
49 StatefulInteractiveElement, Styled, Tab, Tooltip, VisibleOnHover, VisualContext, Window, div,
50 h_flex, v_flex,
51};
52use util::ResultExt;
53use variable_list::VariableList;
54use workspace::{
55 ActivePaneDecorator, DraggedTab, Item, ItemHandle, Member, Pane, PaneGroup, SplitDirection,
56 Workspace, item::TabContentParams, move_item, pane::Event,
57};
58
59pub struct RunningState {
60 session: Entity<Session>,
61 thread_id: Option<ThreadId>,
62 focus_handle: FocusHandle,
63 _remote_id: Option<ViewId>,
64 workspace: WeakEntity<Workspace>,
65 session_id: SessionId,
66 variable_list: Entity<variable_list::VariableList>,
67 _subscriptions: Vec<Subscription>,
68 stack_frame_list: Entity<stack_frame_list::StackFrameList>,
69 loaded_sources_list: Entity<LoadedSourceList>,
70 pub debug_terminal: Entity<DebugTerminal>,
71 module_list: Entity<module_list::ModuleList>,
72 console: Entity<Console>,
73 breakpoint_list: Entity<BreakpointList>,
74 panes: PaneGroup,
75 active_pane: Option<Entity<Pane>>,
76 pane_close_subscriptions: HashMap<EntityId, Subscription>,
77 dock_axis: Axis,
78 _schedule_serialize: Option<Task<()>>,
79}
80
81impl Render for RunningState {
82 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
83 let zoomed_pane = self
84 .panes
85 .panes()
86 .into_iter()
87 .find(|pane| pane.read(cx).is_zoomed());
88
89 let active = self.panes.panes().into_iter().next();
90 let x = if let Some(ref zoomed_pane) = zoomed_pane {
91 zoomed_pane.update(cx, |pane, cx| pane.render(window, cx).into_any_element())
92 } else if let Some(active) = active {
93 self.panes
94 .render(
95 None,
96 &ActivePaneDecorator::new(active, &self.workspace),
97 window,
98 cx,
99 )
100 .into_any_element()
101 } else {
102 div().into_any_element()
103 };
104 let thread_status = self
105 .thread_id
106 .map(|thread_id| self.session.read(cx).thread_status(thread_id))
107 .unwrap_or(ThreadStatus::Exited);
108
109 self.variable_list.update(cx, |this, cx| {
110 this.disabled(thread_status != ThreadStatus::Stopped, cx);
111 });
112 v_flex()
113 .size_full()
114 .key_context("DebugSessionItem")
115 .track_focus(&self.focus_handle(cx))
116 .child(h_flex().flex_1().child(x))
117 }
118}
119
120pub(crate) struct SubView {
121 inner: AnyView,
122 pane_focus_handle: FocusHandle,
123 kind: DebuggerPaneItem,
124 show_indicator: Box<dyn Fn(&App) -> bool>,
125 hovered: bool,
126}
127
128impl SubView {
129 pub(crate) fn new(
130 pane_focus_handle: FocusHandle,
131 view: AnyView,
132 kind: DebuggerPaneItem,
133 show_indicator: Option<Box<dyn Fn(&App) -> bool>>,
134 cx: &mut App,
135 ) -> Entity<Self> {
136 cx.new(|_| Self {
137 kind,
138 inner: view,
139 pane_focus_handle,
140 show_indicator: show_indicator.unwrap_or(Box::new(|_| false)),
141 hovered: false,
142 })
143 }
144
145 pub(crate) fn view_kind(&self) -> DebuggerPaneItem {
146 self.kind
147 }
148}
149impl Focusable for SubView {
150 fn focus_handle(&self, _: &App) -> FocusHandle {
151 self.pane_focus_handle.clone()
152 }
153}
154impl EventEmitter<()> for SubView {}
155impl Item for SubView {
156 type Event = ();
157
158 /// This is used to serialize debugger pane layouts
159 /// A SharedString gets converted to a enum and back during serialization/deserialization.
160 fn tab_content_text(&self, _detail: usize, _cx: &App) -> SharedString {
161 self.kind.to_shared_string()
162 }
163
164 fn tab_content(
165 &self,
166 params: workspace::item::TabContentParams,
167 _: &Window,
168 cx: &App,
169 ) -> AnyElement {
170 let label = Label::new(self.kind.to_shared_string())
171 .size(ui::LabelSize::Small)
172 .color(params.text_color())
173 .line_height_style(ui::LineHeightStyle::UiLabel);
174
175 if !params.selected && self.show_indicator.as_ref()(cx) {
176 return h_flex()
177 .justify_between()
178 .child(ui::Indicator::dot())
179 .gap_2()
180 .child(label)
181 .into_any_element();
182 }
183
184 label.into_any_element()
185 }
186}
187
188impl Render for SubView {
189 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
190 v_flex()
191 .id(SharedString::from(format!(
192 "subview-container-{}",
193 self.kind.to_shared_string()
194 )))
195 .on_hover(cx.listener(|this, hovered, _, cx| {
196 this.hovered = *hovered;
197 cx.notify();
198 }))
199 .size_full()
200 // Add border unconditionally to prevent layout shifts on focus changes.
201 .border_1()
202 .when(self.pane_focus_handle.contains_focused(window, cx), |el| {
203 el.border_color(cx.theme().colors().pane_focused_border)
204 })
205 .child(self.inner.clone())
206 }
207}
208
209pub(crate) fn new_debugger_pane(
210 workspace: WeakEntity<Workspace>,
211 project: Entity<Project>,
212 window: &mut Window,
213 cx: &mut Context<RunningState>,
214) -> Entity<Pane> {
215 let weak_running = cx.weak_entity();
216 let custom_drop_handle = {
217 let workspace = workspace.clone();
218 let project = project.downgrade();
219 let weak_running = weak_running.clone();
220 move |pane: &mut Pane, any: &dyn Any, window: &mut Window, cx: &mut Context<Pane>| {
221 let Some(tab) = any.downcast_ref::<DraggedTab>() else {
222 return ControlFlow::Break(());
223 };
224 let Some(project) = project.upgrade() else {
225 return ControlFlow::Break(());
226 };
227 let this_pane = cx.entity().clone();
228 let item = if tab.pane == this_pane {
229 pane.item_for_index(tab.ix)
230 } else {
231 tab.pane.read(cx).item_for_index(tab.ix)
232 };
233 let Some(item) = item.filter(|item| item.downcast::<SubView>().is_some()) else {
234 return ControlFlow::Break(());
235 };
236
237 let source = tab.pane.clone();
238 let item_id_to_move = item.item_id();
239
240 let Ok(new_split_pane) = pane
241 .drag_split_direction()
242 .map(|split_direction| {
243 weak_running.update(cx, |running, cx| {
244 let new_pane =
245 new_debugger_pane(workspace.clone(), project.clone(), window, cx);
246 let _previous_subscription = running.pane_close_subscriptions.insert(
247 new_pane.entity_id(),
248 cx.subscribe_in(&new_pane, window, RunningState::handle_pane_event),
249 );
250 debug_assert!(_previous_subscription.is_none());
251 running
252 .panes
253 .split(&this_pane, &new_pane, split_direction)?;
254 anyhow::Ok(new_pane)
255 })
256 })
257 .transpose()
258 else {
259 return ControlFlow::Break(());
260 };
261
262 match new_split_pane.transpose() {
263 // Source pane may be the one currently updated, so defer the move.
264 Ok(Some(new_pane)) => cx
265 .spawn_in(window, async move |_, cx| {
266 cx.update(|window, cx| {
267 move_item(
268 &source,
269 &new_pane,
270 item_id_to_move,
271 new_pane.read(cx).active_item_index(),
272 window,
273 cx,
274 );
275 })
276 .ok();
277 })
278 .detach(),
279 // If we drop into existing pane or current pane,
280 // regular pane drop handler will take care of it,
281 // using the right tab index for the operation.
282 Ok(None) => return ControlFlow::Continue(()),
283 err @ Err(_) => {
284 err.log_err();
285 return ControlFlow::Break(());
286 }
287 };
288
289 ControlFlow::Break(())
290 }
291 };
292
293 let ret = cx.new(move |cx| {
294 let mut pane = Pane::new(
295 workspace.clone(),
296 project.clone(),
297 Default::default(),
298 None,
299 NoAction.boxed_clone(),
300 window,
301 cx,
302 );
303 let focus_handle = pane.focus_handle(cx);
304 pane.set_can_split(Some(Arc::new({
305 let weak_running = weak_running.clone();
306 move |pane, dragged_item, _window, cx| {
307 if let Some(tab) = dragged_item.downcast_ref::<DraggedTab>() {
308 let is_current_pane = tab.pane == cx.entity();
309 let Some(can_drag_away) = weak_running
310 .update(cx, |running_state, _| {
311 let current_panes = running_state.panes.panes();
312 !current_panes.contains(&&tab.pane)
313 || current_panes.len() > 1
314 || (!is_current_pane || pane.items_len() > 1)
315 })
316 .ok()
317 else {
318 return false;
319 };
320 if can_drag_away {
321 let item = if is_current_pane {
322 pane.item_for_index(tab.ix)
323 } else {
324 tab.pane.read(cx).item_for_index(tab.ix)
325 };
326 if let Some(item) = item {
327 return item.downcast::<SubView>().is_some();
328 }
329 }
330 }
331 false
332 }
333 })));
334 pane.display_nav_history_buttons(None);
335 pane.set_custom_drop_handle(cx, custom_drop_handle);
336 pane.set_should_display_tab_bar(|_, _| true);
337 pane.set_render_tab_bar_buttons(cx, |_, _, _| (None, None));
338 pane.set_render_tab_bar(cx, {
339 move |pane, window, cx| {
340 let active_pane_item = pane.active_item();
341 let pane_group_id: SharedString =
342 format!("pane-zoom-button-hover-{}", cx.entity_id()).into();
343 let is_hovered = active_pane_item.as_ref().map_or(false, |item| {
344 item.downcast::<SubView>()
345 .map_or(false, |this| this.read(cx).hovered)
346 });
347 h_flex()
348 .group(pane_group_id.clone())
349 .justify_between()
350 .bg(cx.theme().colors().tab_bar_background)
351 .border_b_1()
352 .px_2()
353 .border_color(cx.theme().colors().border)
354 .track_focus(&focus_handle)
355 .child(
356 h_flex()
357 .w_full()
358 .gap_1()
359 .h(Tab::container_height(cx))
360 .drag_over::<DraggedTab>(|bar, _, _, cx| {
361 bar.bg(cx.theme().colors().drop_target_background)
362 })
363 .on_drop(cx.listener(
364 move |this, dragged_tab: &DraggedTab, window, cx| {
365 this.drag_split_direction = None;
366 this.handle_tab_drop(dragged_tab, this.items_len(), window, cx)
367 },
368 ))
369 .children(pane.items().enumerate().map(|(ix, item)| {
370 let selected = active_pane_item
371 .as_ref()
372 .map_or(false, |active| active.item_id() == item.item_id());
373 let deemphasized = !pane.has_focus(window, cx);
374 let item_ = item.boxed_clone();
375 div()
376 .id(SharedString::from(format!(
377 "debugger_tab_{}",
378 item.item_id().as_u64()
379 )))
380 .p_1()
381 .rounded_md()
382 .cursor_pointer()
383 .map(|this| {
384 let theme = cx.theme();
385 if selected {
386 let color = theme.colors().tab_active_background;
387 let color = if deemphasized {
388 color.opacity(0.5)
389 } else {
390 color
391 };
392 this.bg(color)
393 } else {
394 let hover_color = theme.colors().element_hover;
395 this.hover(|style| style.bg(hover_color))
396 }
397 })
398 .on_click(cx.listener(move |this, _, window, cx| {
399 let index = this.index_for_item(&*item_);
400 if let Some(index) = index {
401 this.activate_item(index, true, true, window, cx);
402 }
403 }))
404 .child(item.tab_content(
405 TabContentParams {
406 selected,
407 deemphasized,
408 ..Default::default()
409 },
410 window,
411 cx,
412 ))
413 .on_drop(cx.listener(
414 move |this, dragged_tab: &DraggedTab, window, cx| {
415 this.drag_split_direction = None;
416 this.handle_tab_drop(dragged_tab, ix, window, cx)
417 },
418 ))
419 .on_drag(
420 DraggedTab {
421 item: item.boxed_clone(),
422 pane: cx.entity().clone(),
423 detail: 0,
424 is_active: selected,
425 ix,
426 },
427 |tab, _, _, cx| cx.new(|_| tab.clone()),
428 )
429 })),
430 )
431 .child({
432 let zoomed = pane.is_zoomed();
433 div()
434 .visible_on_hover(pane_group_id)
435 .when(is_hovered, |this| this.visible())
436 .child(
437 IconButton::new(
438 SharedString::from(format!(
439 "debug-toggle-zoom-{}",
440 cx.entity_id()
441 )),
442 if zoomed {
443 IconName::Minimize
444 } else {
445 IconName::Maximize
446 },
447 )
448 .icon_size(IconSize::XSmall)
449 .on_click(cx.listener(move |pane, _, window, cx| {
450 pane.toggle_zoom(&workspace::ToggleZoom, window, cx);
451 }))
452 .tooltip({
453 let focus_handle = focus_handle.clone();
454 move |window, cx| {
455 let zoomed_text =
456 if zoomed { "Zoom Out" } else { "Zoom In" };
457 Tooltip::for_action_in(
458 zoomed_text,
459 &workspace::ToggleZoom,
460 &focus_handle,
461 window,
462 cx,
463 )
464 }
465 }),
466 )
467 })
468 .into_any_element()
469 }
470 });
471 pane
472 });
473
474 ret
475}
476
477pub struct DebugTerminal {
478 pub terminal: Option<Entity<TerminalView>>,
479 focus_handle: FocusHandle,
480}
481
482impl DebugTerminal {
483 fn empty(cx: &mut Context<Self>) -> Self {
484 Self {
485 terminal: None,
486 focus_handle: cx.focus_handle(),
487 }
488 }
489}
490
491impl gpui::Render for DebugTerminal {
492 fn render(&mut self, _window: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
493 if let Some(terminal) = self.terminal.clone() {
494 terminal.into_any_element()
495 } else {
496 div().track_focus(&self.focus_handle).into_any_element()
497 }
498 }
499}
500impl Focusable for DebugTerminal {
501 fn focus_handle(&self, cx: &App) -> FocusHandle {
502 if let Some(terminal) = self.terminal.as_ref() {
503 return terminal.focus_handle(cx);
504 } else {
505 self.focus_handle.clone()
506 }
507 }
508}
509
510impl RunningState {
511 pub fn new(
512 session: Entity<Session>,
513 project: Entity<Project>,
514 workspace: WeakEntity<Workspace>,
515 serialized_pane_layout: Option<SerializedLayout>,
516 dock_axis: Axis,
517 window: &mut Window,
518 cx: &mut Context<Self>,
519 ) -> Self {
520 let focus_handle = cx.focus_handle();
521 let session_id = session.read(cx).session_id();
522 let weak_state = cx.weak_entity();
523 let stack_frame_list = cx.new(|cx| {
524 StackFrameList::new(workspace.clone(), session.clone(), weak_state, window, cx)
525 });
526
527 let debug_terminal = cx.new(DebugTerminal::empty);
528
529 let variable_list =
530 cx.new(|cx| VariableList::new(session.clone(), stack_frame_list.clone(), window, cx));
531
532 let module_list = cx.new(|cx| ModuleList::new(session.clone(), workspace.clone(), cx));
533
534 let loaded_source_list = cx.new(|cx| LoadedSourceList::new(session.clone(), cx));
535
536 let console = cx.new(|cx| {
537 Console::new(
538 session.clone(),
539 stack_frame_list.clone(),
540 variable_list.clone(),
541 window,
542 cx,
543 )
544 });
545
546 let breakpoint_list = BreakpointList::new(session.clone(), workspace.clone(), &project, cx);
547
548 let _subscriptions = vec![
549 cx.observe(&module_list, |_, _, cx| cx.notify()),
550 cx.subscribe_in(&session, window, |this, _, event, window, cx| {
551 match event {
552 SessionEvent::Stopped(thread_id) => {
553 this.workspace
554 .update(cx, |workspace, cx| {
555 workspace.open_panel::<crate::DebugPanel>(window, cx);
556 })
557 .log_err();
558
559 if let Some(thread_id) = thread_id {
560 this.select_thread(*thread_id, window, cx);
561 }
562 }
563 SessionEvent::Threads => {
564 let threads = this.session.update(cx, |this, cx| this.threads(cx));
565 this.select_current_thread(&threads, window, cx);
566 }
567 SessionEvent::CapabilitiesLoaded => {
568 let capabilities = this.capabilities(cx);
569 if !capabilities.supports_modules_request.unwrap_or(false) {
570 this.remove_pane_item(DebuggerPaneItem::Modules, window, cx);
571 }
572 if !capabilities
573 .supports_loaded_sources_request
574 .unwrap_or(false)
575 {
576 this.remove_pane_item(DebuggerPaneItem::LoadedSources, window, cx);
577 }
578 }
579 SessionEvent::RunInTerminal { request, sender } => this
580 .handle_run_in_terminal(request, sender.clone(), window, cx)
581 .detach_and_log_err(cx),
582
583 _ => {}
584 }
585 cx.notify()
586 }),
587 cx.on_focus_out(&focus_handle, window, |this, _, window, cx| {
588 this.serialize_layout(window, cx);
589 }),
590 ];
591
592 let mut pane_close_subscriptions = HashMap::default();
593 let panes = if let Some(root) = serialized_pane_layout.and_then(|serialized_layout| {
594 persistence::deserialize_pane_layout(
595 serialized_layout.panes,
596 dock_axis != serialized_layout.dock_axis,
597 &workspace,
598 &project,
599 &stack_frame_list,
600 &variable_list,
601 &module_list,
602 &console,
603 &breakpoint_list,
604 &loaded_source_list,
605 &debug_terminal,
606 &mut pane_close_subscriptions,
607 window,
608 cx,
609 )
610 }) {
611 workspace::PaneGroup::with_root(root)
612 } else {
613 pane_close_subscriptions.clear();
614
615 let root = Self::default_pane_layout(
616 project,
617 &workspace,
618 &stack_frame_list,
619 &variable_list,
620 &module_list,
621 &loaded_source_list,
622 &console,
623 &breakpoint_list,
624 dock_axis,
625 &mut pane_close_subscriptions,
626 window,
627 cx,
628 );
629
630 workspace::PaneGroup::with_root(root)
631 };
632
633 Self {
634 session,
635 workspace,
636 focus_handle,
637 variable_list,
638 _subscriptions,
639 thread_id: None,
640 _remote_id: None,
641 stack_frame_list,
642 session_id,
643 panes,
644 active_pane: None,
645 module_list,
646 console,
647 breakpoint_list,
648 loaded_sources_list: loaded_source_list,
649 pane_close_subscriptions,
650 debug_terminal,
651 dock_axis,
652 _schedule_serialize: None,
653 }
654 }
655
656 pub(crate) fn remove_pane_item(
657 &mut self,
658 item_kind: DebuggerPaneItem,
659 window: &mut Window,
660 cx: &mut Context<Self>,
661 ) {
662 if let Some((pane, item_id)) = self.panes.panes().iter().find_map(|pane| {
663 Some(pane).zip(
664 pane.read(cx)
665 .items()
666 .find(|item| {
667 item.act_as::<SubView>(cx)
668 .is_some_and(|view| view.read(cx).kind == item_kind)
669 })
670 .map(|item| item.item_id()),
671 )
672 }) {
673 pane.update(cx, |pane, cx| {
674 pane.remove_item(item_id, false, true, window, cx)
675 })
676 }
677 }
678
679 pub(crate) fn has_pane_at_position(&self, position: Point<Pixels>) -> bool {
680 self.panes.pane_at_pixel_position(position).is_some()
681 }
682
683 pub(crate) fn resolve_scenario(
684 &self,
685 scenario: DebugScenario,
686 task_context: TaskContext,
687 buffer: Option<Entity<Buffer>>,
688 worktree_id: Option<WorktreeId>,
689 window: &Window,
690 cx: &mut Context<Self>,
691 ) -> Task<Result<DebugTaskDefinition>> {
692 let Some(workspace) = self.workspace.upgrade() else {
693 return Task::ready(Err(anyhow!("no workspace")));
694 };
695 let project = workspace.read(cx).project().clone();
696 let dap_store = project.read(cx).dap_store().downgrade();
697 let task_store = project.read(cx).task_store().downgrade();
698 let weak_project = project.downgrade();
699 let weak_workspace = workspace.downgrade();
700 let is_local = project.read(cx).is_local();
701 cx.spawn_in(window, async move |this, cx| {
702 let DebugScenario {
703 adapter,
704 label,
705 build,
706 request,
707 initialize_args,
708 tcp_connection,
709 stop_on_entry,
710 } = scenario;
711 let build_output = if let Some(build) = build {
712 let (task, locator_name) = match build {
713 BuildTaskDefinition::Template {
714 task_template,
715 locator_name,
716 } => (task_template, locator_name),
717 BuildTaskDefinition::ByName(ref label) => {
718 let Some(task) = task_store.update(cx, |this, cx| {
719 this.task_inventory().and_then(|inventory| {
720 inventory.read(cx).task_template_by_label(
721 buffer,
722 worktree_id,
723 &label,
724 cx,
725 )
726 })
727 })?
728 else {
729 anyhow::bail!("Couldn't find task template for {:?}", build)
730 };
731 (task, None)
732 }
733 };
734 let locator_name = if let Some(locator_name) = locator_name {
735 debug_assert!(request.is_none());
736 Some(locator_name)
737 } else if request.is_none() {
738 dap_store
739 .update(cx, |this, cx| {
740 this.debug_scenario_for_build_task(task.clone(), adapter.clone(), cx)
741 .and_then(|scenario| match scenario.build {
742 Some(BuildTaskDefinition::Template {
743 locator_name, ..
744 }) => locator_name,
745 _ => None,
746 })
747 })
748 .ok()
749 .flatten()
750 } else {
751 None
752 };
753
754 let Some(task) = task.resolve_task("debug-build-task", &task_context) else {
755 anyhow::bail!("Could not resolve task variables within a debug scenario");
756 };
757
758 let builder = ShellBuilder::new(is_local, &task.resolved.shell);
759 let command_label = builder.command_label(&task.resolved.command_label);
760 let (command, args) =
761 builder.build(task.resolved.command.clone(), &task.resolved.args);
762
763 let task_with_shell = SpawnInTerminal {
764 command_label,
765 command,
766 args,
767 ..task.resolved.clone()
768 };
769 let terminal = project
770 .update_in(cx, |project, window, cx| {
771 project.create_terminal(
772 TerminalKind::Task(task_with_shell.clone()),
773 window.window_handle(),
774 cx,
775 )
776 })?
777 .await?;
778
779 let terminal_view = cx.new_window_entity(|window, cx| {
780 TerminalView::new(
781 terminal.clone(),
782 weak_workspace,
783 None,
784 weak_project,
785 false,
786 window,
787 cx,
788 )
789 })?;
790
791 this.update_in(cx, |this, window, cx| {
792 this.ensure_pane_item(DebuggerPaneItem::Terminal, window, cx);
793 this.debug_terminal.update(cx, |debug_terminal, cx| {
794 debug_terminal.terminal = Some(terminal_view);
795 cx.notify();
796 });
797 })?;
798
799 let exit_status = terminal
800 .read_with(cx, |terminal, cx| terminal.wait_for_completed_task(cx))?
801 .await
802 .ok_or_else(|| anyhow!("Failed to wait for completed task"))?;
803
804 if !exit_status.success() {
805 anyhow::bail!("Build failed");
806 }
807 Some((task.resolved.clone(), locator_name))
808 } else {
809 None
810 };
811 let request = if let Some(request) = request {
812 request
813 } else if let Some((task, locator_name)) = build_output {
814 let locator_name = locator_name
815 .ok_or_else(|| anyhow!("Could not find a valid locator for a build task"))?;
816 dap_store
817 .update(cx, |this, cx| {
818 this.run_debug_locator(&locator_name, task, cx)
819 })?
820 .await?
821 } else {
822 return Err(anyhow!("No request or build provided"));
823 };
824 let request = match request {
825 dap::DebugRequest::Launch(launch_request) => {
826 let cwd = match launch_request.cwd.as_deref().and_then(|path| path.to_str()) {
827 Some(cwd) => {
828 let substituted_cwd = substitute_variables_in_str(&cwd, &task_context)
829 .ok_or_else(|| anyhow!("Failed to substitute variables in cwd"))?;
830 Some(PathBuf::from(substituted_cwd))
831 }
832 None => None,
833 };
834
835 let env = substitute_variables_in_map(
836 &launch_request.env.into_iter().collect(),
837 &task_context,
838 )
839 .ok_or_else(|| anyhow!("Failed to substitute variables in env"))?
840 .into_iter()
841 .collect();
842 let new_launch_request = LaunchRequest {
843 program: substitute_variables_in_str(
844 &launch_request.program,
845 &task_context,
846 )
847 .ok_or_else(|| anyhow!("Failed to substitute variables in program"))?,
848 args: launch_request
849 .args
850 .into_iter()
851 .map(|arg| substitute_variables_in_str(&arg, &task_context))
852 .collect::<Option<Vec<_>>>()
853 .ok_or_else(|| anyhow!("Failed to substitute variables in args"))?,
854 cwd,
855 env,
856 };
857
858 dap::DebugRequest::Launch(new_launch_request)
859 }
860 request @ dap::DebugRequest::Attach(_) => request,
861 };
862 Ok(DebugTaskDefinition {
863 label,
864 adapter: DebugAdapterName(adapter),
865 request,
866 initialize_args,
867 stop_on_entry,
868 tcp_connection,
869 })
870 })
871 }
872
873 fn handle_run_in_terminal(
874 &self,
875 request: &RunInTerminalRequestArguments,
876 mut sender: mpsc::Sender<Result<u32>>,
877 window: &mut Window,
878 cx: &mut Context<Self>,
879 ) -> Task<Result<()>> {
880 let running = cx.entity();
881 let Ok(project) = self
882 .workspace
883 .update(cx, |workspace, _| workspace.project().clone())
884 else {
885 return Task::ready(Err(anyhow!("no workspace")));
886 };
887 let session = self.session.read(cx);
888
889 let cwd = Some(&request.cwd)
890 .filter(|cwd| cwd.len() > 0)
891 .map(PathBuf::from)
892 .or_else(|| session.binary().cwd.clone());
893
894 let mut args = request.args.clone();
895
896 // Handle special case for NodeJS debug adapter
897 // If only the Node binary path is provided, we set the command to None
898 // This prevents the NodeJS REPL from appearing, which is not the desired behavior
899 // The expected usage is for users to provide their own Node command, e.g., `node test.js`
900 // This allows the NodeJS debug client to attach correctly
901 let command = if args.len() > 1 {
902 Some(args.remove(0))
903 } else {
904 None
905 };
906
907 let mut envs: HashMap<String, String> = Default::default();
908 if let Some(Value::Object(env)) = &request.env {
909 for (key, value) in env {
910 let value_str = match (key.as_str(), value) {
911 (_, Value::String(value)) => value,
912 _ => continue,
913 };
914
915 envs.insert(key.clone(), value_str.clone());
916 }
917 }
918
919 let shell = project.read(cx).terminal_settings(&cwd, cx).shell.clone();
920 let kind = if let Some(command) = command {
921 let title = request.title.clone().unwrap_or(command.clone());
922 TerminalKind::Task(task::SpawnInTerminal {
923 id: task::TaskId("debug".to_string()),
924 full_label: title.clone(),
925 label: title.clone(),
926 command: command.clone(),
927 args,
928 command_label: title.clone(),
929 cwd,
930 env: envs,
931 use_new_terminal: true,
932 allow_concurrent_runs: true,
933 reveal: task::RevealStrategy::NoFocus,
934 reveal_target: task::RevealTarget::Dock,
935 hide: task::HideStrategy::Never,
936 shell,
937 show_summary: false,
938 show_command: false,
939 show_rerun: false,
940 })
941 } else {
942 TerminalKind::Shell(cwd.map(|c| c.to_path_buf()))
943 };
944
945 let workspace = self.workspace.clone();
946 let weak_project = project.downgrade();
947
948 let terminal_task = project.update(cx, |project, cx| {
949 project.create_terminal(kind, window.window_handle(), cx)
950 });
951 let terminal_task = cx.spawn_in(window, async move |_, cx| {
952 let terminal = terminal_task.await?;
953
954 let terminal_view = cx.new_window_entity(|window, cx| {
955 TerminalView::new(
956 terminal.clone(),
957 workspace,
958 None,
959 weak_project,
960 false,
961 window,
962 cx,
963 )
964 })?;
965
966 running.update_in(cx, |running, window, cx| {
967 running.ensure_pane_item(DebuggerPaneItem::Terminal, window, cx);
968 running.debug_terminal.update(cx, |debug_terminal, cx| {
969 debug_terminal.terminal = Some(terminal_view);
970 cx.notify();
971 });
972 })?;
973
974 terminal.read_with(cx, |terminal, _| {
975 terminal
976 .pty_info
977 .pid()
978 .map(|pid| pid.as_u32())
979 .ok_or_else(|| anyhow!("Terminal was spawned but PID was not available"))
980 })?
981 });
982
983 cx.background_spawn(async move { anyhow::Ok(sender.send(terminal_task.await).await?) })
984 }
985
986 fn create_sub_view(
987 &self,
988 item_kind: DebuggerPaneItem,
989 _pane: &Entity<Pane>,
990 cx: &mut Context<Self>,
991 ) -> Box<dyn ItemHandle> {
992 match item_kind {
993 DebuggerPaneItem::Console => {
994 let weak_console = self.console.clone().downgrade();
995
996 Box::new(SubView::new(
997 self.console.focus_handle(cx),
998 self.console.clone().into(),
999 item_kind,
1000 Some(Box::new(move |cx| {
1001 weak_console
1002 .read_with(cx, |console, cx| console.show_indicator(cx))
1003 .unwrap_or_default()
1004 })),
1005 cx,
1006 ))
1007 }
1008 DebuggerPaneItem::Variables => Box::new(SubView::new(
1009 self.variable_list.focus_handle(cx),
1010 self.variable_list.clone().into(),
1011 item_kind,
1012 None,
1013 cx,
1014 )),
1015 DebuggerPaneItem::BreakpointList => Box::new(SubView::new(
1016 self.breakpoint_list.focus_handle(cx),
1017 self.breakpoint_list.clone().into(),
1018 item_kind,
1019 None,
1020 cx,
1021 )),
1022 DebuggerPaneItem::Frames => Box::new(SubView::new(
1023 self.stack_frame_list.focus_handle(cx),
1024 self.stack_frame_list.clone().into(),
1025 item_kind,
1026 None,
1027 cx,
1028 )),
1029 DebuggerPaneItem::Modules => Box::new(SubView::new(
1030 self.module_list.focus_handle(cx),
1031 self.module_list.clone().into(),
1032 item_kind,
1033 None,
1034 cx,
1035 )),
1036 DebuggerPaneItem::LoadedSources => Box::new(SubView::new(
1037 self.loaded_sources_list.focus_handle(cx),
1038 self.loaded_sources_list.clone().into(),
1039 item_kind,
1040 None,
1041 cx,
1042 )),
1043 DebuggerPaneItem::Terminal => Box::new(SubView::new(
1044 self.debug_terminal.focus_handle(cx),
1045 self.debug_terminal.clone().into(),
1046 item_kind,
1047 None,
1048 cx,
1049 )),
1050 }
1051 }
1052
1053 pub(crate) fn ensure_pane_item(
1054 &mut self,
1055 item_kind: DebuggerPaneItem,
1056 window: &mut Window,
1057 cx: &mut Context<Self>,
1058 ) {
1059 if self.pane_items_status(cx).get(&item_kind) == Some(&true) {
1060 return;
1061 };
1062 let pane = self.panes.last_pane();
1063 let sub_view = self.create_sub_view(item_kind, &pane, cx);
1064
1065 pane.update(cx, |pane, cx| {
1066 pane.add_item_inner(sub_view, false, false, false, None, window, cx);
1067 })
1068 }
1069
1070 pub(crate) fn add_pane_item(
1071 &mut self,
1072 item_kind: DebuggerPaneItem,
1073 position: Point<Pixels>,
1074 window: &mut Window,
1075 cx: &mut Context<Self>,
1076 ) {
1077 debug_assert!(
1078 item_kind.is_supported(self.session.read(cx).capabilities()),
1079 "We should only allow adding supported item kinds"
1080 );
1081
1082 if let Some(pane) = self.panes.pane_at_pixel_position(position) {
1083 let sub_view = self.create_sub_view(item_kind, pane, cx);
1084
1085 pane.update(cx, |pane, cx| {
1086 pane.add_item(sub_view, false, false, None, window, cx);
1087 })
1088 }
1089 }
1090
1091 pub(crate) fn pane_items_status(&self, cx: &App) -> IndexMap<DebuggerPaneItem, bool> {
1092 let caps = self.session.read(cx).capabilities();
1093 let mut pane_item_status = IndexMap::from_iter(
1094 DebuggerPaneItem::all()
1095 .iter()
1096 .filter(|kind| kind.is_supported(&caps))
1097 .map(|kind| (*kind, false)),
1098 );
1099 self.panes.panes().iter().for_each(|pane| {
1100 pane.read(cx)
1101 .items()
1102 .filter_map(|item| item.act_as::<SubView>(cx))
1103 .for_each(|view| {
1104 pane_item_status.insert(view.read(cx).kind, true);
1105 });
1106 });
1107
1108 pane_item_status
1109 }
1110
1111 pub(crate) fn serialize_layout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1112 if self._schedule_serialize.is_none() {
1113 self._schedule_serialize = Some(cx.spawn_in(window, async move |this, cx| {
1114 cx.background_executor()
1115 .timer(Duration::from_millis(100))
1116 .await;
1117
1118 let Some((adapter_name, pane_layout)) = this
1119 .read_with(cx, |this, cx| {
1120 let adapter_name = this.session.read(cx).adapter();
1121 (
1122 adapter_name,
1123 persistence::build_serialized_layout(
1124 &this.panes.root,
1125 this.dock_axis,
1126 cx,
1127 ),
1128 )
1129 })
1130 .ok()
1131 else {
1132 return;
1133 };
1134
1135 persistence::serialize_pane_layout(adapter_name, pane_layout)
1136 .await
1137 .log_err();
1138
1139 this.update(cx, |this, _| {
1140 this._schedule_serialize.take();
1141 })
1142 .ok();
1143 }));
1144 }
1145 }
1146
1147 pub(crate) fn handle_pane_event(
1148 this: &mut RunningState,
1149 source_pane: &Entity<Pane>,
1150 event: &Event,
1151 window: &mut Window,
1152 cx: &mut Context<RunningState>,
1153 ) {
1154 this.serialize_layout(window, cx);
1155 match event {
1156 Event::Remove { .. } => {
1157 let _did_find_pane = this.panes.remove(&source_pane).is_ok();
1158 debug_assert!(_did_find_pane);
1159 cx.notify();
1160 }
1161 Event::Focus => {
1162 this.active_pane = Some(source_pane.clone());
1163 }
1164 Event::ZoomIn => {
1165 source_pane.update(cx, |pane, cx| {
1166 pane.set_zoomed(true, cx);
1167 });
1168 cx.notify();
1169 }
1170 Event::ZoomOut => {
1171 source_pane.update(cx, |pane, cx| {
1172 pane.set_zoomed(false, cx);
1173 });
1174 cx.notify();
1175 }
1176 _ => {}
1177 }
1178 }
1179
1180 pub(crate) fn activate_pane_in_direction(
1181 &mut self,
1182 direction: SplitDirection,
1183 window: &mut Window,
1184 cx: &mut Context<Self>,
1185 ) {
1186 if let Some(pane) = self
1187 .active_pane
1188 .as_ref()
1189 .and_then(|pane| self.panes.find_pane_in_direction(pane, direction, cx))
1190 {
1191 window.focus(&pane.focus_handle(cx));
1192 } else {
1193 self.workspace
1194 .update(cx, |workspace, cx| {
1195 workspace.activate_pane_in_direction(direction, window, cx)
1196 })
1197 .ok();
1198 }
1199 }
1200
1201 pub(crate) fn go_to_selected_stack_frame(&self, window: &Window, cx: &mut Context<Self>) {
1202 if self.thread_id.is_some() {
1203 self.stack_frame_list
1204 .update(cx, |list, cx| list.go_to_selected_stack_frame(window, cx));
1205 }
1206 }
1207
1208 pub(crate) fn has_open_context_menu(&self, cx: &App) -> bool {
1209 self.variable_list.read(cx).has_open_context_menu()
1210 }
1211
1212 pub fn session(&self) -> &Entity<Session> {
1213 &self.session
1214 }
1215
1216 pub fn session_id(&self) -> SessionId {
1217 self.session_id
1218 }
1219
1220 pub(crate) fn selected_stack_frame_id(&self, cx: &App) -> Option<dap::StackFrameId> {
1221 self.stack_frame_list.read(cx).selected_stack_frame_id()
1222 }
1223
1224 #[cfg(test)]
1225 pub fn stack_frame_list(&self) -> &Entity<StackFrameList> {
1226 &self.stack_frame_list
1227 }
1228
1229 #[cfg(test)]
1230 pub fn console(&self) -> &Entity<Console> {
1231 &self.console
1232 }
1233
1234 #[cfg(test)]
1235 pub(crate) fn module_list(&self) -> &Entity<ModuleList> {
1236 &self.module_list
1237 }
1238
1239 pub(crate) fn activate_item(&self, item: DebuggerPaneItem, window: &mut Window, cx: &mut App) {
1240 let (variable_list_position, pane) = self
1241 .panes
1242 .panes()
1243 .into_iter()
1244 .find_map(|pane| {
1245 pane.read(cx)
1246 .items_of_type::<SubView>()
1247 .position(|view| view.read(cx).view_kind() == item)
1248 .map(|view| (view, pane))
1249 })
1250 .unwrap();
1251 pane.update(cx, |this, cx| {
1252 this.activate_item(variable_list_position, true, true, window, cx);
1253 })
1254 }
1255
1256 #[cfg(test)]
1257 pub(crate) fn variable_list(&self) -> &Entity<VariableList> {
1258 &self.variable_list
1259 }
1260
1261 #[cfg(test)]
1262 pub(crate) fn serialized_layout(&self, cx: &App) -> SerializedLayout {
1263 persistence::build_serialized_layout(&self.panes.root, self.dock_axis, cx)
1264 }
1265
1266 pub fn capabilities(&self, cx: &App) -> Capabilities {
1267 self.session().read(cx).capabilities().clone()
1268 }
1269
1270 pub fn select_current_thread(
1271 &mut self,
1272 threads: &Vec<(Thread, ThreadStatus)>,
1273 window: &mut Window,
1274 cx: &mut Context<Self>,
1275 ) {
1276 let selected_thread = self
1277 .thread_id
1278 .and_then(|thread_id| threads.iter().find(|(thread, _)| thread.id == thread_id.0))
1279 .or_else(|| threads.first());
1280
1281 let Some((selected_thread, _)) = selected_thread else {
1282 return;
1283 };
1284
1285 if Some(ThreadId(selected_thread.id)) != self.thread_id {
1286 self.select_thread(ThreadId(selected_thread.id), window, cx);
1287 }
1288 }
1289
1290 pub(crate) fn selected_thread_id(&self) -> Option<ThreadId> {
1291 self.thread_id
1292 }
1293
1294 pub fn thread_status(&self, cx: &App) -> Option<ThreadStatus> {
1295 self.thread_id
1296 .map(|id| self.session().read(cx).thread_status(id))
1297 }
1298
1299 fn select_thread(&mut self, thread_id: ThreadId, window: &mut Window, cx: &mut Context<Self>) {
1300 if self.thread_id.is_some_and(|id| id == thread_id) {
1301 return;
1302 }
1303
1304 self.thread_id = Some(thread_id);
1305
1306 self.stack_frame_list
1307 .update(cx, |list, cx| list.schedule_refresh(true, window, cx));
1308 }
1309
1310 pub fn continue_thread(&mut self, cx: &mut Context<Self>) {
1311 let Some(thread_id) = self.thread_id else {
1312 return;
1313 };
1314
1315 self.session().update(cx, |state, cx| {
1316 state.continue_thread(thread_id, cx);
1317 });
1318 }
1319
1320 pub fn step_over(&mut self, cx: &mut Context<Self>) {
1321 let Some(thread_id) = self.thread_id else {
1322 return;
1323 };
1324
1325 let granularity = DebuggerSettings::get_global(cx).stepping_granularity;
1326
1327 self.session().update(cx, |state, cx| {
1328 state.step_over(thread_id, granularity, cx);
1329 });
1330 }
1331
1332 pub(crate) fn step_in(&mut self, cx: &mut Context<Self>) {
1333 let Some(thread_id) = self.thread_id else {
1334 return;
1335 };
1336
1337 let granularity = DebuggerSettings::get_global(cx).stepping_granularity;
1338
1339 self.session().update(cx, |state, cx| {
1340 state.step_in(thread_id, granularity, cx);
1341 });
1342 }
1343
1344 pub(crate) fn step_out(&mut self, cx: &mut Context<Self>) {
1345 let Some(thread_id) = self.thread_id else {
1346 return;
1347 };
1348
1349 let granularity = DebuggerSettings::get_global(cx).stepping_granularity;
1350
1351 self.session().update(cx, |state, cx| {
1352 state.step_out(thread_id, granularity, cx);
1353 });
1354 }
1355
1356 pub(crate) fn step_back(&mut self, cx: &mut Context<Self>) {
1357 let Some(thread_id) = self.thread_id else {
1358 return;
1359 };
1360
1361 let granularity = DebuggerSettings::get_global(cx).stepping_granularity;
1362
1363 self.session().update(cx, |state, cx| {
1364 state.step_back(thread_id, granularity, cx);
1365 });
1366 }
1367
1368 pub fn restart_session(&self, cx: &mut Context<Self>) {
1369 self.session().update(cx, |state, cx| {
1370 state.restart(None, cx);
1371 });
1372 }
1373
1374 pub fn pause_thread(&self, cx: &mut Context<Self>) {
1375 let Some(thread_id) = self.thread_id else {
1376 return;
1377 };
1378
1379 self.session().update(cx, |state, cx| {
1380 state.pause_thread(thread_id, cx);
1381 });
1382 }
1383
1384 pub(crate) fn shutdown(&mut self, cx: &mut Context<Self>) {
1385 self.workspace
1386 .update(cx, |workspace, cx| {
1387 workspace
1388 .project()
1389 .read(cx)
1390 .breakpoint_store()
1391 .update(cx, |store, cx| {
1392 store.remove_active_position(Some(self.session_id), cx)
1393 })
1394 })
1395 .log_err();
1396
1397 self.session.update(cx, |session, cx| {
1398 session.shutdown(cx).detach();
1399 })
1400 }
1401
1402 pub fn stop_thread(&self, cx: &mut Context<Self>) {
1403 let Some(thread_id) = self.thread_id else {
1404 return;
1405 };
1406
1407 self.workspace
1408 .update(cx, |workspace, cx| {
1409 workspace
1410 .project()
1411 .read(cx)
1412 .breakpoint_store()
1413 .update(cx, |store, cx| {
1414 store.remove_active_position(Some(self.session_id), cx)
1415 })
1416 })
1417 .log_err();
1418
1419 self.session().update(cx, |state, cx| {
1420 state.terminate_threads(Some(vec![thread_id; 1]), cx);
1421 });
1422 }
1423
1424 pub fn detach_client(&self, cx: &mut Context<Self>) {
1425 self.session().update(cx, |state, cx| {
1426 state.disconnect_client(cx);
1427 });
1428 }
1429
1430 pub fn toggle_ignore_breakpoints(&mut self, cx: &mut Context<Self>) {
1431 self.session.update(cx, |session, cx| {
1432 session.toggle_ignore_breakpoints(cx).detach();
1433 });
1434 }
1435
1436 pub(crate) fn thread_dropdown(
1437 &self,
1438 window: &mut Window,
1439 cx: &mut Context<'_, RunningState>,
1440 ) -> DropdownMenu {
1441 let state = cx.entity();
1442 let session_terminated = self.session.read(cx).is_terminated();
1443 let threads = self.session.update(cx, |this, cx| this.threads(cx));
1444 let selected_thread_name = threads
1445 .iter()
1446 .find(|(thread, _)| self.thread_id.map(|id| id.0) == Some(thread.id))
1447 .map(|(thread, _)| thread.name.clone())
1448 .unwrap_or("Threads".to_owned());
1449 DropdownMenu::new(
1450 ("thread-list", self.session_id.0),
1451 selected_thread_name,
1452 ContextMenu::build_eager(window, cx, move |mut this, _, _| {
1453 for (thread, _) in threads {
1454 let state = state.clone();
1455 let thread_id = thread.id;
1456 this = this.entry(thread.name, None, move |window, cx| {
1457 state.update(cx, |state, cx| {
1458 state.select_thread(ThreadId(thread_id), window, cx);
1459 });
1460 });
1461 }
1462 this
1463 }),
1464 )
1465 .disabled(session_terminated)
1466 }
1467
1468 fn default_pane_layout(
1469 project: Entity<Project>,
1470 workspace: &WeakEntity<Workspace>,
1471 stack_frame_list: &Entity<StackFrameList>,
1472 variable_list: &Entity<VariableList>,
1473 module_list: &Entity<ModuleList>,
1474 loaded_source_list: &Entity<LoadedSourceList>,
1475 console: &Entity<Console>,
1476 breakpoints: &Entity<BreakpointList>,
1477 dock_axis: Axis,
1478 subscriptions: &mut HashMap<EntityId, Subscription>,
1479 window: &mut Window,
1480 cx: &mut Context<'_, RunningState>,
1481 ) -> Member {
1482 let leftmost_pane = new_debugger_pane(workspace.clone(), project.clone(), window, cx);
1483 leftmost_pane.update(cx, |this, cx| {
1484 this.add_item(
1485 Box::new(SubView::new(
1486 this.focus_handle(cx),
1487 stack_frame_list.clone().into(),
1488 DebuggerPaneItem::Frames,
1489 None,
1490 cx,
1491 )),
1492 true,
1493 false,
1494 None,
1495 window,
1496 cx,
1497 );
1498 this.add_item(
1499 Box::new(SubView::new(
1500 breakpoints.focus_handle(cx),
1501 breakpoints.clone().into(),
1502 DebuggerPaneItem::BreakpointList,
1503 None,
1504 cx,
1505 )),
1506 true,
1507 false,
1508 None,
1509 window,
1510 cx,
1511 );
1512 this.activate_item(0, false, false, window, cx);
1513 });
1514 let center_pane = new_debugger_pane(workspace.clone(), project.clone(), window, cx);
1515
1516 center_pane.update(cx, |this, cx| {
1517 this.add_item(
1518 Box::new(SubView::new(
1519 variable_list.focus_handle(cx),
1520 variable_list.clone().into(),
1521 DebuggerPaneItem::Variables,
1522 None,
1523 cx,
1524 )),
1525 true,
1526 false,
1527 None,
1528 window,
1529 cx,
1530 );
1531 this.add_item(
1532 Box::new(SubView::new(
1533 module_list.focus_handle(cx),
1534 module_list.clone().into(),
1535 DebuggerPaneItem::Modules,
1536 None,
1537 cx,
1538 )),
1539 false,
1540 false,
1541 None,
1542 window,
1543 cx,
1544 );
1545
1546 this.add_item(
1547 Box::new(SubView::new(
1548 loaded_source_list.focus_handle(cx),
1549 loaded_source_list.clone().into(),
1550 DebuggerPaneItem::LoadedSources,
1551 None,
1552 cx,
1553 )),
1554 false,
1555 false,
1556 None,
1557 window,
1558 cx,
1559 );
1560 this.activate_item(0, false, false, window, cx);
1561 });
1562
1563 let rightmost_pane = new_debugger_pane(workspace.clone(), project.clone(), window, cx);
1564 rightmost_pane.update(cx, |this, cx| {
1565 let weak_console = console.downgrade();
1566 this.add_item(
1567 Box::new(SubView::new(
1568 this.focus_handle(cx),
1569 console.clone().into(),
1570 DebuggerPaneItem::Console,
1571 Some(Box::new(move |cx| {
1572 weak_console
1573 .read_with(cx, |console, cx| console.show_indicator(cx))
1574 .unwrap_or_default()
1575 })),
1576 cx,
1577 )),
1578 true,
1579 false,
1580 None,
1581 window,
1582 cx,
1583 );
1584 });
1585
1586 subscriptions.extend(
1587 [&leftmost_pane, ¢er_pane, &rightmost_pane]
1588 .into_iter()
1589 .map(|entity| {
1590 (
1591 entity.entity_id(),
1592 cx.subscribe_in(entity, window, Self::handle_pane_event),
1593 )
1594 }),
1595 );
1596
1597 let group_root = workspace::PaneAxis::new(
1598 dock_axis.invert(),
1599 [leftmost_pane, center_pane, rightmost_pane]
1600 .into_iter()
1601 .map(workspace::Member::Pane)
1602 .collect(),
1603 );
1604
1605 Member::Axis(group_root)
1606 }
1607
1608 pub(crate) fn invert_axies(&mut self) {
1609 self.dock_axis = self.dock_axis.invert();
1610 self.panes.invert_axies();
1611 }
1612}
1613
1614impl EventEmitter<DebugPanelItemEvent> for RunningState {}
1615
1616impl Focusable for RunningState {
1617 fn focus_handle(&self, _: &App) -> FocusHandle {
1618 self.focus_handle.clone()
1619 }
1620}