Detailed changes
@@ -108,7 +108,6 @@ pub fn init(cx: &mut AppContext) {
workspace.toggle_panel_focus::<AssistantPanel>(cx);
})
- .register_action(AssistantPanel::inline_assist)
.register_action(ContextEditor::quote_selection)
.register_action(ContextEditor::insert_selection)
.register_action(ContextEditor::copy_code)
@@ -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<dyn Fs>, client: Arc<Client>, 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::<zed_actions::InlineAssist>()];
+
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| {
@@ -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<Workspace>,
) {
let settings = AssistantSettings::get_global(cx);
@@ -19,6 +19,9 @@ pub fn init(cx: &mut AppContext) {
pub struct CommandPaletteFilter {
hidden_namespaces: HashSet<&'static str>,
hidden_action_types: HashSet<TypeId>,
+ /// Actions that have explicitly been shown. These should be shown even if
+ /// they are in a hidden namespace.
+ shown_action_types: HashSet<TypeId>,
}
#[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<Item = &'a TypeId>) {
for action_type in action_types {
+ self.shown_action_types.insert(*action_type);
self.hidden_action_types.remove(action_type);
}
}
@@ -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();