Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
assistant2: Don't block `ThreadStore` initialization on reloading the threads (#23728)
Marshall Bowersf096a28a1949
diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rsindex b6aa52b5ceb..e9b99a5213c 100644--- a/crates/assistant2/src/assistant_panel.rs+++ b/crates/assistant2/src/assistant_panel.rs@@ -119,12 +119,10 @@ impl AssistantPanel {cx.spawn(|mut cx| async move {let tools = Arc::new(ToolWorkingSet::default());log::info!("[assistant2-debug] initializing ThreadStore");- let thread_store = workspace- .update(&mut cx, |workspace, cx| {- let project = workspace.project().clone();- ThreadStore::new(project, tools.clone(), cx)- })?- .await?;+ let thread_store = workspace.update(&mut cx, |workspace, cx| {+ let project = workspace.project().clone();+ ThreadStore::new(project, tools.clone(), cx)+ })??;log::info!("[assistant2-debug] finished initializing ThreadStore");let slash_commands = Arc::new(SlashCommandWorkingSet::default());diff --git a/crates/assistant2/src/thread_store.rs b/crates/assistant2/src/thread_store.rsindex 386adb33d0c..3e7ee82da91 100644--- a/crates/assistant2/src/thread_store.rs+++ b/crates/assistant2/src/thread_store.rs@@ -34,45 +34,39 @@ impl ThreadStore {project: Entity<Project>,tools: Arc<ToolWorkingSet>,cx: &mut App,- ) -> Task<Result<Entity<Self>>> {- cx.spawn(|mut cx| async move {- let this = cx.new(|cx: &mut Context<Self>| {- let context_server_factory_registry =- ContextServerFactoryRegistry::default_global(cx);- let context_server_manager = cx.new(|cx| {- ContextServerManager::new(context_server_factory_registry, project.clone(), cx)- });+ ) -> Result<Entity<Self>> {+ let this = cx.new(|cx| {+ let context_server_factory_registry = ContextServerFactoryRegistry::default_global(cx);+ let context_server_manager = cx.new(|cx| {+ ContextServerManager::new(context_server_factory_registry, project.clone(), cx)+ });++ let executor = cx.background_executor().clone();+ let database_future = executor+ .spawn({+ let executor = executor.clone();+ let database_path = paths::support_dir().join("threads/threads-db.0.mdb");+ async move { ThreadsDatabase::new(database_path, executor) }+ })+ .then(|result| future::ready(result.map(Arc::new).map_err(Arc::new)))+ .boxed()+ .shared();++ let this = Self {+ project,+ tools,+ context_server_manager,+ context_server_tool_ids: HashMap::default(),+ threads: Vec::new(),+ database_future,+ };+ this.register_context_server_handlers(cx);+ this.reload(cx).detach_and_log_err(cx);- let executor = cx.background_executor().clone();- let database_future = executor- .spawn({- let executor = executor.clone();- let database_path = paths::support_dir().join("threads/threads-db.0.mdb");- async move { ThreadsDatabase::new(database_path, executor) }- })- .then(|result| future::ready(result.map(Arc::new).map_err(Arc::new)))- .boxed()- .shared();-- let this = Self {- project,- tools,- context_server_manager,- context_server_tool_ids: HashMap::default(),- threads: Vec::new(),- database_future,- };- this.register_context_server_handlers(cx);-- this- })?;-- log::info!("[assistant2-debug] reloading threads");- this.update(&mut cx, |this, cx| this.reload(cx))?.await?;- log::info!("[assistant2-debug] finished reloading threads");-- Ok(this)- })+ this+ });++ Ok(this)}/// Returns the number of threads.