Consolidate Assistant panels in assistant2 feature flag (#23442)

This PR consolidates the two Assistant panels into one for users in the
`assistant2` feature flag.

Now that the Assistant1 prompt editor is accessible through the
Assistant2 panel, we no longer have a need to show both panels.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-01-21 21:56:42 -05:00 committed by GitHub
parent 7516b8c8b7
commit c887bf8e54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 89 additions and 51 deletions

View file

@ -31,7 +31,6 @@ use crate::slash_command_settings::SlashCommandSettings;
actions!( actions!(
assistant, assistant,
[ [
ToggleFocus,
InsertActivePrompt, InsertActivePrompt,
DeployHistory, DeployHistory,
DeployPromptLibrary, DeployPromptLibrary,

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
terminal_inline_assistant::TerminalInlineAssistant, DeployHistory, DeployPromptLibrary, terminal_inline_assistant::TerminalInlineAssistant, DeployHistory, DeployPromptLibrary,
InlineAssistant, NewContext, ToggleFocus, InlineAssistant, NewContext,
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use assistant_context_editor::{ use assistant_context_editor::{
@ -42,7 +42,7 @@ use workspace::{
item::Item, item::Item,
pane, DraggedSelection, Pane, ShowConfiguration, ToggleZoom, Workspace, pane, DraggedSelection, Pane, ShowConfiguration, ToggleZoom, Workspace,
}; };
use zed_actions::InlineAssist; use zed_actions::assistant::{InlineAssist, ToggleFocus};
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
<dyn AssistantPanelDelegate>::set_global(Arc::new(ConcreteAssistantPanelDelegate), cx); <dyn AssistantPanelDelegate>::set_global(Arc::new(ConcreteAssistantPanelDelegate), cx);
@ -51,14 +51,6 @@ pub fn init(cx: &mut AppContext) {
cx.observe_new_views( cx.observe_new_views(
|workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| { |workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| {
workspace workspace
.register_action(|workspace, _: &ToggleFocus, cx| {
let settings = AssistantSettings::get_global(cx);
if !settings.enabled {
return;
}
workspace.toggle_panel_focus::<AssistantPanel>(cx);
})
.register_action(ContextEditor::quote_selection) .register_action(ContextEditor::quote_selection)
.register_action(ContextEditor::insert_selection) .register_action(ContextEditor::insert_selection)
.register_action(ContextEditor::copy_code) .register_action(ContextEditor::copy_code)
@ -341,6 +333,19 @@ impl AssistantPanel {
this this
} }
pub fn toggle_focus(
workspace: &mut Workspace,
_: &ToggleFocus,
cx: &mut ViewContext<Workspace>,
) {
let settings = AssistantSettings::get_global(cx);
if !settings.enabled {
return;
}
workspace.toggle_panel_focus::<Self>(cx);
}
fn watch_client_status(client: Arc<Client>, cx: &mut ViewContext<Self>) -> Task<()> { fn watch_client_status(client: Arc<Client>, cx: &mut ViewContext<Self>) -> Task<()> {
let mut status_rx = client.status(); let mut status_rx = client.status();

View file

@ -1728,7 +1728,7 @@ impl PromptEditor {
} }
fn placeholder_text(codegen: &Codegen, cx: &WindowContext) -> String { fn placeholder_text(codegen: &Codegen, cx: &WindowContext) -> String {
let context_keybinding = text_for_action(&crate::ToggleFocus, cx) let context_keybinding = text_for_action(&zed_actions::assistant::ToggleFocus, cx)
.map(|keybinding| format!("{keybinding} for context")) .map(|keybinding| format!("{keybinding} for context"))
.unwrap_or_default(); .unwrap_or_default();

View file

@ -740,7 +740,7 @@ impl PromptEditor {
} }
fn placeholder_text(cx: &WindowContext) -> String { fn placeholder_text(cx: &WindowContext) -> String {
let context_keybinding = text_for_action(&crate::ToggleFocus, cx) let context_keybinding = text_for_action(&zed_actions::assistant::ToggleFocus, cx)
.map(|keybinding| format!("{keybinding} for context")) .map(|keybinding| format!("{keybinding} for context"))
.unwrap_or_default(); .unwrap_or_default();

View file

@ -34,7 +34,6 @@ pub use crate::inline_assistant::InlineAssistant;
actions!( actions!(
assistant2, assistant2,
[ [
ToggleFocus,
NewThread, NewThread,
NewPromptEditor, NewPromptEditor,
ToggleContextPicker, ToggleContextPicker,

View file

@ -24,22 +24,20 @@ use ui::{prelude::*, ContextMenu, KeyBinding, PopoverMenu, PopoverMenuHandle, Ta
use util::ResultExt as _; use util::ResultExt as _;
use workspace::dock::{DockPosition, Panel, PanelEvent}; use workspace::dock::{DockPosition, Panel, PanelEvent};
use workspace::Workspace; use workspace::Workspace;
use zed_actions::assistant::ToggleFocus;
use crate::active_thread::ActiveThread; use crate::active_thread::ActiveThread;
use crate::message_editor::MessageEditor; use crate::message_editor::MessageEditor;
use crate::thread::{Thread, ThreadError, ThreadId}; use crate::thread::{Thread, ThreadError, ThreadId};
use crate::thread_history::{PastThread, ThreadHistory}; use crate::thread_history::{PastThread, ThreadHistory};
use crate::thread_store::ThreadStore; use crate::thread_store::ThreadStore;
use crate::{NewPromptEditor, NewThread, OpenHistory, OpenPromptEditorHistory, ToggleFocus}; use crate::{NewPromptEditor, NewThread, OpenHistory, OpenPromptEditorHistory};
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
<dyn AssistantPanelDelegate>::set_global(Arc::new(ConcreteAssistantPanelDelegate), cx); <dyn AssistantPanelDelegate>::set_global(Arc::new(ConcreteAssistantPanelDelegate), cx);
cx.observe_new_views( cx.observe_new_views(
|workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| { |workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| {
workspace workspace
.register_action(|workspace, _: &ToggleFocus, cx| {
workspace.toggle_panel_focus::<AssistantPanel>(cx);
})
.register_action(|workspace, _: &NewThread, cx| { .register_action(|workspace, _: &NewThread, cx| {
if let Some(panel) = workspace.panel::<AssistantPanel>(cx) { if let Some(panel) = workspace.panel::<AssistantPanel>(cx) {
panel.update(cx, |panel, cx| panel.new_thread(cx)); panel.update(cx, |panel, cx| panel.new_thread(cx));
@ -189,6 +187,19 @@ impl AssistantPanel {
} }
} }
pub fn toggle_focus(
workspace: &mut Workspace,
_: &ToggleFocus,
cx: &mut ViewContext<Workspace>,
) {
let settings = AssistantSettings::get_global(cx);
if !settings.enabled {
return;
}
workspace.toggle_panel_focus::<Self>(cx);
}
pub(crate) fn local_timezone(&self) -> UtcOffset { pub(crate) fn local_timezone(&self) -> UtcOffset {
self.local_timezone self.local_timezone
} }
@ -438,7 +449,7 @@ impl Panel for AssistantPanel {
return None; return None;
} }
Some(IconName::ZedAssistant2) Some(IconName::ZedAssistant)
} }
fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> {

View file

@ -204,7 +204,7 @@ impl InlineAssistant {
pub fn inline_assist( pub fn inline_assist(
workspace: &mut Workspace, workspace: &mut Workspace,
_action: &zed_actions::InlineAssist, _action: &zed_actions::assistant::InlineAssist,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) { ) {
let settings = AssistantSettings::get_global(cx); let settings = AssistantSettings::get_global(cx);

View file

@ -270,9 +270,10 @@ impl<T: 'static> PromptEditor<T> {
PromptEditorMode::Terminal { .. } => "Generate", PromptEditorMode::Terminal { .. } => "Generate",
}; };
let assistant_panel_keybinding = ui::text_for_action(&crate::ToggleFocus, cx) let assistant_panel_keybinding =
.map(|keybinding| format!("{keybinding} to chat ― ")) ui::text_for_action(&zed_actions::assistant::ToggleFocus, cx)
.unwrap_or_default(); .map(|keybinding| format!("{keybinding} to chat ― "))
.unwrap_or_default();
format!("{action}… ({assistant_panel_keybinding}↓↑ for history)") format!("{action}… ({assistant_panel_keybinding}↓↑ for history)")
} }

View file

@ -27,7 +27,7 @@ use ui::{
}; };
use util::{ResultExt, TryFutureExt}; use util::{ResultExt, TryFutureExt};
use workspace::Workspace; use workspace::Workspace;
use zed_actions::InlineAssist; use zed_actions::assistant::InlineAssist;
pub use crate::prompt_store::*; pub use crate::prompt_store::*;
pub use crate::prompts::*; pub use crate::prompts::*;

View file

@ -42,7 +42,7 @@ use workspace::{
}; };
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use zed_actions::InlineAssist; use zed_actions::assistant::InlineAssist;
const TERMINAL_PANEL_KEY: &str = "TerminalPanel"; const TERMINAL_PANEL_KEY: &str = "TerminalPanel";

View file

@ -56,7 +56,7 @@ use anyhow::Context;
use serde::Deserialize; use serde::Deserialize;
use settings::{Settings, SettingsStore}; use settings::{Settings, SettingsStore};
use smol::Timer; use smol::Timer;
use zed_actions::InlineAssist; use zed_actions::assistant::InlineAssist;
use std::{ use std::{
cmp, cmp,

View file

@ -362,11 +362,6 @@ fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Wo
workspace_handle.clone(), workspace_handle.clone(),
cx.clone(), cx.clone(),
); );
let assistant_panel = assistant::AssistantPanel::load(
workspace_handle.clone(),
prompt_builder.clone(),
cx.clone(),
);
let ( let (
project_panel, project_panel,
@ -375,7 +370,6 @@ fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Wo
channels_panel, channels_panel,
chat_panel, chat_panel,
notification_panel, notification_panel,
assistant_panel,
) = futures::try_join!( ) = futures::try_join!(
project_panel, project_panel,
outline_panel, outline_panel,
@ -383,7 +377,6 @@ fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Wo
channels_panel, channels_panel,
chat_panel, chat_panel,
notification_panel, notification_panel,
assistant_panel,
)?; )?;
workspace_handle.update(&mut cx, |workspace, cx| { workspace_handle.update(&mut cx, |workspace, cx| {
@ -393,7 +386,6 @@ fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Wo
workspace.add_panel(channels_panel, cx); workspace.add_panel(channels_panel, cx);
workspace.add_panel(chat_panel, cx); workspace.add_panel(chat_panel, cx);
workspace.add_panel(notification_panel, cx); workspace.add_panel(notification_panel, cx);
workspace.add_panel(assistant_panel, cx)
})?; })?;
let git_ui_enabled = { let git_ui_enabled = {
@ -429,27 +421,50 @@ fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Wo
_ = timeout => false, _ = timeout => false,
} }
}; };
let assistant2_panel = if is_assistant2_enabled {
Some( let (assistant_panel, assistant2_panel) = if is_assistant2_enabled {
assistant2::AssistantPanel::load( let assistant2_panel = assistant2::AssistantPanel::load(
workspace_handle.clone(), workspace_handle.clone(),
prompt_builder, prompt_builder,
cx.clone(), cx.clone(),
)
.await?,
) )
.await?;
(None, Some(assistant2_panel))
} else { } else {
None let assistant_panel = assistant::AssistantPanel::load(
workspace_handle.clone(),
prompt_builder.clone(),
cx.clone(),
)
.await?;
(Some(assistant_panel), None)
}; };
workspace_handle.update(&mut cx, |workspace, cx| { workspace_handle.update(&mut cx, |workspace, cx| {
if let Some(assistant2_panel) = assistant2_panel { if let Some(assistant2_panel) = assistant2_panel {
workspace.add_panel(assistant2_panel, cx); workspace.add_panel(assistant2_panel, cx);
} }
if let Some(assistant_panel) = assistant_panel {
workspace.add_panel(assistant_panel, cx);
}
// Register the actions that are shared between `assistant` and `assistant2`.
//
// We need to do this here instead of within the individual `init`
// functions so that we only register the actions once.
//
// Once we ship `assistant2` we can push this back down into `assistant2::assistant_panel::init`.
if is_assistant2_enabled { if is_assistant2_enabled {
workspace.register_action(assistant2::InlineAssistant::inline_assist); workspace
.register_action(assistant2::AssistantPanel::toggle_focus)
.register_action(assistant2::InlineAssistant::inline_assist);
} else { } else {
workspace.register_action(assistant::AssistantPanel::inline_assist); workspace
.register_action(assistant::AssistantPanel::toggle_focus)
.register_action(assistant::AssistantPanel::inline_assist);
} }
})?; })?;

View file

@ -23,7 +23,7 @@ use vim_mode_setting::VimModeSetting;
use workspace::{ use workspace::{
item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace, item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
}; };
use zed_actions::{outline::ToggleOutline, InlineAssist}; use zed_actions::{assistant::InlineAssist, outline::ToggleOutline};
pub struct QuickActionBar { pub struct QuickActionBar {
_inlay_hints_enabled_subscription: Option<Subscription>, _inlay_hints_enabled_subscription: Option<Subscription>,

View file

@ -77,12 +77,20 @@ pub mod theme_selector {
impl_actions!(theme_selector, [Toggle]); impl_actions!(theme_selector, [Toggle]);
} }
#[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)] pub mod assistant {
pub struct InlineAssist { use gpui::{actions, impl_actions};
pub prompt: Option<String>, use schemars::JsonSchema;
} use serde::Deserialize;
impl_actions!(assistant, [InlineAssist]); actions!(assistant, [ToggleFocus]);
#[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
pub struct InlineAssist {
pub prompt: Option<String>,
}
impl_actions!(assistant, [InlineAssist]);
}
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)] #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct OpenRecent { pub struct OpenRecent {