mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
debugger_ui: Enable search in debugger terminal panel (#56863)
When a debug session is running, pressing cmd-f (or using Edit → Find) in the terminal panel had no effect. Three things were missing: - The debugger panes never had a BufferSearchBar added to their toolbar, so there was no search UI to deploy. - SubView::as_searchable returned None for all item kinds, so even if a search bar were present it could not find a search target. - RunningState::render did not wrap its output with the pane search action handlers, so buffer_search::Deploy was never handled. Fix all three: - Register BufferSearchBar on each debugger pane toolbar via the PaneSearchBarCallbacks global (same pattern as terminal_panel). - Implement SubView::as_searchable for Terminal kind, delegating to the inner TerminalView which already implements SearchableItem. - Wrap RunningState::render with wrap_div_with_search_actions so the Deploy action reaches the active pane's toolbar. - Add refresh_terminal_toolbars to re-fire toolbar.set_active_item when the terminal entity is set, covering the case where the Terminal tab was already active before the terminal was created. Only refreshes panes where the Terminal subview is currently the active item. Add a test that verifies the active debugger pane toolbar has a BufferSearchBar after a session starts. Self-Review Checklist: - [ ] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [ ] Performance impact has been considered and is acceptable Fixes #38409 Release Notes: - Fixed `cmd-f` search not working in the debugger terminal panel. --------- Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
Generated
+1
@@ -4813,6 +4813,7 @@ dependencies = [
|
||||
"project",
|
||||
"rpc",
|
||||
"schemars 1.0.4",
|
||||
"search",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_json_lenient",
|
||||
|
||||
@@ -55,6 +55,7 @@ picker.workspace = true
|
||||
project.workspace = true
|
||||
rpc.workspace = true
|
||||
schemars.workspace = true
|
||||
search.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde_json_lenient.workspace = true
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user