editor: Inline Code Actions Indicator (#31432)

Follow up to https://github.com/zed-industries/zed/pull/30140 and
https://github.com/zed-industries/zed/pull/31236

This PR introduces an inline code action indicator that shows up at the
start of a buffer line when there's enough space. If space is tight, it
adjusts to lines above or below instead. It also adjusts when cursor is
near indicator.

The indicator won't appear if there's no space within about 8 rows in
either direction, and it also stays hidden for folded ranges. It also
won't show up in case there is not space in multi buffer excerpt. These
cases account for very little because practically all languages do have
indents.


https://github.com/user-attachments/assets/1363ee8a-3178-4665-89a7-c86c733f2885

This PR also sets the existing `toolbar.code_actions` setting to `false`
in favor of this.

Release Notes:

- Added code action indicator which shows up inline at the start of the
row. This can be disabled by setting `inline_code_actions` to `false`.
This commit is contained in:
Smit Barmase 2025-05-26 19:41:19 +05:30 committed by GitHub
parent 5a0a8ce30a
commit 625bf09830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 259 additions and 12 deletions

View file

@ -1072,6 +1072,7 @@ pub struct EditorSnapshot {
show_gutter: bool,
show_line_numbers: Option<bool>,
show_git_diff_gutter: Option<bool>,
show_code_actions: Option<bool>,
show_runnables: Option<bool>,
show_breakpoints: Option<bool>,
git_blame_gutter_max_author_length: Option<usize>,
@ -2307,6 +2308,7 @@ impl Editor {
show_gutter: self.show_gutter,
show_line_numbers: self.show_line_numbers,
show_git_diff_gutter: self.show_git_diff_gutter,
show_code_actions: self.show_code_actions,
show_runnables: self.show_runnables,
show_breakpoints: self.show_breakpoints,
git_blame_gutter_max_author_length,
@ -5755,7 +5757,7 @@ impl Editor {
self.refresh_code_actions(window, cx);
}
pub fn code_actions_enabled(&self, cx: &App) -> bool {
pub fn code_actions_enabled_for_toolbar(&self, cx: &App) -> bool {
!self.code_action_providers.is_empty()
&& EditorSettings::get_global(cx).toolbar.code_actions
}
@ -5766,6 +5768,53 @@ impl Editor {
.is_some_and(|(_, actions)| !actions.is_empty())
}
fn render_inline_code_actions(
&self,
icon_size: ui::IconSize,
display_row: DisplayRow,
is_active: bool,
cx: &mut Context<Self>,
) -> AnyElement {
let show_tooltip = !self.context_menu_visible();
IconButton::new("inline_code_actions", ui::IconName::BoltFilled)
.icon_size(icon_size)
.shape(ui::IconButtonShape::Square)
.style(ButtonStyle::Transparent)
.icon_color(ui::Color::Hidden)
.toggle_state(is_active)
.when(show_tooltip, |this| {
this.tooltip({
let focus_handle = self.focus_handle.clone();
move |window, cx| {
Tooltip::for_action_in(
"Toggle Code Actions",
&ToggleCodeActions {
deployed_from: None,
quick_launch: false,
},
&focus_handle,
window,
cx,
)
}
})
})
.on_click(cx.listener(move |editor, _: &ClickEvent, window, cx| {
window.focus(&editor.focus_handle(cx));
editor.toggle_code_actions(
&crate::actions::ToggleCodeActions {
deployed_from: Some(crate::actions::CodeActionSource::Indicator(
display_row,
)),
quick_launch: false,
},
window,
cx,
);
}))
.into_any_element()
}
pub fn context_menu(&self) -> &RefCell<Option<CodeContextMenu>> {
&self.context_menu
}