diff --git a/crates/assistant/src/inline_assistant.rs b/crates/assistant/src/inline_assistant.rs index 1134747d55..9af8193605 100644 --- a/crates/assistant/src/inline_assistant.rs +++ b/crates/assistant/src/inline_assistant.rs @@ -54,7 +54,7 @@ use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase}; use terminal_view::terminal_panel::TerminalPanel; use text::{OffsetRangeExt, ToPoint as _}; use theme::ThemeSettings; -use ui::{prelude::*, CheckboxWithLabel, IconButtonShape, Popover, Tooltip}; +use ui::{prelude::*, text_for_action, CheckboxWithLabel, IconButtonShape, Popover, Tooltip}; use util::{RangeExt, ResultExt}; use workspace::{notifications::NotificationId, ItemHandle, Toast, Workspace}; @@ -1596,7 +1596,7 @@ impl PromptEditor { // always show the cursor (even when it isn't focused) because // typing in one will make what you typed appear in all of them. editor.set_show_cursor_when_unfocused(true, cx); - editor.set_placeholder_text("Add a prompt…", cx); + editor.set_placeholder_text(Self::placeholder_text(codegen.read(cx), cx), cx); editor }); @@ -1653,6 +1653,7 @@ impl PromptEditor { self.editor = cx.new_view(|cx| { let mut editor = Editor::auto_height(Self::MAX_LINES as usize, cx); editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx); + editor.set_placeholder_text(Self::placeholder_text(self.codegen.read(cx), cx), cx); editor.set_placeholder_text("Add a prompt…", cx); editor.set_text(prompt, cx); if focus { @@ -1663,6 +1664,20 @@ impl PromptEditor { self.subscribe_to_editor(cx); } + fn placeholder_text(codegen: &Codegen, cx: &WindowContext) -> String { + let context_keybinding = text_for_action(&crate::ToggleFocus, cx) + .map(|keybinding| format!(" • {keybinding} for context")) + .unwrap_or_default(); + + let action = if codegen.is_insertion { + "Generate" + } else { + "Transform" + }; + + format!("{action}…{context_keybinding} • ↓↑ for history") + } + fn prompt(&self, cx: &AppContext) -> String { self.editor.read(cx).text(cx) } @@ -2260,6 +2275,7 @@ pub struct Codegen { initial_transaction_id: Option, telemetry: Option>, builder: Arc, + is_insertion: bool, } impl Codegen { @@ -2282,6 +2298,7 @@ impl Codegen { ) }); let mut this = Self { + is_insertion: range.to_offset(&buffer.read(cx).snapshot(cx)).is_empty(), alternatives: vec![codegen], active_alternative: 0, seen_alternatives: HashSet::default(), @@ -2683,7 +2700,7 @@ impl CodegenAlternative { let prompt = self .builder - .generate_content_prompt(user_prompt, language_name, buffer, range) + .generate_inline_transformation_prompt(user_prompt, language_name, buffer, range) .map_err(|e| anyhow::anyhow!("Failed to generate content prompt: {}", e))?; let mut messages = Vec::new(); diff --git a/crates/assistant/src/prompts.rs b/crates/assistant/src/prompts.rs index 132b3df68f..2d0829086c 100644 --- a/crates/assistant/src/prompts.rs +++ b/crates/assistant/src/prompts.rs @@ -204,7 +204,7 @@ impl PromptBuilder { Ok(()) } - pub fn generate_content_prompt( + pub fn generate_inline_transformation_prompt( &self, user_prompt: String, language_name: Option<&LanguageName>, diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index 135599b914..cd45a11d9f 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -196,7 +196,7 @@ impl KeyIcon { } /// Returns a textual representation of the key binding for the given [`Action`]. -pub fn text_for_action(action: &dyn Action, cx: &mut WindowContext) -> Option { +pub fn text_for_action(action: &dyn Action, cx: &WindowContext) -> Option { let key_binding = cx.bindings_for_action(action).last().cloned()?; Some(text_for_key_binding(key_binding, PlatformStyle::platform())) }