From 1e1997c97ba7d4e684d8aae1dd195255875a466e Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 21 Jan 2025 23:57:51 -0500 Subject: [PATCH] Wire up `AssistantPanelDelegate` based on `assistant2` feature flag (#23444) This PR adjusts how the `AssistantPanelDelegate` global is set to be based on the state of the feature flag. This should prevent `assistant` and `assistant2` from potentially clobbering each other. Release Notes: - N/A --- Cargo.lock | 1 + crates/assistant/src/assistant_panel.rs | 4 +--- crates/assistant2/src/assistant.rs | 2 +- crates/assistant2/src/assistant_panel.rs | 3 +-- crates/zed/Cargo.toml | 1 + crates/zed/src/zed.rs | 11 +++++++++++ 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8ad6cb921180177738ffe2dfc20131f23a61ff0..2544a53fc0c14022c32ebd32e11401f2d552ba93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16275,6 +16275,7 @@ dependencies = [ "assets", "assistant", "assistant2", + "assistant_context_editor", "assistant_settings", "assistant_tools", "async-watch", diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 81c8272d341e570ee1bfee58a72140134190e3d2..ccafd3eca9a39daab1f36ecc2fbe442ec6fc5235 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -45,8 +45,6 @@ use workspace::{ use zed_actions::assistant::{InlineAssist, ToggleFocus}; pub fn init(cx: &mut AppContext) { - ::set_global(Arc::new(ConcreteAssistantPanelDelegate), cx); - workspace::FollowableViewRegistry::register::(cx); cx.observe_new_views( |workspace: &mut Workspace, _cx: &mut ViewContext| { @@ -1299,7 +1297,7 @@ impl prompt_library::InlineAssistDelegate for PromptLibraryInlineAssist { } } -struct ConcreteAssistantPanelDelegate; +pub struct ConcreteAssistantPanelDelegate; impl AssistantPanelDelegate for ConcreteAssistantPanelDelegate { fn active_context_editor( diff --git a/crates/assistant2/src/assistant.rs b/crates/assistant2/src/assistant.rs index 0f8ab2c3057e69a31fa6a9fcdf6ec88672a001cb..4d1385abddc2a844f0866a17fc8320629c597755 100644 --- a/crates/assistant2/src/assistant.rs +++ b/crates/assistant2/src/assistant.rs @@ -28,7 +28,7 @@ use prompt_library::{PromptBuilder, PromptLoadingParams}; use settings::Settings as _; use util::ResultExt; -pub use crate::assistant_panel::AssistantPanel; +pub use crate::assistant_panel::{AssistantPanel, ConcreteAssistantPanelDelegate}; pub use crate::inline_assistant::InlineAssistant; actions!( diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rs index c90056bd0868712d1b203faf0a0b1f08401838c8..1d92243a89b5dd3c11ff59009de7ab5d172caf5b 100644 --- a/crates/assistant2/src/assistant_panel.rs +++ b/crates/assistant2/src/assistant_panel.rs @@ -34,7 +34,6 @@ use crate::thread_store::ThreadStore; use crate::{NewPromptEditor, NewThread, OpenHistory, OpenPromptEditorHistory}; pub fn init(cx: &mut AppContext) { - ::set_global(Arc::new(ConcreteAssistantPanelDelegate), cx); cx.observe_new_views( |workspace: &mut Workspace, _cx: &mut ViewContext| { workspace @@ -811,7 +810,7 @@ impl Render for AssistantPanel { } } -struct ConcreteAssistantPanelDelegate; +pub struct ConcreteAssistantPanelDelegate; impl AssistantPanelDelegate for ConcreteAssistantPanelDelegate { fn active_context_editor( diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index d493e1e700fa74a50209b9f5364fddc4cc0371ea..fff53ca0e79b1d2e0478eff6c0c77f6205675534 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -21,6 +21,7 @@ anyhow.workspace = true assets.workspace = true assistant.workspace = true assistant2.workspace = true +assistant_context_editor.workspace = true assistant_settings.workspace = true assistant_tools.workspace = true async-watch.workspace = true diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 687ebeef4f577ef98c9945dddc8af87d09a052aa..a6714625af2ad7e8f281481f20dee1c7da07893e 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -12,6 +12,7 @@ pub(crate) mod windows_only_instance; use anyhow::Context as _; pub use app_menus::*; use assets::Assets; +use assistant_context_editor::AssistantPanelDelegate; use breadcrumbs::Breadcrumbs; use client::{zed_urls, ZED_URL_SCHEME}; use collections::VecDeque; @@ -458,10 +459,20 @@ fn initialize_panels(prompt_builder: Arc, cx: &mut ViewContext::set_global( + Arc::new(assistant2::ConcreteAssistantPanelDelegate), + cx, + ); + workspace .register_action(assistant2::AssistantPanel::toggle_focus) .register_action(assistant2::InlineAssistant::inline_assist); } else { + ::set_global( + Arc::new(assistant::assistant_panel::ConcreteAssistantPanelDelegate), + cx, + ); + workspace .register_action(assistant::AssistantPanel::toggle_focus) .register_action(assistant::AssistantPanel::inline_assist);