1use anyhow::{Context as _, bail};
2use collections::{FxHashMap, HashMap, HashSet};
3use language::LanguageRegistry;
4use std::{
5 borrow::Cow,
6 path::{Path, PathBuf},
7 sync::Arc,
8 usize,
9};
10use tasks_ui::{TaskOverrides, TasksModal};
11
12use dap::{
13 DapRegistry, DebugRequest, TelemetrySpawnLocation, adapters::DebugAdapterName, send_telemetry,
14};
15use editor::{Editor, EditorElement, EditorStyle};
16use fuzzy::{StringMatch, StringMatchCandidate};
17use gpui::{
18 Action, App, AppContext, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable,
19 KeyContext, Render, Subscription, Task, TextStyle, WeakEntity,
20};
21use itertools::Itertools as _;
22use picker::{Picker, PickerDelegate, highlighted_match_with_paths::HighlightedMatch};
23use project::{DebugScenarioContext, TaskContexts, TaskSourceKind, task_store::TaskStore};
24use settings::Settings;
25use task::{DebugScenario, RevealTarget, ZedDebugConfig};
26use theme::ThemeSettings;
27use ui::{
28 ActiveTheme, Button, ButtonCommon, ButtonSize, CheckboxWithLabel, Clickable, Color, Context,
29 ContextMenu, Disableable, DropdownMenu, FluentBuilder, Icon, IconName, IconSize,
30 IconWithIndicator, Indicator, InteractiveElement, IntoElement, KeyBinding, Label,
31 LabelCommon as _, LabelSize, ListItem, ListItemSpacing, ParentElement, RenderOnce,
32 SharedString, Styled, StyledExt, ToggleButton, ToggleState, Toggleable, Tooltip, Window, div,
33 h_flex, relative, rems, v_flex,
34};
35use util::ResultExt;
36use workspace::{ModalView, Workspace, notifications::DetachAndPromptErr, pane};
37
38use crate::{attach_modal::AttachModal, debugger_panel::DebugPanel};
39
40pub(super) struct NewProcessModal {
41 workspace: WeakEntity<Workspace>,
42 debug_panel: WeakEntity<DebugPanel>,
43 mode: NewProcessMode,
44 debug_picker: Entity<Picker<DebugDelegate>>,
45 attach_mode: Entity<AttachMode>,
46 configure_mode: Entity<ConfigureMode>,
47 task_mode: TaskMode,
48 debugger: Option<DebugAdapterName>,
49 _subscriptions: [Subscription; 3],
50}
51
52fn suggested_label(request: &DebugRequest, debugger: &str) -> SharedString {
53 match request {
54 DebugRequest::Launch(config) => {
55 let last_path_component = Path::new(&config.program)
56 .file_name()
57 .map(|name| name.to_string_lossy())
58 .unwrap_or_else(|| Cow::Borrowed(&config.program));
59
60 format!("{} ({debugger})", last_path_component).into()
61 }
62 DebugRequest::Attach(config) => format!(
63 "pid: {} ({debugger})",
64 config.process_id.unwrap_or(u32::MAX)
65 )
66 .into(),
67 }
68}
69
70impl NewProcessModal {
71 pub(super) fn show(
72 workspace: &mut Workspace,
73 window: &mut Window,
74 mode: NewProcessMode,
75 reveal_target: Option<RevealTarget>,
76 cx: &mut Context<Workspace>,
77 ) {
78 let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) else {
79 return;
80 };
81 let task_store = workspace.project().read(cx).task_store().clone();
82 let languages = workspace.app_state().languages.clone();
83
84 cx.spawn_in(window, async move |workspace, cx| {
85 let task_contexts = workspace.update_in(cx, |workspace, window, cx| {
86 // todo(debugger): get the buffer here (if the active item is an editor) and store it so we can pass it to start_session later
87 tasks_ui::task_contexts(workspace, window, cx)
88 })?;
89 workspace.update_in(cx, |workspace, window, cx| {
90 let workspace_handle = workspace.weak_handle();
91 workspace.toggle_modal(window, cx, |window, cx| {
92 let attach_mode = AttachMode::new(None, workspace_handle.clone(), window, cx);
93
94 let debug_picker = cx.new(|cx| {
95 let delegate =
96 DebugDelegate::new(debug_panel.downgrade(), task_store.clone());
97 Picker::uniform_list(delegate, window, cx).modal(false)
98 });
99
100 let configure_mode = ConfigureMode::new(window, cx);
101
102 let task_overrides = Some(TaskOverrides { reveal_target });
103
104 let task_mode = TaskMode {
105 task_modal: cx.new(|cx| {
106 TasksModal::new(
107 task_store.clone(),
108 Arc::new(TaskContexts::default()),
109 task_overrides,
110 false,
111 workspace_handle.clone(),
112 window,
113 cx,
114 )
115 }),
116 };
117
118 let _subscriptions = [
119 cx.subscribe(&debug_picker, |_, _, _, cx| {
120 cx.emit(DismissEvent);
121 }),
122 cx.subscribe(
123 &attach_mode.read(cx).attach_picker.clone(),
124 |_, _, _, cx| {
125 cx.emit(DismissEvent);
126 },
127 ),
128 cx.subscribe(&task_mode.task_modal, |_, _, _: &DismissEvent, cx| {
129 cx.emit(DismissEvent)
130 }),
131 ];
132
133 cx.spawn_in(window, {
134 let debug_picker = debug_picker.downgrade();
135 let configure_mode = configure_mode.downgrade();
136 let task_modal = task_mode.task_modal.downgrade();
137 let workspace = workspace_handle.clone();
138
139 async move |this, cx| {
140 let task_contexts = task_contexts.await;
141 let task_contexts = Arc::new(task_contexts);
142 let lsp_task_sources = task_contexts.lsp_task_sources.clone();
143 let task_position = task_contexts.latest_selection;
144 // Get LSP tasks and filter out based on language vs lsp preference
145 let (lsp_tasks, prefer_lsp) =
146 workspace.update(cx, |workspace, cx| {
147 let lsp_tasks = editor::lsp_tasks(
148 workspace.project().clone(),
149 &lsp_task_sources,
150 task_position,
151 cx,
152 );
153 let prefer_lsp = workspace
154 .active_item(cx)
155 .and_then(|item| item.downcast::<Editor>())
156 .map(|editor| {
157 editor
158 .read(cx)
159 .buffer()
160 .read(cx)
161 .language_settings(cx)
162 .tasks
163 .prefer_lsp
164 })
165 .unwrap_or(false);
166 (lsp_tasks, prefer_lsp)
167 })?;
168
169 let lsp_tasks = lsp_tasks.await;
170 let add_current_language_tasks = !prefer_lsp || lsp_tasks.is_empty();
171
172 let lsp_tasks = lsp_tasks
173 .into_iter()
174 .flat_map(|(kind, tasks_with_locations)| {
175 tasks_with_locations
176 .into_iter()
177 .sorted_by_key(|(location, task)| {
178 (location.is_none(), task.resolved_label.clone())
179 })
180 .map(move |(_, task)| (kind.clone(), task))
181 })
182 .collect::<Vec<_>>();
183
184 let Some(task_inventory) = task_store
185 .update(cx, |task_store, _| task_store.task_inventory().cloned())?
186 else {
187 return Ok(());
188 };
189
190 let (used_tasks, current_resolved_tasks) = task_inventory
191 .update(cx, |task_inventory, cx| {
192 task_inventory
193 .used_and_current_resolved_tasks(task_contexts.clone(), cx)
194 })?
195 .await;
196
197 if let Ok(task) = debug_picker.update(cx, |picker, cx| {
198 picker.delegate.tasks_loaded(
199 task_contexts.clone(),
200 languages,
201 lsp_tasks.clone(),
202 current_resolved_tasks.clone(),
203 add_current_language_tasks,
204 cx,
205 )
206 }) {
207 task.await;
208 debug_picker
209 .update_in(cx, |picker, window, cx| {
210 picker.refresh(window, cx);
211 cx.notify();
212 })
213 .ok();
214 }
215
216 if let Some(active_cwd) = task_contexts
217 .active_context()
218 .and_then(|context| context.cwd.clone())
219 {
220 configure_mode
221 .update_in(cx, |configure_mode, window, cx| {
222 configure_mode.load(active_cwd, window, cx);
223 })
224 .ok();
225 }
226
227 task_modal
228 .update_in(cx, |task_modal, window, cx| {
229 task_modal.tasks_loaded(
230 task_contexts,
231 lsp_tasks,
232 used_tasks,
233 current_resolved_tasks,
234 add_current_language_tasks,
235 window,
236 cx,
237 );
238 })
239 .ok();
240
241 this.update(cx, |_, cx| {
242 cx.notify();
243 })
244 .ok();
245
246 anyhow::Ok(())
247 }
248 })
249 .detach();
250
251 Self {
252 debug_picker,
253 attach_mode,
254 configure_mode,
255 task_mode,
256 debugger: None,
257 mode,
258 debug_panel: debug_panel.downgrade(),
259 workspace: workspace_handle,
260 _subscriptions,
261 }
262 });
263 })?;
264
265 anyhow::Ok(())
266 })
267 .detach();
268 }
269
270 fn render_mode(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
271 let dap_menu = self.adapter_drop_down_menu(window, cx);
272 match self.mode {
273 NewProcessMode::Task => self
274 .task_mode
275 .task_modal
276 .read(cx)
277 .picker
278 .clone()
279 .into_any_element(),
280 NewProcessMode::Attach => self.attach_mode.update(cx, |this, cx| {
281 this.clone().render(window, cx).into_any_element()
282 }),
283 NewProcessMode::Launch => self.configure_mode.update(cx, |this, cx| {
284 this.clone().render(dap_menu, window, cx).into_any_element()
285 }),
286 NewProcessMode::Debug => v_flex()
287 .w(rems(34.))
288 .child(self.debug_picker.clone())
289 .into_any_element(),
290 }
291 }
292
293 fn mode_focus_handle(&self, cx: &App) -> FocusHandle {
294 match self.mode {
295 NewProcessMode::Task => self.task_mode.task_modal.focus_handle(cx),
296 NewProcessMode::Attach => self.attach_mode.read(cx).attach_picker.focus_handle(cx),
297 NewProcessMode::Launch => self.configure_mode.read(cx).program.focus_handle(cx),
298 NewProcessMode::Debug => self.debug_picker.focus_handle(cx),
299 }
300 }
301
302 fn debug_scenario(&self, debugger: &str, cx: &App) -> Task<Option<DebugScenario>> {
303 let request = match self.mode {
304 NewProcessMode::Launch => {
305 DebugRequest::Launch(self.configure_mode.read(cx).debug_request(cx))
306 }
307 NewProcessMode::Attach => {
308 DebugRequest::Attach(self.attach_mode.read(cx).debug_request())
309 }
310 _ => return Task::ready(None),
311 };
312 let label = suggested_label(&request, debugger);
313
314 let stop_on_entry = if let NewProcessMode::Launch = &self.mode {
315 Some(self.configure_mode.read(cx).stop_on_entry.selected())
316 } else {
317 None
318 };
319
320 let session_scenario = ZedDebugConfig {
321 adapter: debugger.to_owned().into(),
322 label,
323 request,
324 stop_on_entry,
325 };
326
327 let adapter = cx
328 .global::<DapRegistry>()
329 .adapter(&session_scenario.adapter);
330
331 cx.spawn(async move |_| adapter?.config_from_zed_format(session_scenario).await.ok())
332 }
333
334 fn start_new_session(&mut self, window: &mut Window, cx: &mut Context<Self>) {
335 if self.debugger.as_ref().is_none() {
336 return;
337 }
338
339 if let NewProcessMode::Debug = &self.mode {
340 self.debug_picker.update(cx, |picker, cx| {
341 picker.delegate.confirm(false, window, cx);
342 });
343 return;
344 }
345
346 if let NewProcessMode::Launch = &self.mode
347 && self.configure_mode.read(cx).save_to_debug_json.selected() {
348 self.save_debug_scenario(window, cx);
349 }
350
351 let Some(debugger) = self.debugger.clone() else {
352 return;
353 };
354
355 let debug_panel = self.debug_panel.clone();
356 let Some(task_contexts) = self.task_contexts(cx) else {
357 return;
358 };
359
360 let task_context = task_contexts.active_context().cloned().unwrap_or_default();
361 let worktree_id = task_contexts.worktree();
362 let mode = self.mode;
363 cx.spawn_in(window, async move |this, cx| {
364 let Some(config) = this
365 .update(cx, |this, cx| this.debug_scenario(&debugger, cx))?
366 .await
367 else {
368 bail!("debug config not found in mode: {mode}");
369 };
370
371 debug_panel.update_in(cx, |debug_panel, window, cx| {
372 send_telemetry(&config, TelemetrySpawnLocation::Custom, cx);
373 debug_panel.start_session(config, task_context, None, worktree_id, window, cx)
374 })?;
375 this.update(cx, |_, cx| {
376 cx.emit(DismissEvent);
377 })
378 .ok();
379 anyhow::Ok(())
380 })
381 .detach_and_log_err(cx);
382 }
383
384 fn update_attach_picker(
385 attach: &Entity<AttachMode>,
386 adapter: &DebugAdapterName,
387 window: &mut Window,
388 cx: &mut App,
389 ) {
390 attach.update(cx, |this, cx| {
391 if adapter.0 != this.definition.adapter {
392 this.definition.adapter = adapter.0.clone();
393
394 this.attach_picker.update(cx, |this, cx| {
395 this.picker.update(cx, |this, cx| {
396 this.delegate.definition.adapter = adapter.0.clone();
397 this.focus(window, cx);
398 })
399 });
400 }
401
402 cx.notify();
403 })
404 }
405
406 fn task_contexts(&self, cx: &App) -> Option<Arc<TaskContexts>> {
407 self.debug_picker.read(cx).delegate.task_contexts.clone()
408 }
409
410 pub fn save_debug_scenario(&mut self, window: &mut Window, cx: &mut Context<Self>) {
411 let task_contexts = self.task_contexts(cx);
412 let Some(adapter) = self.debugger.as_ref() else {
413 return;
414 };
415 let scenario = self.debug_scenario(adapter, cx);
416 cx.spawn_in(window, async move |this, cx| {
417 let scenario = scenario.await.context("no scenario to save")?;
418 let worktree_id = task_contexts
419 .context("no task contexts")?
420 .worktree()
421 .context("no active worktree")?;
422 this.update_in(cx, |this, window, cx| {
423 this.debug_panel.update(cx, |panel, cx| {
424 panel.save_scenario(scenario, worktree_id, window, cx)
425 })
426 })??
427 .await?;
428 this.update_in(cx, |_, _, cx| {
429 cx.emit(DismissEvent);
430 })
431 })
432 .detach_and_prompt_err("Failed to edit debug.json", window, cx, |_, _, _| None);
433 }
434
435 fn adapter_drop_down_menu(
436 &mut self,
437 window: &mut Window,
438 cx: &mut Context<Self>,
439 ) -> ui::DropdownMenu {
440 let workspace = self.workspace.clone();
441 let weak = cx.weak_entity();
442 let active_buffer = self.task_contexts(cx).and_then(|tc| {
443 tc.active_item_context
444 .as_ref()
445 .and_then(|aic| aic.1.as_ref().map(|l| l.buffer.clone()))
446 });
447
448 let active_buffer_language = active_buffer
449 .and_then(|buffer| buffer.read(cx).language())
450 .cloned();
451
452 let mut available_adapters: Vec<_> = workspace
453 .update(cx, |_, cx| DapRegistry::global(cx).enumerate_adapters())
454 .unwrap_or_default();
455 if let Some(language) = active_buffer_language {
456 available_adapters.sort_by_key(|adapter| {
457 language
458 .config()
459 .debuggers
460 .get_index_of(adapter.0.as_ref())
461 .unwrap_or(usize::MAX)
462 });
463 if self.debugger.is_none() {
464 self.debugger = available_adapters.first().cloned();
465 }
466 }
467
468 let label = self
469 .debugger
470 .as_ref()
471 .map(|d| d.0.clone())
472 .unwrap_or_else(|| SELECT_DEBUGGER_LABEL.clone());
473
474 DropdownMenu::new(
475 "dap-adapter-picker",
476 label,
477 ContextMenu::build(window, cx, move |mut menu, _, _| {
478 let setter_for_name = |name: DebugAdapterName| {
479 let weak = weak.clone();
480 move |window: &mut Window, cx: &mut App| {
481 weak.update(cx, |this, cx| {
482 this.debugger = Some(name.clone());
483 cx.notify();
484 if let NewProcessMode::Attach = &this.mode {
485 Self::update_attach_picker(&this.attach_mode, &name, window, cx);
486 }
487 })
488 .ok();
489 }
490 };
491
492 for adapter in available_adapters.into_iter() {
493 menu = menu.entry(adapter.0.clone(), None, setter_for_name(adapter.clone()));
494 }
495
496 menu
497 }),
498 )
499 }
500}
501
502static SELECT_DEBUGGER_LABEL: SharedString = SharedString::new_static("Select Debugger");
503
504#[derive(Clone, Copy)]
505pub(crate) enum NewProcessMode {
506 Task,
507 Launch,
508 Attach,
509 Debug,
510}
511
512impl std::fmt::Display for NewProcessMode {
513 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
514 let mode = match self {
515 NewProcessMode::Task => "Run",
516 NewProcessMode::Debug => "Debug",
517 NewProcessMode::Attach => "Attach",
518 NewProcessMode::Launch => "Launch",
519 };
520
521 write!(f, "{}", mode)
522 }
523}
524
525impl Focusable for NewProcessMode {
526 fn focus_handle(&self, cx: &App) -> FocusHandle {
527 cx.focus_handle()
528 }
529}
530
531fn render_editor(editor: &Entity<Editor>, window: &mut Window, cx: &App) -> impl IntoElement {
532 let settings = ThemeSettings::get_global(cx);
533 let theme = cx.theme();
534
535 let text_style = TextStyle {
536 color: cx.theme().colors().text,
537 font_family: settings.buffer_font.family.clone(),
538 font_features: settings.buffer_font.features.clone(),
539 font_size: settings.buffer_font_size(cx).into(),
540 font_weight: settings.buffer_font.weight,
541 line_height: relative(settings.buffer_line_height.value()),
542 background_color: Some(theme.colors().editor_background),
543 ..Default::default()
544 };
545
546 let element = EditorElement::new(
547 editor,
548 EditorStyle {
549 background: theme.colors().editor_background,
550 local_player: theme.players().local(),
551 text: text_style,
552 ..Default::default()
553 },
554 );
555
556 div()
557 .rounded_md()
558 .p_1()
559 .border_1()
560 .border_color(theme.colors().border_variant)
561 .when(
562 editor.focus_handle(cx).contains_focused(window, cx),
563 |this| this.border_color(theme.colors().border_focused),
564 )
565 .child(element)
566 .bg(theme.colors().editor_background)
567}
568
569impl Render for NewProcessModal {
570 fn render(
571 &mut self,
572 window: &mut ui::Window,
573 cx: &mut ui::Context<Self>,
574 ) -> impl ui::IntoElement {
575 v_flex()
576 .key_context({
577 let mut key_context = KeyContext::new_with_defaults();
578 key_context.add("Pane");
579 key_context.add("RunModal");
580 key_context
581 })
582 .size_full()
583 .w(rems(34.))
584 .elevation_3(cx)
585 .overflow_hidden()
586 .on_action(cx.listener(|_, _: &menu::Cancel, _, cx| {
587 cx.emit(DismissEvent);
588 }))
589 .on_action(cx.listener(|this, _: &pane::ActivateNextItem, window, cx| {
590 this.mode = match this.mode {
591 NewProcessMode::Task => NewProcessMode::Debug,
592 NewProcessMode::Debug => NewProcessMode::Attach,
593 NewProcessMode::Attach => NewProcessMode::Launch,
594 NewProcessMode::Launch => NewProcessMode::Task,
595 };
596
597 this.mode_focus_handle(cx).focus(window);
598 }))
599 .on_action(
600 cx.listener(|this, _: &pane::ActivatePreviousItem, window, cx| {
601 this.mode = match this.mode {
602 NewProcessMode::Task => NewProcessMode::Launch,
603 NewProcessMode::Debug => NewProcessMode::Task,
604 NewProcessMode::Attach => NewProcessMode::Debug,
605 NewProcessMode::Launch => NewProcessMode::Attach,
606 };
607
608 this.mode_focus_handle(cx).focus(window);
609 }),
610 )
611 .child(
612 h_flex()
613 .p_2()
614 .w_full()
615 .border_b_1()
616 .border_color(cx.theme().colors().border_variant)
617 .child(
618 ToggleButton::new(
619 "debugger-session-ui-tasks-button",
620 NewProcessMode::Task.to_string(),
621 )
622 .size(ButtonSize::Default)
623 .toggle_state(matches!(self.mode, NewProcessMode::Task))
624 .style(ui::ButtonStyle::Subtle)
625 .on_click(cx.listener(|this, _, window, cx| {
626 this.mode = NewProcessMode::Task;
627 this.mode_focus_handle(cx).focus(window);
628 cx.notify();
629 }))
630 .tooltip(Tooltip::text("Run predefined task"))
631 .first(),
632 )
633 .child(
634 ToggleButton::new(
635 "debugger-session-ui-launch-button",
636 NewProcessMode::Debug.to_string(),
637 )
638 .size(ButtonSize::Default)
639 .style(ui::ButtonStyle::Subtle)
640 .toggle_state(matches!(self.mode, NewProcessMode::Debug))
641 .on_click(cx.listener(|this, _, window, cx| {
642 this.mode = NewProcessMode::Debug;
643 this.mode_focus_handle(cx).focus(window);
644 cx.notify();
645 }))
646 .tooltip(Tooltip::text("Start a predefined debug scenario"))
647 .middle(),
648 )
649 .child(
650 ToggleButton::new(
651 "debugger-session-ui-attach-button",
652 NewProcessMode::Attach.to_string(),
653 )
654 .size(ButtonSize::Default)
655 .toggle_state(matches!(self.mode, NewProcessMode::Attach))
656 .style(ui::ButtonStyle::Subtle)
657 .on_click(cx.listener(|this, _, window, cx| {
658 this.mode = NewProcessMode::Attach;
659
660 if let Some(debugger) = this.debugger.as_ref() {
661 Self::update_attach_picker(&this.attach_mode, debugger, window, cx);
662 }
663 this.mode_focus_handle(cx).focus(window);
664 cx.notify();
665 }))
666 .tooltip(Tooltip::text("Attach the debugger to a running process"))
667 .middle(),
668 )
669 .child(
670 ToggleButton::new(
671 "debugger-session-ui-custom-button",
672 NewProcessMode::Launch.to_string(),
673 )
674 .size(ButtonSize::Default)
675 .toggle_state(matches!(self.mode, NewProcessMode::Launch))
676 .style(ui::ButtonStyle::Subtle)
677 .on_click(cx.listener(|this, _, window, cx| {
678 this.mode = NewProcessMode::Launch;
679 this.mode_focus_handle(cx).focus(window);
680 cx.notify();
681 }))
682 .tooltip(Tooltip::text("Launch a new process with a debugger"))
683 .last(),
684 ),
685 )
686 .child(v_flex().child(self.render_mode(window, cx)))
687 .map(|el| {
688 let container = h_flex()
689 .w_full()
690 .p_1p5()
691 .gap_2()
692 .justify_between()
693 .border_t_1()
694 .border_color(cx.theme().colors().border_variant);
695 match self.mode {
696 NewProcessMode::Launch => el.child(
697 container
698 .child(
699 h_flex().child(
700 Button::new("edit-custom-debug", "Edit in debug.json")
701 .on_click(cx.listener(|this, _, window, cx| {
702 this.save_debug_scenario(window, cx);
703 }))
704 .disabled(
705 self.debugger.is_none()
706 || self
707 .configure_mode
708 .read(cx)
709 .program
710 .read(cx)
711 .is_empty(cx),
712 ),
713 ),
714 )
715 .child(
716 Button::new("debugger-spawn", "Start")
717 .on_click(cx.listener(|this, _, window, cx| {
718 this.start_new_session(window, cx)
719 }))
720 .disabled(
721 self.debugger.is_none()
722 || self
723 .configure_mode
724 .read(cx)
725 .program
726 .read(cx)
727 .is_empty(cx),
728 ),
729 ),
730 ),
731 NewProcessMode::Attach => el.child({
732 let disabled = self.debugger.is_none()
733 || self
734 .attach_mode
735 .read(cx)
736 .attach_picker
737 .read(cx)
738 .picker
739 .read(cx)
740 .delegate
741 .match_count()
742 == 0;
743 let secondary_action = menu::SecondaryConfirm.boxed_clone();
744 container
745 .child(div().children(
746 KeyBinding::for_action(&*secondary_action, window, cx).map(
747 |keybind| {
748 Button::new("edit-attach-task", "Edit in debug.json")
749 .label_size(LabelSize::Small)
750 .key_binding(keybind)
751 .on_click(move |_, window, cx| {
752 window.dispatch_action(
753 secondary_action.boxed_clone(),
754 cx,
755 )
756 })
757 .disabled(disabled)
758 },
759 ),
760 ))
761 .child(
762 h_flex()
763 .child(div().child(self.adapter_drop_down_menu(window, cx))),
764 )
765 }),
766 NewProcessMode::Debug => el,
767 NewProcessMode::Task => el,
768 }
769 })
770 }
771}
772
773impl EventEmitter<DismissEvent> for NewProcessModal {}
774impl Focusable for NewProcessModal {
775 fn focus_handle(&self, cx: &ui::App) -> gpui::FocusHandle {
776 self.mode_focus_handle(cx)
777 }
778}
779
780impl ModalView for NewProcessModal {}
781
782impl RenderOnce for AttachMode {
783 fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
784 v_flex()
785 .w_full()
786 .track_focus(&self.attach_picker.focus_handle(cx))
787 .child(self.attach_picker.clone())
788 }
789}
790
791#[derive(Clone)]
792pub(super) struct ConfigureMode {
793 program: Entity<Editor>,
794 cwd: Entity<Editor>,
795 stop_on_entry: ToggleState,
796 save_to_debug_json: ToggleState,
797}
798
799impl ConfigureMode {
800 pub(super) fn new(window: &mut Window, cx: &mut App) -> Entity<Self> {
801 let program = cx.new(|cx| Editor::single_line(window, cx));
802 program.update(cx, |this, cx| {
803 this.set_placeholder_text("ENV=Zed ~/bin/program --option", cx);
804 });
805
806 let cwd = cx.new(|cx| Editor::single_line(window, cx));
807 cwd.update(cx, |this, cx| {
808 this.set_placeholder_text("Ex: $ZED_WORKTREE_ROOT", cx);
809 });
810
811 cx.new(|_| Self {
812 program,
813 cwd,
814 stop_on_entry: ToggleState::Unselected,
815 save_to_debug_json: ToggleState::Unselected,
816 })
817 }
818
819 fn load(&mut self, cwd: PathBuf, window: &mut Window, cx: &mut App) {
820 self.cwd.update(cx, |editor, cx| {
821 if editor.is_empty(cx) {
822 editor.set_text(cwd.to_string_lossy(), window, cx);
823 }
824 });
825 }
826
827 pub(super) fn debug_request(&self, cx: &App) -> task::LaunchRequest {
828 let cwd_text = self.cwd.read(cx).text(cx);
829 let cwd = if cwd_text.is_empty() {
830 None
831 } else {
832 Some(PathBuf::from(cwd_text))
833 };
834
835 if cfg!(windows) {
836 return task::LaunchRequest {
837 program: self.program.read(cx).text(cx),
838 cwd,
839 args: Default::default(),
840 env: Default::default(),
841 };
842 }
843 let command = self.program.read(cx).text(cx);
844 let mut args = shlex::split(&command).into_iter().flatten().peekable();
845 let mut env = FxHashMap::default();
846 while args.peek().is_some_and(|arg| arg.contains('=')) {
847 let arg = args.next().unwrap();
848 let (lhs, rhs) = arg.split_once('=').unwrap();
849 env.insert(lhs.to_string(), rhs.to_string());
850 }
851
852 let program = if let Some(program) = args.next() {
853 program
854 } else {
855 env = FxHashMap::default();
856 command
857 };
858
859 let args = args.collect::<Vec<_>>();
860
861 task::LaunchRequest {
862 program,
863 cwd,
864 args,
865 env,
866 }
867 }
868
869 fn render(
870 &mut self,
871 adapter_menu: DropdownMenu,
872 window: &mut Window,
873 cx: &mut ui::Context<Self>,
874 ) -> impl IntoElement {
875 v_flex()
876 .p_2()
877 .w_full()
878 .gap_2()
879 .track_focus(&self.program.focus_handle(cx))
880 .child(
881 h_flex()
882 .gap_2()
883 .child(
884 Label::new("Debugger")
885 .size(LabelSize::Small)
886 .color(Color::Muted),
887 )
888 .child(adapter_menu),
889 )
890 .child(
891 v_flex()
892 .gap_0p5()
893 .child(
894 Label::new("Program")
895 .size(LabelSize::Small)
896 .color(Color::Muted),
897 )
898 .child(render_editor(&self.program, window, cx)),
899 )
900 .child(
901 v_flex()
902 .gap_0p5()
903 .child(
904 Label::new("Working Directory")
905 .size(LabelSize::Small)
906 .color(Color::Muted),
907 )
908 .child(render_editor(&self.cwd, window, cx)),
909 )
910 .child(
911 CheckboxWithLabel::new(
912 "debugger-stop-on-entry",
913 Label::new("Stop on Entry")
914 .size(LabelSize::Small)
915 .color(Color::Muted),
916 self.stop_on_entry,
917 {
918 let this = cx.weak_entity();
919 move |state, _, cx| {
920 this.update(cx, |this, _| {
921 this.stop_on_entry = *state;
922 })
923 .ok();
924 }
925 },
926 )
927 .checkbox_position(ui::IconPosition::End),
928 )
929 }
930}
931
932#[derive(Clone)]
933pub(super) struct AttachMode {
934 pub(super) definition: ZedDebugConfig,
935 pub(super) attach_picker: Entity<AttachModal>,
936}
937
938impl AttachMode {
939 pub(super) fn new(
940 debugger: Option<DebugAdapterName>,
941 workspace: WeakEntity<Workspace>,
942 window: &mut Window,
943 cx: &mut Context<NewProcessModal>,
944 ) -> Entity<Self> {
945 let definition = ZedDebugConfig {
946 adapter: debugger.unwrap_or(DebugAdapterName("".into())).0,
947 label: "Attach New Session Setup".into(),
948 request: dap::DebugRequest::Attach(task::AttachRequest { process_id: None }),
949 stop_on_entry: Some(false),
950 };
951 let attach_picker = cx.new(|cx| {
952 let modal = AttachModal::new(definition.clone(), workspace, false, window, cx);
953 window.focus(&modal.focus_handle(cx));
954
955 modal
956 });
957
958 cx.new(|_| Self {
959 definition,
960 attach_picker,
961 })
962 }
963 pub(super) fn debug_request(&self) -> task::AttachRequest {
964 task::AttachRequest { process_id: None }
965 }
966}
967
968#[derive(Clone)]
969pub(super) struct TaskMode {
970 pub(super) task_modal: Entity<TasksModal>,
971}
972
973pub(super) struct DebugDelegate {
974 task_store: Entity<TaskStore>,
975 candidates: Vec<(
976 Option<TaskSourceKind>,
977 DebugScenario,
978 Option<DebugScenarioContext>,
979 )>,
980 selected_index: usize,
981 matches: Vec<StringMatch>,
982 prompt: String,
983 debug_panel: WeakEntity<DebugPanel>,
984 task_contexts: Option<Arc<TaskContexts>>,
985 divider_index: Option<usize>,
986 last_used_candidate_index: Option<usize>,
987}
988
989impl DebugDelegate {
990 pub(super) fn new(debug_panel: WeakEntity<DebugPanel>, task_store: Entity<TaskStore>) -> Self {
991 Self {
992 task_store,
993 candidates: Vec::default(),
994 selected_index: 0,
995 matches: Vec::new(),
996 prompt: String::new(),
997 debug_panel,
998 task_contexts: None,
999 divider_index: None,
1000 last_used_candidate_index: None,
1001 }
1002 }
1003
1004 fn get_scenario_kind(
1005 languages: &Arc<LanguageRegistry>,
1006 dap_registry: &DapRegistry,
1007 scenario: DebugScenario,
1008 ) -> (Option<TaskSourceKind>, DebugScenario) {
1009 let language_names = languages.language_names();
1010 let language = dap_registry
1011 .adapter_language(&scenario.adapter)
1012 .map(|language| TaskSourceKind::Language { name: language.0 });
1013
1014 let language = language.or_else(|| {
1015 scenario.label.split_whitespace().find_map(|word| {
1016 language_names
1017 .iter()
1018 .find(|name| name.as_ref().eq_ignore_ascii_case(word))
1019 .map(|name| TaskSourceKind::Language {
1020 name: name.to_owned().into(),
1021 })
1022 })
1023 });
1024
1025 (language, scenario)
1026 }
1027
1028 pub fn tasks_loaded(
1029 &mut self,
1030 task_contexts: Arc<TaskContexts>,
1031 languages: Arc<LanguageRegistry>,
1032 lsp_tasks: Vec<(TaskSourceKind, task::ResolvedTask)>,
1033 current_resolved_tasks: Vec<(TaskSourceKind, task::ResolvedTask)>,
1034 add_current_language_tasks: bool,
1035 cx: &mut Context<Picker<Self>>,
1036 ) -> Task<()> {
1037 self.task_contexts = Some(task_contexts.clone());
1038 let task = self.task_store.update(cx, |task_store, cx| {
1039 task_store.task_inventory().map(|inventory| {
1040 inventory.update(cx, |inventory, cx| {
1041 inventory.list_debug_scenarios(
1042 &task_contexts,
1043 lsp_tasks,
1044 current_resolved_tasks,
1045 add_current_language_tasks,
1046 cx,
1047 )
1048 })
1049 })
1050 });
1051
1052 let valid_adapters: HashSet<_> = cx.global::<DapRegistry>().enumerate_adapters();
1053
1054 cx.spawn(async move |this, cx| {
1055 let (recent, scenarios) = if let Some(task) = task {
1056 task.await
1057 } else {
1058 (Vec::new(), Vec::new())
1059 };
1060
1061 this.update(cx, |this, cx| {
1062 if !recent.is_empty() {
1063 this.delegate.last_used_candidate_index = Some(recent.len() - 1);
1064 }
1065
1066 let dap_registry = cx.global::<DapRegistry>();
1067 let hide_vscode = scenarios.iter().any(|(kind, _)| match kind {
1068 TaskSourceKind::Worktree {
1069 id: _,
1070 directory_in_worktree: dir,
1071 id_base: _,
1072 } => dir.ends_with(".zed"),
1073 _ => false,
1074 });
1075
1076 this.delegate.candidates = recent
1077 .into_iter()
1078 .map(|(scenario, context)| {
1079 let (kind, scenario) =
1080 Self::get_scenario_kind(&languages, dap_registry, scenario);
1081 (kind, scenario, Some(context))
1082 })
1083 .chain(
1084 scenarios
1085 .into_iter()
1086 .filter(|(kind, _)| match kind {
1087 TaskSourceKind::Worktree {
1088 id: _,
1089 directory_in_worktree: dir,
1090 id_base: _,
1091 } => !(hide_vscode && dir.ends_with(".vscode")),
1092 _ => true,
1093 })
1094 .filter(|(_, scenario)| valid_adapters.contains(&scenario.adapter))
1095 .map(|(kind, scenario)| {
1096 let (language, scenario) =
1097 Self::get_scenario_kind(&languages, dap_registry, scenario);
1098 (language.or(Some(kind)), scenario, None)
1099 }),
1100 )
1101 .collect();
1102 })
1103 .ok();
1104 })
1105 }
1106}
1107
1108impl PickerDelegate for DebugDelegate {
1109 type ListItem = ui::ListItem;
1110
1111 fn match_count(&self) -> usize {
1112 self.matches.len()
1113 }
1114
1115 fn selected_index(&self) -> usize {
1116 self.selected_index
1117 }
1118
1119 fn set_selected_index(
1120 &mut self,
1121 ix: usize,
1122 _window: &mut Window,
1123 _cx: &mut Context<picker::Picker<Self>>,
1124 ) {
1125 self.selected_index = ix;
1126 }
1127
1128 fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> std::sync::Arc<str> {
1129 "Find a debug task, or debug a command.".into()
1130 }
1131
1132 fn update_matches(
1133 &mut self,
1134 query: String,
1135 window: &mut Window,
1136 cx: &mut Context<picker::Picker<Self>>,
1137 ) -> gpui::Task<()> {
1138 let candidates = self.candidates.clone();
1139
1140 cx.spawn_in(window, async move |picker, cx| {
1141 let candidates: Vec<_> = candidates
1142 .into_iter()
1143 .enumerate()
1144 .map(|(index, (_, candidate, _))| {
1145 StringMatchCandidate::new(index, candidate.label.as_ref())
1146 })
1147 .collect();
1148
1149 let matches = fuzzy::match_strings(
1150 &candidates,
1151 &query,
1152 true,
1153 true,
1154 1000,
1155 &Default::default(),
1156 cx.background_executor().clone(),
1157 )
1158 .await;
1159
1160 picker
1161 .update(cx, |picker, _| {
1162 let delegate = &mut picker.delegate;
1163
1164 delegate.matches = matches;
1165 delegate.prompt = query;
1166
1167 delegate.divider_index = delegate.last_used_candidate_index.and_then(|index| {
1168 let index = delegate
1169 .matches
1170 .partition_point(|matching_task| matching_task.candidate_id <= index);
1171 Some(index).and_then(|index| (index != 0).then(|| index - 1))
1172 });
1173
1174 if delegate.matches.is_empty() {
1175 delegate.selected_index = 0;
1176 } else {
1177 delegate.selected_index =
1178 delegate.selected_index.min(delegate.matches.len() - 1);
1179 }
1180 })
1181 .log_err();
1182 })
1183 }
1184
1185 fn separators_after_indices(&self) -> Vec<usize> {
1186 if let Some(i) = self.divider_index {
1187 vec![i]
1188 } else {
1189 Vec::new()
1190 }
1191 }
1192
1193 fn confirm_input(&mut self, _: bool, window: &mut Window, cx: &mut Context<Picker<Self>>) {
1194 let text = self.prompt.clone();
1195 let (task_context, worktree_id) = self
1196 .task_contexts
1197 .as_ref()
1198 .and_then(|task_contexts| {
1199 Some((
1200 task_contexts.active_context().cloned()?,
1201 task_contexts.worktree(),
1202 ))
1203 })
1204 .unwrap_or_default();
1205
1206 let mut args = shlex::split(&text).into_iter().flatten().peekable();
1207 let mut env = HashMap::default();
1208 while args.peek().is_some_and(|arg| arg.contains('=')) {
1209 let arg = args.next().unwrap();
1210 let (lhs, rhs) = arg.split_once('=').unwrap();
1211 env.insert(lhs.to_string(), rhs.to_string());
1212 }
1213
1214 let program = if let Some(program) = args.next() {
1215 program
1216 } else {
1217 env = HashMap::default();
1218 text
1219 };
1220
1221 let args = args.collect::<Vec<_>>();
1222 let task = task::TaskTemplate {
1223 label: "one-off".to_owned(), // TODO: rename using command as label
1224 env,
1225 command: program,
1226 args,
1227 ..Default::default()
1228 };
1229
1230 let Some(location) = self
1231 .task_contexts
1232 .as_ref()
1233 .and_then(|cx| cx.location().cloned())
1234 else {
1235 return;
1236 };
1237 let file = location.buffer.read(cx).file();
1238 let language = location.buffer.read(cx).language();
1239 let language_name = language.as_ref().map(|l| l.name());
1240 let Some(adapter): Option<DebugAdapterName> =
1241 language::language_settings::language_settings(language_name, file, cx)
1242 .debuggers
1243 .first()
1244 .map(SharedString::from)
1245 .map(Into::into)
1246 .or_else(|| {
1247 language.and_then(|l| {
1248 l.config()
1249 .debuggers
1250 .first()
1251 .map(SharedString::from)
1252 .map(Into::into)
1253 })
1254 })
1255 else {
1256 return;
1257 };
1258 let locators = cx.global::<DapRegistry>().locators();
1259 cx.spawn_in(window, async move |this, cx| {
1260 let Some(debug_scenario) = cx
1261 .background_spawn(async move {
1262 for locator in locators {
1263 if let Some(scenario) =
1264 // TODO: use a more informative label than "one-off"
1265 locator
1266 .1
1267 .create_scenario(&task, &task.label, &adapter)
1268 .await
1269 {
1270 return Some(scenario);
1271 }
1272 }
1273 None
1274 })
1275 .await
1276 else {
1277 return;
1278 };
1279
1280 this.update_in(cx, |this, window, cx| {
1281 send_telemetry(&debug_scenario, TelemetrySpawnLocation::ScenarioList, cx);
1282 this.delegate
1283 .debug_panel
1284 .update(cx, |panel, cx| {
1285 panel.start_session(
1286 debug_scenario,
1287 task_context,
1288 None,
1289 worktree_id,
1290 window,
1291 cx,
1292 );
1293 })
1294 .ok();
1295 cx.emit(DismissEvent);
1296 })
1297 .ok();
1298 })
1299 .detach();
1300 }
1301
1302 fn confirm(
1303 &mut self,
1304 secondary: bool,
1305 window: &mut Window,
1306 cx: &mut Context<picker::Picker<Self>>,
1307 ) {
1308 let debug_scenario = self
1309 .matches
1310 .get(self.selected_index())
1311 .and_then(|match_candidate| self.candidates.get(match_candidate.candidate_id).cloned());
1312
1313 let Some((kind, debug_scenario, context)) = debug_scenario else {
1314 return;
1315 };
1316
1317 let context = context.unwrap_or_else(|| {
1318 self.task_contexts
1319 .as_ref()
1320 .and_then(|task_contexts| {
1321 Some(DebugScenarioContext {
1322 task_context: task_contexts.active_context().cloned()?,
1323 active_buffer: None,
1324 worktree_id: task_contexts.worktree(),
1325 })
1326 })
1327 .unwrap_or_default()
1328 });
1329 let DebugScenarioContext {
1330 task_context,
1331 active_buffer: _,
1332 worktree_id,
1333 } = context;
1334
1335 if secondary {
1336 let Some(kind) = kind else { return };
1337 let Some(id) = worktree_id else { return };
1338 let debug_panel = self.debug_panel.clone();
1339 cx.spawn_in(window, async move |_, cx| {
1340 debug_panel
1341 .update_in(cx, |debug_panel, window, cx| {
1342 debug_panel.go_to_scenario_definition(kind, debug_scenario, id, window, cx)
1343 })?
1344 .await?;
1345 anyhow::Ok(())
1346 })
1347 .detach();
1348 } else {
1349 send_telemetry(&debug_scenario, TelemetrySpawnLocation::ScenarioList, cx);
1350 self.debug_panel
1351 .update(cx, |panel, cx| {
1352 panel.start_session(
1353 debug_scenario,
1354 task_context,
1355 None,
1356 worktree_id,
1357 window,
1358 cx,
1359 );
1360 })
1361 .ok();
1362 }
1363
1364 cx.emit(DismissEvent);
1365 }
1366
1367 fn dismissed(&mut self, _: &mut Window, cx: &mut Context<picker::Picker<Self>>) {
1368 cx.emit(DismissEvent);
1369 }
1370
1371 fn render_footer(
1372 &self,
1373 window: &mut Window,
1374 cx: &mut Context<Picker<Self>>,
1375 ) -> Option<ui::AnyElement> {
1376 let current_modifiers = window.modifiers();
1377 let footer = h_flex()
1378 .w_full()
1379 .p_1p5()
1380 .justify_between()
1381 .border_t_1()
1382 .border_color(cx.theme().colors().border_variant)
1383 .children({
1384 let action = menu::SecondaryConfirm.boxed_clone();
1385 KeyBinding::for_action(&*action, window, cx).map(|keybind| {
1386 Button::new("edit-debug-task", "Edit in debug.json")
1387 .label_size(LabelSize::Small)
1388 .key_binding(keybind)
1389 .on_click(move |_, window, cx| {
1390 window.dispatch_action(action.boxed_clone(), cx)
1391 })
1392 })
1393 })
1394 .map(|this| {
1395 if (current_modifiers.alt || self.matches.is_empty()) && !self.prompt.is_empty() {
1396 let action = picker::ConfirmInput { secondary: false }.boxed_clone();
1397 this.children(KeyBinding::for_action(&*action, window, cx).map(|keybind| {
1398 Button::new("launch-custom", "Launch Custom")
1399 .key_binding(keybind)
1400 .on_click(move |_, window, cx| {
1401 window.dispatch_action(action.boxed_clone(), cx)
1402 })
1403 }))
1404 } else {
1405 this.children(KeyBinding::for_action(&menu::Confirm, window, cx).map(
1406 |keybind| {
1407 let is_recent_selected =
1408 self.divider_index >= Some(self.selected_index);
1409 let run_entry_label =
1410 if is_recent_selected { "Rerun" } else { "Spawn" };
1411
1412 Button::new("spawn", run_entry_label)
1413 .key_binding(keybind)
1414 .on_click(|_, window, cx| {
1415 window.dispatch_action(menu::Confirm.boxed_clone(), cx);
1416 })
1417 },
1418 ))
1419 }
1420 });
1421 Some(footer.into_any_element())
1422 }
1423
1424 fn render_match(
1425 &self,
1426 ix: usize,
1427 selected: bool,
1428 window: &mut Window,
1429 cx: &mut Context<picker::Picker<Self>>,
1430 ) -> Option<Self::ListItem> {
1431 let hit = &self.matches[ix];
1432
1433 let highlighted_location = HighlightedMatch {
1434 text: hit.string.clone(),
1435 highlight_positions: hit.positions.clone(),
1436 char_count: hit.string.chars().count(),
1437 color: Color::Default,
1438 };
1439 let task_kind = &self.candidates[hit.candidate_id].0;
1440
1441 let icon = match task_kind {
1442 Some(TaskSourceKind::UserInput) => Some(Icon::new(IconName::Terminal)),
1443 Some(TaskSourceKind::AbsPath { .. }) => Some(Icon::new(IconName::Settings)),
1444 Some(TaskSourceKind::Worktree { .. }) => Some(Icon::new(IconName::FileTree)),
1445 Some(TaskSourceKind::Lsp {
1446 language_name: name,
1447 ..
1448 })
1449 | Some(TaskSourceKind::Language { name }) => file_icons::FileIcons::get(cx)
1450 .get_icon_for_type(&name.to_lowercase(), cx)
1451 .map(Icon::from_path),
1452 None => Some(Icon::new(IconName::HistoryRerun)),
1453 }
1454 .map(|icon| icon.color(Color::Muted).size(IconSize::Small));
1455 let indicator = if matches!(task_kind, Some(TaskSourceKind::Lsp { .. })) {
1456 Some(Indicator::icon(
1457 Icon::new(IconName::BoltFilled)
1458 .color(Color::Muted)
1459 .size(IconSize::Small),
1460 ))
1461 } else {
1462 None
1463 };
1464 let icon = icon.map(|icon| {
1465 IconWithIndicator::new(icon, indicator)
1466 .indicator_border_color(Some(cx.theme().colors().border_transparent))
1467 });
1468
1469 Some(
1470 ListItem::new(SharedString::from(format!("debug-scenario-selection-{ix}")))
1471 .inset(true)
1472 .start_slot::<IconWithIndicator>(icon)
1473 .spacing(ListItemSpacing::Sparse)
1474 .toggle_state(selected)
1475 .child(highlighted_location.render(window, cx)),
1476 )
1477 }
1478}
1479
1480pub(crate) fn resolve_path(path: &mut String) {
1481 if path.starts_with('~') {
1482 let home = paths::home_dir().to_string_lossy().to_string();
1483 let trimmed_path = path.trim().to_owned();
1484 *path = trimmed_path.replacen('~', &home, 1);
1485 } else if let Some(strip_path) = path.strip_prefix(&format!(".{}", std::path::MAIN_SEPARATOR)) {
1486 *path = format!(
1487 "$ZED_WORKTREE_ROOT{}{}",
1488 std::path::MAIN_SEPARATOR,
1489 &strip_path
1490 );
1491 };
1492}
1493
1494#[cfg(test)]
1495impl NewProcessModal {
1496 pub(crate) fn set_configure(
1497 &mut self,
1498 program: impl AsRef<str>,
1499 cwd: impl AsRef<str>,
1500 stop_on_entry: bool,
1501 window: &mut Window,
1502 cx: &mut Context<Self>,
1503 ) {
1504 self.mode = NewProcessMode::Launch;
1505 self.debugger = Some(dap::adapters::DebugAdapterName("fake-adapter".into()));
1506
1507 self.configure_mode.update(cx, |configure, cx| {
1508 configure.program.update(cx, |editor, cx| {
1509 editor.clear(window, cx);
1510 editor.set_text(program.as_ref(), window, cx);
1511 });
1512
1513 configure.cwd.update(cx, |editor, cx| {
1514 editor.clear(window, cx);
1515 editor.set_text(cwd.as_ref(), window, cx);
1516 });
1517
1518 configure.stop_on_entry = match stop_on_entry {
1519 true => ToggleState::Selected,
1520 _ => ToggleState::Unselected,
1521 }
1522 })
1523 }
1524}