editor: Show tooltips on breakpoints (#29523)

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-04-28 12:28:13 +02:00 committed by GitHub
parent 9bd0828303
commit ddfeb202a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 113 additions and 36 deletions

View file

@ -815,6 +815,16 @@ struct InlineBlamePopover {
popover_state: InlineBlamePopoverState,
}
/// Represents a breakpoint indicator that shows up when hovering over lines in the gutter that don't have
/// a breakpoint on them.
#[derive(Clone, Copy, Debug)]
struct PhantomBreakpointIndicator {
display_row: DisplayRow,
/// There's a small debounce between hovering over the line and showing the indicator.
/// We don't want to show the indicator when moving the mouse from editor to e.g. project panel.
is_active: bool,
collides_with_existing_breakpoint: bool,
}
/// Zed's primary implementation of text input, allowing users to edit a [`MultiBuffer`].
///
/// See the [module level documentation](self) for more information.
@ -963,10 +973,7 @@ pub struct Editor {
tasks: BTreeMap<(BufferId, BufferRow), RunnableTasks>,
tasks_update_task: Option<Task<()>>,
breakpoint_store: Option<Entity<BreakpointStore>>,
/// Allow's a user to create a breakpoint by selecting this indicator
/// It should be None while a user is not hovering over the gutter
/// Otherwise it represents the point that the breakpoint will be shown
gutter_breakpoint_indicator: (Option<(DisplayPoint, bool)>, Option<Task<()>>),
gutter_breakpoint_indicator: (Option<PhantomBreakpointIndicator>, Option<Task<()>>),
in_project_search: bool,
previous_search_ranges: Option<Arc<[Range<Anchor>]>>,
breadcrumb_header: Option<String>,
@ -6965,6 +6972,21 @@ impl Editor {
breakpoint: &Breakpoint,
cx: &mut Context<Self>,
) -> IconButton {
// Is it a breakpoint that shows up when hovering over gutter?
let (is_phantom, collides_with_existing) = self.gutter_breakpoint_indicator.0.map_or(
(false, false),
|PhantomBreakpointIndicator {
is_active,
display_row,
collides_with_existing_breakpoint,
}| {
(
is_active && display_row == row,
collides_with_existing_breakpoint,
)
},
);
let (color, icon) = {
let icon = match (&breakpoint.message.is_some(), breakpoint.is_disabled()) {
(false, false) => ui::IconName::DebugBreakpoint,
@ -6973,11 +6995,7 @@ impl Editor {
(true, true) => ui::IconName::DebugDisabledLogBreakpoint,
};
let color = if self
.gutter_breakpoint_indicator
.0
.is_some_and(|(point, is_visible)| is_visible && point.row() == row)
{
let color = if is_phantom {
Color::Hint
} else {
Color::Debugger
@ -6988,6 +7006,24 @@ impl Editor {
let breakpoint = Arc::from(breakpoint.clone());
let alt_as_text = gpui::Keystroke {
modifiers: Modifiers::secondary_key(),
..Default::default()
};
let primary_action_text = if breakpoint.is_disabled() {
"enable"
} else if is_phantom && !collides_with_existing {
"set"
} else {
"unset"
};
let mut primary_text = format!("Click to {primary_action_text}");
if collides_with_existing && !breakpoint.is_disabled() {
use std::fmt::Write;
write!(primary_text, ", {alt_as_text}-click to disable").ok();
}
let primary_text = SharedString::from(primary_text);
let focus_handle = self.focus_handle.clone();
IconButton::new(("breakpoint_indicator", row.0 as usize), icon)
.icon_size(IconSize::XSmall)
.size(ui::ButtonSize::None)
@ -7021,6 +7057,16 @@ impl Editor {
cx,
);
}))
.tooltip(move |window, cx| {
Tooltip::with_meta_in(
primary_text.clone(),
None,
"Right-click for more options",
&focus_handle,
window,
cx,
)
})
}
fn build_tasks_context(