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