From dc90aaa4cdb0a5fe3b926e13e7ef561916c2c267 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 9 Jan 2025 14:33:30 +0100 Subject: [PATCH] Introduce UI affordances to make enabling/disabling inline completions easier (#22894) Release Notes: - N/A --------- Co-authored-by: Thorsten --- crates/editor/src/editor.rs | 11 +++++ .../src/inline_completion_button.rs | 43 ++++++++++++------- crates/zed/src/zed/quick_action_bar.rs | 23 ++++++++++ 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 720f9d6bf3..27dbcf3c65 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1787,6 +1787,17 @@ impl Editor { self.refresh_inline_completion(false, true, cx); } + pub fn inline_completions_enabled(&self, cx: &AppContext) -> bool { + let cursor = self.selections.newest_anchor().head(); + if let Some((buffer, buffer_position)) = + self.buffer.read(cx).text_anchor_for_position(cursor, cx) + { + self.should_show_inline_completions(&buffer, buffer_position, cx) + } else { + false + } + } + fn should_show_inline_completions( &self, buffer: &Model, diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rs index 1f52cca3be..06a9885d2a 100644 --- a/crates/inline_completion_button/src/inline_completion_button.rs +++ b/crates/inline_completion_button/src/inline_completion_button.rs @@ -204,23 +204,17 @@ impl Render for InlineCompletionButton { return div(); } + let this = cx.view().clone(); div().child( - IconButton::new("zeta", IconName::ZedPredict) - .tooltip(|cx| { - Tooltip::with_meta( - "Zed Predict", - Some(&RateCompletions), - "Click to rate completions", - cx, - ) + PopoverMenu::new("zeta") + .menu(move |cx| { + Some(this.update(cx, |this, cx| this.build_zeta_context_menu(cx))) }) - .on_click(cx.listener(|this, _, cx| { - if let Some(workspace) = this.workspace.upgrade() { - workspace.update(cx, |workspace, cx| { - RateCompletionModal::toggle(workspace, cx) - }); - } - })), + .anchor(Corner::BottomRight) + .trigger( + IconButton::new("zeta", IconName::ZedPredict) + .tooltip(|cx| Tooltip::text("Zed Predict", cx)), + ), ) } } @@ -360,6 +354,25 @@ impl InlineCompletionButton { }) } + fn build_zeta_context_menu(&self, cx: &mut ViewContext) -> View { + let workspace = self.workspace.clone(); + ContextMenu::build(cx, |menu, cx| { + self.build_language_settings_menu(menu, cx) + .separator() + .entry( + "Rate Completions", + Some(RateCompletions.boxed_clone()), + move |cx| { + workspace + .update(cx, |workspace, cx| { + RateCompletionModal::toggle(workspace, cx) + }) + .ok(); + }, + ) + }) + } + pub fn update_enabled(&mut self, editor: View, cx: &mut ViewContext) { let editor = editor.read(cx); let snapshot = editor.buffer().read(cx).snapshot(cx); diff --git a/crates/zed/src/zed/quick_action_bar.rs b/crates/zed/src/zed/quick_action_bar.rs index ca48f024a8..48a0be9ef9 100644 --- a/crates/zed/src/zed/quick_action_bar.rs +++ b/crates/zed/src/zed/quick_action_bar.rs @@ -94,6 +94,7 @@ impl Render for QuickActionBar { git_blame_inline_enabled, show_git_blame_gutter, auto_signature_help_enabled, + inline_completions_enabled, ) = { let editor = editor.read(cx); let selection_menu_enabled = editor.selection_menu_enabled(cx); @@ -102,6 +103,7 @@ impl Render for QuickActionBar { let git_blame_inline_enabled = editor.git_blame_inline_enabled(); let show_git_blame_gutter = editor.show_git_blame_gutter(); let auto_signature_help_enabled = editor.auto_signature_help_enabled(cx); + let inline_completions_enabled = editor.inline_completions_enabled(cx); ( selection_menu_enabled, @@ -110,6 +112,7 @@ impl Render for QuickActionBar { git_blame_inline_enabled, show_git_blame_gutter, auto_signature_help_enabled, + inline_completions_enabled, ) }; @@ -283,6 +286,26 @@ impl Render for QuickActionBar { }, ); + menu = menu.toggleable_entry( + "Inline Completions", + inline_completions_enabled, + IconPosition::Start, + Some(editor::actions::ToggleInlineCompletions.boxed_clone()), + { + let editor = editor.clone(); + move |cx| { + editor + .update(cx, |editor, cx| { + editor.toggle_inline_completions( + &editor::actions::ToggleInlineCompletions, + cx, + ); + }) + .ok(); + } + }, + ); + menu = menu.separator(); menu = menu.toggleable_entry(