Don't construct an agent panel when disable_ai is set (#39689)
Follow-up to #39649, possible fix for #39669 This implements an alternate strategy for showing/hiding the agent panel in response to `disable_ai`. We don't load the panel at all if AI is disabled at startup, and when the value of `disable_ai` changes, we load the panel or destroy it as needed. Release Notes: - N/A
This commit is contained in:
+48
-14
@@ -46,7 +46,7 @@ use paths::{
|
||||
local_debug_file_relative_path, local_settings_file_relative_path,
|
||||
local_tasks_file_relative_path,
|
||||
};
|
||||
use project::{DirectoryLister, ProjectItem};
|
||||
use project::{DirectoryLister, DisableAiSettings, ProjectItem};
|
||||
use project_panel::ProjectPanel;
|
||||
use prompt_store::PromptBuilder;
|
||||
use quick_action_bar::QuickActionBar;
|
||||
@@ -604,21 +604,55 @@ fn initialize_panels(
|
||||
workspace.add_panel(debug_panel, window, cx);
|
||||
})?;
|
||||
|
||||
let is_assistant2_enabled = !cfg!(test);
|
||||
let agent_panel = if is_assistant2_enabled {
|
||||
let agent_panel =
|
||||
agent_ui::AgentPanel::load(workspace_handle.clone(), prompt_builder, cx.clone())
|
||||
.await?;
|
||||
fn setup_or_teardown_agent_panel(
|
||||
workspace: &mut Workspace,
|
||||
prompt_builder: Arc<PromptBuilder>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
let disable_ai = SettingsStore::global(cx)
|
||||
.get::<DisableAiSettings>(None)
|
||||
.disable_ai
|
||||
|| cfg!(test);
|
||||
let existing_panel = workspace.panel::<agent_ui::AgentPanel>(cx);
|
||||
match (disable_ai, existing_panel) {
|
||||
(false, None) => cx.spawn_in(window, async move |workspace, cx| {
|
||||
let panel =
|
||||
agent_ui::AgentPanel::load(workspace.clone(), prompt_builder, cx.clone())
|
||||
.await?;
|
||||
workspace.update_in(cx, |workspace, window, cx| {
|
||||
let disable_ai = SettingsStore::global(cx)
|
||||
.get::<DisableAiSettings>(None)
|
||||
.disable_ai;
|
||||
let have_panel = workspace.panel::<agent_ui::AgentPanel>(cx).is_some();
|
||||
if !disable_ai && !have_panel {
|
||||
workspace.add_panel(panel, window, cx);
|
||||
}
|
||||
})
|
||||
}),
|
||||
(true, Some(existing_panel)) => {
|
||||
workspace.remove_panel::<agent_ui::AgentPanel>(&existing_panel, window, cx);
|
||||
Task::ready(Ok(()))
|
||||
}
|
||||
_ => Task::ready(Ok(())),
|
||||
}
|
||||
}
|
||||
|
||||
Some(agent_panel)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
workspace_handle
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
setup_or_teardown_agent_panel(workspace, prompt_builder.clone(), window, cx)
|
||||
})?
|
||||
.await?;
|
||||
|
||||
workspace_handle.update_in(cx, |workspace, window, cx| {
|
||||
if let Some(agent_panel) = agent_panel {
|
||||
workspace.add_panel(agent_panel, window, cx);
|
||||
}
|
||||
cx.observe_global_in::<SettingsStore>(window, {
|
||||
let prompt_builder = prompt_builder.clone();
|
||||
move |workspace, window, cx| {
|
||||
setup_or_teardown_agent_panel(workspace, prompt_builder.clone(), window, cx)
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
// Register the actions that are shared between `assistant` and `assistant2`.
|
||||
//
|
||||
@@ -626,7 +660,7 @@ fn initialize_panels(
|
||||
// functions so that we only register the actions once.
|
||||
//
|
||||
// Once we ship `assistant2` we can push this back down into `agent::agent_panel::init`.
|
||||
if is_assistant2_enabled {
|
||||
if !cfg!(test) {
|
||||
<dyn AgentPanelDelegate>::set_global(
|
||||
Arc::new(agent_ui::ConcreteAssistantPanelDelegate),
|
||||
cx,
|
||||
|
||||
Reference in New Issue
Block a user