diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index da3e77f8dc..bfa82b7c40 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -108,7 +108,6 @@ pub fn init(cx: &mut AppContext) { workspace.toggle_panel_focus::(cx); }) - .register_action(AssistantPanel::inline_assist) .register_action(ContextEditor::quote_selection) .register_action(ContextEditor::insert_selection) .register_action(ContextEditor::copy_code) diff --git a/crates/assistant2/src/assistant.rs b/crates/assistant2/src/assistant.rs index 298360c6f3..93f3c3bace 100644 --- a/crates/assistant2/src/assistant.rs +++ b/crates/assistant2/src/assistant.rs @@ -15,9 +15,9 @@ mod thread_history; mod thread_store; mod ui; +use std::any::TypeId; use std::sync::Arc; -use assistant_settings::AssistantSettings; use client::Client; use command_palette_hooks::CommandPaletteFilter; use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt}; @@ -28,6 +28,8 @@ use settings::Settings as _; use util::ResultExt; pub use crate::assistant_panel::AssistantPanel; +use crate::assistant_settings::AssistantSettings; +pub use crate::inline_assistant::InlineAssistant; actions!( assistant2, @@ -38,7 +40,6 @@ actions!( ToggleModelSelector, OpenHistory, Chat, - ToggleInlineAssist, CycleNextInlineAssist, CyclePreviousInlineAssist ] @@ -80,6 +81,8 @@ pub fn init(fs: Arc, client: Arc, stdout_is_a_pty: bool, cx: &mu fn feature_gate_assistant2_actions(cx: &mut AppContext) { const ASSISTANT1_NAMESPACE: &str = "assistant"; + let inline_assist_actions = [TypeId::of::()]; + CommandPaletteFilter::update_global(cx, |filter, _cx| { filter.hide_namespace(NAMESPACE); }); @@ -89,6 +92,11 @@ fn feature_gate_assistant2_actions(cx: &mut AppContext) { CommandPaletteFilter::update_global(cx, |filter, _cx| { filter.show_namespace(NAMESPACE); filter.hide_namespace(ASSISTANT1_NAMESPACE); + + // We're hiding all of the `assistant: ` actions, but we want to + // keep the inline assist action around so we can use the same + // one in Assistant2. + filter.show_action_types(inline_assist_actions.iter()); }); } else { CommandPaletteFilter::update_global(cx, |filter, _cx| { diff --git a/crates/assistant2/src/inline_assistant.rs b/crates/assistant2/src/inline_assistant.rs index 9ecf166c51..d492dc961f 100644 --- a/crates/assistant2/src/inline_assistant.rs +++ b/crates/assistant2/src/inline_assistant.rs @@ -8,7 +8,7 @@ use crate::{ prompts::PromptBuilder, streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff}, terminal_inline_assistant::TerminalInlineAssistant, - CycleNextInlineAssist, CyclePreviousInlineAssist, ToggleInlineAssist, + CycleNextInlineAssist, CyclePreviousInlineAssist, }; use crate::{AssistantPanel, ToggleContextPicker}; use anyhow::{Context as _, Result}; @@ -75,9 +75,7 @@ pub fn init( cx: &mut AppContext, ) { cx.set_global(InlineAssistant::new(fs, prompt_builder, telemetry)); - cx.observe_new_views(|workspace: &mut Workspace, cx| { - workspace.register_action(InlineAssistant::toggle_inline_assist); - + cx.observe_new_views(|_workspace: &mut Workspace, cx| { let workspace = cx.view().clone(); InlineAssistant::update_global(cx, |inline_assistant, cx| { inline_assistant.register_workspace(&workspace, cx) @@ -204,9 +202,9 @@ impl InlineAssistant { } } - pub fn toggle_inline_assist( + pub fn inline_assist( workspace: &mut Workspace, - _action: &ToggleInlineAssist, + _action: &zed_actions::InlineAssist, cx: &mut ViewContext, ) { let settings = AssistantSettings::get_global(cx); diff --git a/crates/command_palette_hooks/src/command_palette_hooks.rs b/crates/command_palette_hooks/src/command_palette_hooks.rs index c1a61e287c..e113fe59ca 100644 --- a/crates/command_palette_hooks/src/command_palette_hooks.rs +++ b/crates/command_palette_hooks/src/command_palette_hooks.rs @@ -19,6 +19,9 @@ pub fn init(cx: &mut AppContext) { pub struct CommandPaletteFilter { hidden_namespaces: HashSet<&'static str>, hidden_action_types: HashSet, + /// Actions that have explicitly been shown. These should be shown even if + /// they are in a hidden namespace. + shown_action_types: HashSet, } #[derive(Deref, DerefMut, Default)] @@ -53,6 +56,11 @@ impl CommandPaletteFilter { let name = action.name(); let namespace = name.split("::").next().unwrap_or("malformed action name"); + // If this action has specifically been shown then it should be visible. + if self.shown_action_types.contains(&action.type_id()) { + return false; + } + self.hidden_namespaces.contains(namespace) || self.hidden_action_types.contains(&action.type_id()) } @@ -69,12 +77,16 @@ impl CommandPaletteFilter { /// Hides all actions with the given types. pub fn hide_action_types(&mut self, action_types: &[TypeId]) { - self.hidden_action_types.extend(action_types); + for action_type in action_types { + self.hidden_action_types.insert(*action_type); + self.shown_action_types.remove(action_type); + } } /// Shows all actions with the given types. pub fn show_action_types<'a>(&mut self, action_types: impl Iterator) { for action_type in action_types { + self.shown_action_types.insert(*action_type); self.hidden_action_types.remove(action_type); } } diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 4fc6ef944f..7372ffea11 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -314,12 +314,13 @@ pub fn initialize_workspace( workspace_handle.update(&mut cx, |workspace, cx| { if let Some(assistant_panel) = assistant_panel { workspace.add_panel(assistant_panel, cx); + workspace.register_action(assistant::AssistantPanel::inline_assist); } if let Some(assistant2_panel) = assistant2_panel { workspace.add_panel(assistant2_panel, cx); + workspace.register_action(assistant2::InlineAssistant::inline_assist); } - }) }) .detach();