Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
debugger_ui: Enable search in debugger terminal panel (#56863)
Sushank Mandalcb73ee1d45db
diff --git a/Cargo.lock b/Cargo.lockindex 05a1bb03a6d..fc5ad44ab7e 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4813,6 +4813,7 @@ dependencies = ["project","rpc","schemars 1.0.4",+ "search","serde","serde_json","serde_json_lenient",diff --git a/crates/debugger_ui/Cargo.toml b/crates/debugger_ui/Cargo.tomlindex c8fd8e6a8d0..826d24a1608 100644--- a/crates/debugger_ui/Cargo.toml+++ b/crates/debugger_ui/Cargo.toml@@ -55,6 +55,7 @@ picker.workspace = trueproject.workspace = truerpc.workspace = trueschemars.workspace = true+search.workspace = trueserde.workspace = trueserde_json.workspace = trueserde_json_lenient.workspace = truediff --git a/crates/debugger_ui/src/session/running.rs b/crates/debugger_ui/src/session/running.rsindex 8f4301913d9..8757683ee5c 100644--- a/crates/debugger_ui/src/session/running.rs+++ b/crates/debugger_ui/src/session/running.rs@@ -32,8 +32,8 @@ use dap::{};use futures::{SinkExt, channel::mpsc};use gpui::{- Action as _, AnyView, AppContext, Axis, Entity, EntityId, EventEmitter, FocusHandle, Focusable,- NoAction, Pixels, Point, Subscription, Task, TaskExt, WeakEntity,+ Action as _, AnyView, App, AppContext, Axis, Entity, EntityId, EventEmitter, FocusHandle,+ Focusable, NoAction, Pixels, Point, Subscription, Task, TaskExt, WeakEntity,};use language::Buffer;use loaded_source_list::LoadedSourceList;@@ -133,7 +133,14 @@ impl Render for RunningState {self.variable_list.update(cx, |this, cx| {this.disabled(thread_status != ThreadStatus::Stopped, cx);});- v_flex()+ let outer = cx+ .try_global::<workspace::PaneSearchBarCallbacks>()+ .map(|callbacks| {+ (callbacks.wrap_div_with_search_actions)(div(), self.active_pane.clone())+ })+ .unwrap_or_else(div);+ outer+ .v_flex().size_full().key_context("DebugSessionItem").track_focus(&self.focus_handle(cx))@@ -374,6 +381,19 @@ impl Item for SubView {true}++ fn as_searchable(+ &self,+ _: &Entity<Self>,+ cx: &App,+ ) -> Option<Box<dyn workspace::searchable::SearchableItemHandle>> {+ if self.kind != DebuggerPaneItem::Terminal {+ return None;+ }+ let debug_terminal = self.inner.clone().downcast::<DebugTerminal>().ok()?;+ let terminal_view = debug_terminal.read(cx).terminal.clone()?;+ Some(Box::new(terminal_view))+ }}impl Render for SubView {@@ -671,6 +691,11 @@ pub(crate) fn new_debugger_pane(pane.set_render_tab_bar(cx, {move |pane, window, cx| render_debugger_tab_bar(pane, &focus_handle, window, cx)});+ let toolbar = pane.toolbar().clone();+ if let Some(callbacks) = cx.try_global::<workspace::PaneSearchBarCallbacks>() {+ let languages = Some(project.read(cx).languages().clone());+ (callbacks.setup_search_bar)(languages, &toolbar, window, cx);+ }pane})}@@ -1219,6 +1244,7 @@ impl RunningState {debug_terminal.terminal = Some(terminal_view);cx.notify();});+ this.refresh_terminal_toolbars(window, cx);})?;let exit_status = terminal@@ -1383,6 +1409,7 @@ impl RunningState {debug_terminal.terminal = Some(terminal_view);cx.notify();});+ running.refresh_terminal_toolbars(window, cx);})?;terminal.read_with(cx, |terminal, _| {@@ -1486,6 +1513,26 @@ impl RunningState {})}+ fn refresh_terminal_toolbars(&mut self, window: &mut Window, cx: &mut Context<Self>) {+ let panes: Vec<Entity<Pane>> = self.panes.panes().into_iter().cloned().collect();+ for pane in panes {+ let is_active_terminal = pane.read(cx).active_item().is_some_and(|item| {+ item.act_as::<SubView>(cx)+ .is_some_and(|s| s.read(cx).kind == DebuggerPaneItem::Terminal)+ });+ if !is_active_terminal {+ continue;+ }+ pane.update(cx, |pane, cx| {+ let active = pane.active_item();+ let toolbar = pane.toolbar().clone();+ toolbar.update(cx, |toolbar, cx| {+ toolbar.set_active_item(active.as_deref(), window, cx);+ });+ });+ }+ }+pub(crate) fn add_pane_item(&mut self,item_kind: DebuggerPaneItem,diff --git a/crates/debugger_ui/src/tests/debugger_panel.rs b/crates/debugger_ui/src/tests/debugger_panel.rsindex ddc2bfa86e2..cd795e5a012 100644--- a/crates/debugger_ui/src/tests/debugger_panel.rs+++ b/crates/debugger_ui/src/tests/debugger_panel.rs@@ -18,7 +18,7 @@ use editor::{ActiveDebugLine, Editor, EditorMode, MultiBuffer,actions::{self},};-use gpui::{BackgroundExecutor, TestAppContext, VisualTestContext};+use gpui::{AppContext, BackgroundExecutor, TestAppContext, VisualTestContext};use project::{FakeFs, Project,debugger::session::{ThreadId, ThreadStatus},@@ -2691,3 +2691,82 @@ async fn test_restart_request_is_not_sent_more_than_once_until_response("A second restart should be allowed after the first one completes");}++#[gpui::test]+async fn test_debugger_terminal_pane_has_search_bar(+ executor: BackgroundExecutor,+ cx: &mut TestAppContext,+) {+ init_test(cx);++ cx.update(|cx| {+ cx.set_global(workspace::PaneSearchBarCallbacks {+ setup_search_bar: |languages, toolbar, window, cx| {+ let search_bar = cx.new(|cx| search::BufferSearchBar::new(languages, window, cx));+ toolbar.update(cx, |toolbar, cx| {+ toolbar.add_item(search_bar, window, cx);+ });+ },+ wrap_div_with_search_actions: search::buffer_search::register_pane_search_actions,+ });+ });++ let fs = FakeFs::new(executor.clone());+ fs.insert_tree(path!("/project"), json!({"main.rs": ""}))+ .await;+ let project = Project::test(fs, [path!("/project").as_ref()], cx).await;+ let workspace = init_test_workspace(&project, cx).await;+ let cx = &mut VisualTestContext::from_window(*workspace, cx);++ let session = start_debug_session(&workspace, cx, |_| {}).unwrap();+ let client = session.update(cx, |session, _| session.adapter_client().unwrap());++ client.on_request::<Threads, _>(move |_, _| {+ Ok(dap::ThreadsResponse {+ threads: vec![dap::Thread {+ id: 1,+ name: "main".into(),+ }],+ })+ });+ client.on_request::<StackTrace, _>(move |_, _| {+ Ok(dap::StackTraceResponse {+ stack_frames: vec![],+ total_frames: None,+ })+ });++ client+ .fake_event(dap::messages::Events::Stopped(dap::StoppedEvent {+ reason: dap::StoppedEventReason::Breakpoint,+ description: None,+ thread_id: Some(1),+ preserve_focus_hint: None,+ text: None,+ all_threads_stopped: None,+ hit_breakpoint_ids: None,+ }))+ .await;+ cx.run_until_parked();++ workspace+ .update(cx, |workspace, _, cx| {+ let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();+ let session = debug_panel+ .read(cx)+ .active_session()+ .expect("active session");+ let running_state = session.read(cx).running_state().clone();+ let active_pane = running_state.read(cx).active_pane().clone();+ let search_bar = active_pane+ .read(cx)+ .toolbar()+ .read(cx)+ .item_of_type::<search::BufferSearchBar>();+ assert!(+ search_bar.is_some(),+ "active debugger pane toolbar should have BufferSearchBar for cmd-f support"+ );+ })+ .unwrap();+}