Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use a single Text segment + indoc! in active thread preview (#30373)
Michael Sloan8c8357387e3a
diff --git a/Cargo.lock b/Cargo.lockindex a29906beb46..460d8a465db 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3196,6 +3196,7 @@ dependencies = ["db","futures 0.3.31","gpui",+ "indoc","languages","log","notifications",diff --git a/crates/component_preview/Cargo.toml b/crates/component_preview/Cargo.tomlindex e3f04d8cba9..93cb81fc93a 100644--- a/crates/component_preview/Cargo.toml+++ b/crates/component_preview/Cargo.toml@@ -17,12 +17,14 @@ default = [][dependencies]agent.workspace = trueanyhow.workspace = true+assistant_tool.workspace = trueclient.workspace = truecollections.workspace = truecomponent.workspace = truedb.workspace = truefutures.workspace = truegpui.workspace = true+indoc.workspace = truelanguages.workspace = truelog.workspace = truenotifications.workspace = true@@ -34,4 +36,3 @@ ui_input.workspace = trueutil.workspace = trueworkspace-hack.workspace = trueworkspace.workspace = true-assistant_tool.workspace = truediff --git a/crates/component_preview/src/preview_support/active_thread.rs b/crates/component_preview/src/preview_support/active_thread.rsindex b66f7b64467..97b75cdf326 100644--- a/crates/component_preview/src/preview_support/active_thread.rs+++ b/crates/component_preview/src/preview_support/active_thread.rs@@ -1,12 +1,12 @@-use languages::LanguageRegistry;-use project::Project;-use std::sync::Arc;-use agent::{ActiveThread, ContextStore, MessageSegment, TextThreadStore, ThreadStore};use anyhow::{Result, anyhow};use assistant_tool::ToolWorkingSet;use gpui::{AppContext, AsyncApp, Entity, Task, WeakEntity};+use indoc::indoc;+use languages::LanguageRegistry;+use project::Project;use prompt_store::PromptBuilder;+use std::sync::Arc;use ui::{App, Window};use workspace::Workspace;@@ -60,16 +60,30 @@ pub fn static_active_thread(let thread = thread_store.update(cx, |thread_store, cx| thread_store.create_thread(cx));thread.update(cx, |thread, cx| {thread.insert_assistant_message(vec![- MessageSegment::Text("I'll help you fix the lifetime error in your `cx.spawn` call. When working with async operations in GPUI, there are specific patterns to follow for proper lifetime management.".to_string()),- MessageSegment::Text("\n\nLet's look at what's happening in your code:".to_string()),- MessageSegment::Text("\n\n---\n\nLet's check the current state of the active_thread.rs file to understand what might have changed:".to_string()),- MessageSegment::Text("\n\n---\n\nLooking at the implementation of `load_preview_thread_store` and understanding GPUI's async patterns, here's the issue:".to_string()),- MessageSegment::Text("\n\n1. `load_preview_thread_store` returns a `Task<anyhow::Result<Entity<ThreadStore>>>`, which means it's already a task".to_string()),- MessageSegment::Text("\n2. When you call this function inside another `spawn` call, you're nesting tasks incorrectly".to_string()),- MessageSegment::Text("\n3. The `this` parameter you're trying to use in your closure has the wrong context".to_string()),- MessageSegment::Text("\n\nHere's the correct way to implement this:".to_string()),- MessageSegment::Text("\n\n---\n\nThe problem is in how you're setting up the async closure and trying to reference variables like `window` and `language_registry` that aren't accessible in that scope.".to_string()),- MessageSegment::Text("\n\nHere's how to fix it:".to_string()),+ MessageSegment::Text(indoc! {"+ I'll help you fix the lifetime error in your `cx.spawn` call. When working with async operations in GPUI, there are specific patterns to follow for proper lifetime management.++ Let's look at what's happening in your code:++ ---++ Let's check the current state of the active_thread.rs file to understand what might have changed:++ ---++ Looking at the implementation of `load_preview_thread_store` and understanding GPUI's async patterns, here's the issue:++ 1. `load_preview_thread_store` returns a `Task<anyhow::Result<Entity<ThreadStore>>>`, which means it's already a task.+ 2. When you call this function inside another `spawn` call, you're nesting tasks incorrectly.++ Here's the correct way to implement this:++ ---++ The problem is in how you're setting up the async closure and trying to reference variables like `window` and `language_registry` that aren't accessible in that scope.++ Here's how to fix it:+ "}.to_string()),], cx);});cx.new(|cx| {