mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Use the same InlineAssist
action between both assistant
and assistant2
(#22126)
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
This PR makes it so `assistant` and `assistant2` both use the same action for inline assist (`zed_actions::InlineAssist`). This makes it so the keybindings to deploy the inline assist seamlessly swap based on the feature flag without needing to rebind them. One minor caveat: if you're using `assistant2` the action name in the command palette will be `assistant: inline assist`. Release Notes: - N/A
This commit is contained in:
parent
80431e5518
commit
3052fc2565
5 changed files with 29 additions and 11 deletions
|
@ -108,7 +108,6 @@ pub fn init(cx: &mut AppContext) {
|
||||||
|
|
||||||
workspace.toggle_panel_focus::<AssistantPanel>(cx);
|
workspace.toggle_panel_focus::<AssistantPanel>(cx);
|
||||||
})
|
})
|
||||||
.register_action(AssistantPanel::inline_assist)
|
|
||||||
.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)
|
||||||
|
|
|
@ -15,9 +15,9 @@ mod thread_history;
|
||||||
mod thread_store;
|
mod thread_store;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
use std::any::TypeId;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use assistant_settings::AssistantSettings;
|
|
||||||
use client::Client;
|
use client::Client;
|
||||||
use command_palette_hooks::CommandPaletteFilter;
|
use command_palette_hooks::CommandPaletteFilter;
|
||||||
use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
|
use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
|
||||||
|
@ -28,6 +28,8 @@ use settings::Settings as _;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
pub use crate::assistant_panel::AssistantPanel;
|
pub use crate::assistant_panel::AssistantPanel;
|
||||||
|
use crate::assistant_settings::AssistantSettings;
|
||||||
|
pub use crate::inline_assistant::InlineAssistant;
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
assistant2,
|
assistant2,
|
||||||
|
@ -38,7 +40,6 @@ actions!(
|
||||||
ToggleModelSelector,
|
ToggleModelSelector,
|
||||||
OpenHistory,
|
OpenHistory,
|
||||||
Chat,
|
Chat,
|
||||||
ToggleInlineAssist,
|
|
||||||
CycleNextInlineAssist,
|
CycleNextInlineAssist,
|
||||||
CyclePreviousInlineAssist
|
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) {
|
fn feature_gate_assistant2_actions(cx: &mut AppContext) {
|
||||||
const ASSISTANT1_NAMESPACE: &str = "assistant";
|
const ASSISTANT1_NAMESPACE: &str = "assistant";
|
||||||
|
|
||||||
|
let inline_assist_actions = [TypeId::of::<zed_actions::InlineAssist>()];
|
||||||
|
|
||||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||||
filter.hide_namespace(NAMESPACE);
|
filter.hide_namespace(NAMESPACE);
|
||||||
});
|
});
|
||||||
|
@ -89,6 +92,11 @@ fn feature_gate_assistant2_actions(cx: &mut AppContext) {
|
||||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||||
filter.show_namespace(NAMESPACE);
|
filter.show_namespace(NAMESPACE);
|
||||||
filter.hide_namespace(ASSISTANT1_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 {
|
} else {
|
||||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
prompts::PromptBuilder,
|
prompts::PromptBuilder,
|
||||||
streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff},
|
streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff},
|
||||||
terminal_inline_assistant::TerminalInlineAssistant,
|
terminal_inline_assistant::TerminalInlineAssistant,
|
||||||
CycleNextInlineAssist, CyclePreviousInlineAssist, ToggleInlineAssist,
|
CycleNextInlineAssist, CyclePreviousInlineAssist,
|
||||||
};
|
};
|
||||||
use crate::{AssistantPanel, ToggleContextPicker};
|
use crate::{AssistantPanel, ToggleContextPicker};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
|
@ -75,9 +75,7 @@ pub fn init(
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) {
|
) {
|
||||||
cx.set_global(InlineAssistant::new(fs, prompt_builder, telemetry));
|
cx.set_global(InlineAssistant::new(fs, prompt_builder, telemetry));
|
||||||
cx.observe_new_views(|workspace: &mut Workspace, cx| {
|
cx.observe_new_views(|_workspace: &mut Workspace, cx| {
|
||||||
workspace.register_action(InlineAssistant::toggle_inline_assist);
|
|
||||||
|
|
||||||
let workspace = cx.view().clone();
|
let workspace = cx.view().clone();
|
||||||
InlineAssistant::update_global(cx, |inline_assistant, cx| {
|
InlineAssistant::update_global(cx, |inline_assistant, cx| {
|
||||||
inline_assistant.register_workspace(&workspace, 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,
|
workspace: &mut Workspace,
|
||||||
_action: &ToggleInlineAssist,
|
_action: &zed_actions::InlineAssist,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
let settings = AssistantSettings::get_global(cx);
|
||||||
|
|
|
@ -19,6 +19,9 @@ pub fn init(cx: &mut AppContext) {
|
||||||
pub struct CommandPaletteFilter {
|
pub struct CommandPaletteFilter {
|
||||||
hidden_namespaces: HashSet<&'static str>,
|
hidden_namespaces: HashSet<&'static str>,
|
||||||
hidden_action_types: HashSet<TypeId>,
|
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)]
|
#[derive(Deref, DerefMut, Default)]
|
||||||
|
@ -53,6 +56,11 @@ impl CommandPaletteFilter {
|
||||||
let name = action.name();
|
let name = action.name();
|
||||||
let namespace = name.split("::").next().unwrap_or("malformed 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_namespaces.contains(namespace)
|
||||||
|| self.hidden_action_types.contains(&action.type_id())
|
|| self.hidden_action_types.contains(&action.type_id())
|
||||||
}
|
}
|
||||||
|
@ -69,12 +77,16 @@ impl CommandPaletteFilter {
|
||||||
|
|
||||||
/// Hides all actions with the given types.
|
/// Hides all actions with the given types.
|
||||||
pub fn hide_action_types(&mut self, action_types: &[TypeId]) {
|
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.
|
/// Shows all actions with the given types.
|
||||||
pub fn show_action_types<'a>(&mut self, action_types: impl Iterator<Item = &'a TypeId>) {
|
pub fn show_action_types<'a>(&mut self, action_types: impl Iterator<Item = &'a TypeId>) {
|
||||||
for action_type in action_types {
|
for action_type in action_types {
|
||||||
|
self.shown_action_types.insert(*action_type);
|
||||||
self.hidden_action_types.remove(action_type);
|
self.hidden_action_types.remove(action_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,12 +314,13 @@ pub fn initialize_workspace(
|
||||||
workspace_handle.update(&mut cx, |workspace, cx| {
|
workspace_handle.update(&mut cx, |workspace, cx| {
|
||||||
if let Some(assistant_panel) = assistant_panel {
|
if let Some(assistant_panel) = assistant_panel {
|
||||||
workspace.add_panel(assistant_panel, cx);
|
workspace.add_panel(assistant_panel, cx);
|
||||||
|
workspace.register_action(assistant::AssistantPanel::inline_assist);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
workspace.register_action(assistant2::InlineAssistant::inline_assist);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
Loading…
Reference in a new issue