assistant2: Show the popover keybinding when context is empty (#22452)

Danilo Leal and Agus Zubiaga created

This PR makes it so we always show the "Add Context {keybinding}" text
when there's no context pills attached. Also, while we haven't fully
implemented the mention system (triggered by typing `@`), we removed the
instruction on the message editor placeholder. Once that's fully in
place, we should return with it!

<img width="800" alt="Screenshot 2024-12-27 at 1 35 56 PM"
src="https://github.com/user-attachments/assets/201cf784-e7ac-420a-adf2-51b6e075c2b6"
/>

Release Notes:

- N/A

---------

Co-authored-by: Agus Zubiaga <hi@aguz.me>

Change summary

crates/assistant2/src/context_strip.rs  | 54 ++++++++++++++++++++-------
crates/assistant2/src/message_editor.rs |  2 
2 files changed, 41 insertions(+), 15 deletions(-)

Detailed changes

crates/assistant2/src/context_strip.rs 🔗

@@ -9,6 +9,7 @@ use crate::context_store::ContextStore;
 use crate::thread_store::ThreadStore;
 use crate::ui::ContextPill;
 use crate::ToggleContextPicker;
+use settings::Settings;
 
 pub struct ContextStrip {
     context_store: Model<ContextStore>,
@@ -45,7 +46,7 @@ impl ContextStrip {
 
 impl Render for ContextStrip {
     fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
-        let context = self.context_store.read(cx).context();
+        let context = self.context_store.read(cx).context().clone();
         let context_picker = self.context_picker.clone();
         let focus_handle = self.focus_handle.clone();
 
@@ -76,6 +77,29 @@ impl Render for ContextStrip {
                     })
                     .with_handle(self.context_picker_menu_handle.clone()),
             )
+            .when(context.is_empty(), {
+                |parent| {
+                    parent.child(
+                        h_flex()
+                            .id("no-content-info")
+                            .ml_1p5()
+                            .gap_2()
+                            .font(theme::ThemeSettings::get_global(cx).buffer_font.clone())
+                            .text_size(TextSize::Small.rems(cx))
+                            .text_color(cx.theme().colors().text_muted)
+                            .child("Add Context")
+                            .children(
+                                ui::KeyBinding::for_action_in(
+                                    &ToggleContextPicker,
+                                    &self.focus_handle,
+                                    cx,
+                                )
+                                .map(|binding| binding.into_any_element()),
+                            )
+                            .opacity(0.5),
+                    )
+                }
+            })
             .children(context.iter().map(|context| {
                 ContextPill::new(context.clone()).on_remove({
                     let context = context.clone();
@@ -88,19 +112,21 @@ impl Render for ContextStrip {
                     }))
                 })
             }))
-            .when(!context.is_empty(), |parent| {
-                parent.child(
-                    IconButton::new("remove-all-context", IconName::Eraser)
-                        .icon_size(IconSize::Small)
-                        .tooltip(move |cx| Tooltip::text("Remove All Context", cx))
-                        .on_click({
-                            let context_store = self.context_store.clone();
-                            cx.listener(move |_this, _event, cx| {
-                                context_store.update(cx, |this, _cx| this.clear());
-                                cx.notify();
-                            })
-                        }),
-                )
+            .when(!context.is_empty(), {
+                move |parent| {
+                    parent.child(
+                        IconButton::new("remove-all-context", IconName::Eraser)
+                            .icon_size(IconSize::Small)
+                            .tooltip(move |cx| Tooltip::text("Remove All Context", cx))
+                            .on_click({
+                                let context_store = self.context_store.clone();
+                                cx.listener(move |_this, _event, cx| {
+                                    context_store.update(cx, |this, _cx| this.clear());
+                                    cx.notify();
+                                })
+                            }),
+                    )
+                }
             })
     }
 }

crates/assistant2/src/message_editor.rs 🔗

@@ -54,7 +54,7 @@ impl MessageEditor {
 
         let editor = cx.new_view(|cx| {
             let mut editor = Editor::auto_height(10, cx);
-            editor.set_placeholder_text("Ask anything, @ to add context", cx);
+            editor.set_placeholder_text("Ask anything…", cx);
             editor.set_show_indent_guides(false, cx);
 
             editor