History

Revert to fix panic in inline assistant (#28428)

This reverts commit f12a554f86fa1e2b9b937a9dd103aa7c9a019db9, which introduced a panic in inline assistant (cc @mgsloan) - I'm not sure what the motivation was for that change, but I figure we can revert to fix the inline assistant now and deal with that later. 😄 Panic was: > Thread "main" panicked with "cannot read workspace::Workspace while it is already being updated" at /Users/rtfeldman/code/zed/crates/gpui/src/app/entity_map.rs:139:32 Release Notes: - N/A

Richard Feldman committed 1 year agov0.182.0-pre

Commit 17a271d1 parent 3d9dbfe6 files · +40 −32Browse files

Unified · Split

6 files
  1. crates/agent/src/assistant_panel.rs +4 −4
  2. crates/agent/src/context_picker/completion_provider.rs +1 −1
  3. crates/agent/src/context_store.rs +16 −6
  4. crates/agent/src/inline_assistant.rs +13 −15
  5. crates/agent/src/terminal_inline_assistant.rs +5 −5
  6. crates/agent/src/thread.rs +1 −1
crates/agent/src/assistant_panel.rs+4−4
@@ -227,14 +227,14 @@ impl AssistantPanel { · 226 unmodified lines
227227 ) -> Self {
228228 let thread = thread_store.update(cx, |this, cx| this.create_thread(cx));
229229 let fs = workspace.app_state().fs.clone();
230− let project = workspace.project();
230+ let project = workspace.project().clone();
231231 let language_registry = project.read(cx).languages().clone();
232232 let workspace = workspace.weak_handle();
233233 let weak_self = cx.entity().downgrade();
234234
235235 let message_editor_context_store = cx.new(|_cx| {
236236 crate::context_store::ContextStore::new(
237− project.downgrade(),
237+ workspace.clone(),
238238 Some(thread_store.downgrade()),
239239 )
240240 });
@@ -344,7 +344,7 @@ impl AssistantPanel { · 103 unmodified lines
344344
345345 let message_editor_context_store = cx.new(|_cx| {
346346 crate::context_store::ContextStore::new(
347− self.project.downgrade(),
347+ self.workspace.clone(),
348348 Some(self.thread_store.downgrade()),
349349 )
350350 });
@@ -521,7 +521,7 @@ impl AssistantPanel { · 170 unmodified lines
521521 this.set_active_view(thread_view, window, cx);
522522 let message_editor_context_store = cx.new(|_cx| {
523523 crate::context_store::ContextStore::new(
524− this.project.downgrade(),
524+ this.workspace.clone(),
525525 Some(this.thread_store.downgrade()),
526526 )
527527 });
crates/agent/src/context_picker/completion_provider.rs+1−1
@@ -867,7 +867,7 @@ mod tests { · 866 unmodified lines
867867 .expect("Opened test file wasn't an editor")
868868 });
869869
870− let context_store = cx.new(|_| ContextStore::new(project.downgrade(), None));
870+ let context_store = cx.new(|_| ContextStore::new(workspace.downgrade(), None));
871871
872872 let editor_entity = editor.downgrade();
873873 editor.update_in(&mut cx, |editor, window, cx| {
crates/agent/src/context_store.rs+16−6
@@ -8,10 +8,11 @@ use futures::future::join_all; · 7 unmodified lines
88 use futures::{self, Future, FutureExt, future};
99 use gpui::{App, AppContext as _, Context, Entity, SharedString, Task, WeakEntity};
1010 use language::{Buffer, File};
11−use project::{Project, ProjectItem, ProjectPath, Worktree};
11+use project::{ProjectItem, ProjectPath, Worktree};
1212 use rope::Rope;
1313 use text::{Anchor, BufferId, OffsetRangeExt};
1414 use util::{ResultExt as _, maybe};
15+use workspace::Workspace;
1516
1617 use crate::ThreadStore;
1718 use crate::context::{
@@ -22,7 +23,7 @@ use crate::context_strip::SuggestedContext; · 4 unmodified lines
2223 use crate::thread::{Thread, ThreadId};
2324
2425 pub struct ContextStore {
25− project: WeakEntity<Project>,
26+ workspace: WeakEntity<Workspace>,
2627 context: Vec<AssistantContext>,
2728 thread_store: Option<WeakEntity<ThreadStore>>,
2829 // TODO: If an EntityId is used for all context types (like BufferId), can remove ContextId.
@@ -39,11 +40,11 @@ pub struct ContextStore { · 10 unmodified lines
3940
4041 impl ContextStore {
4142 pub fn new(
42− project: WeakEntity<Project>,
43+ workspace: WeakEntity<Workspace>,
4344 thread_store: Option<WeakEntity<ThreadStore>>,
4445 ) -> Self {
4546 Self {
46− project,
47+ workspace,
4748 thread_store,
4849 context: Vec::new(),
4950 next_context_id: ContextId(0),
@@ -80,7 +81,12 @@ impl ContextStore { · 30 unmodified lines
8081 remove_if_exists: bool,
8182 cx: &mut Context<Self>,
8283 ) -> Task<Result<()>> {
83− let Some(project) = self.project.upgrade() else {
84+ let workspace = self.workspace.clone();
85+
86+ let Some(project) = workspace
87+ .upgrade()
88+ .map(|workspace| workspace.read(cx).project().clone())
89+ else {
8490 return Task::ready(Err(anyhow!("failed to read project")));
8591 };
8692
@@ -155,7 +161,11 @@ impl ContextStore { · 68 unmodified lines
155161 remove_if_exists: bool,
156162 cx: &mut Context<Self>,
157163 ) -> Task<Result<()>> {
158− let Some(project) = self.project.upgrade() else {
164+ let workspace = self.workspace.clone();
165+ let Some(project) = workspace
166+ .upgrade()
167+ .map(|workspace| workspace.read(cx).project().clone())
168+ else {
159169 return Task::ready(Err(anyhow!("failed to read project")));
160170 };
161171
crates/agent/src/inline_assistant.rs+13−15
@@ -262,7 +262,13 @@ impl InlineAssistant { · 261 unmodified lines
262262 }
263263 InlineAssistTarget::Terminal(active_terminal) => {
264264 TerminalInlineAssistant::update_global(cx, |assistant, cx| {
265− assistant.assist(&active_terminal, cx.entity(), thread_store, window, cx)
265+ assistant.assist(
266+ &active_terminal,
267+ cx.entity().downgrade(),
268+ thread_store,
269+ window,
270+ cx,
271+ )
266272 })
267273 }
268274 };
@@ -316,13 +322,6 @@ impl InlineAssistant { · 47 unmodified lines
316322 window: &mut Window,
317323 cx: &mut App,
318324 ) {
319− let Some(project) = workspace
320− .upgrade()
321− .map(|workspace| workspace.read(cx).project().downgrade())
322− else {
323− return;
324− };
325−
326325 let (snapshot, initial_selections) = editor.update(cx, |editor, cx| {
327326 (
328327 editor.snapshot(window, cx),
@@ -426,7 +425,7 @@ impl InlineAssistant { · 97 unmodified lines
426425 for range in codegen_ranges {
427426 let assist_id = self.next_assist_id.post_inc();
428427 let context_store =
429− cx.new(|_cx| ContextStore::new(project.clone(), thread_store.clone()));
428+ cx.new(|_cx| ContextStore::new(workspace.clone(), thread_store.clone()));
430429 let codegen = cx.new(|cx| {
431430 BufferCodegen::new(
432431 editor.read(cx).buffer().clone(),
@@ -520,7 +519,7 @@ impl InlineAssistant { · 87 unmodified lines
520519 initial_prompt: String,
521520 initial_transaction_id: Option<TransactionId>,
522521 focus: bool,
523− workspace: Entity<Workspace>,
522+ workspace: WeakEntity<Workspace>,
524523 thread_store: Option<WeakEntity<ThreadStore>>,
525524 window: &mut Window,
526525 cx: &mut App,
@@ -538,8 +537,8 @@ impl InlineAssistant { · 11 unmodified lines
538537 range.end = range.end.bias_right(&snapshot);
539538 }
540539
541− let project = workspace.read(cx).project().downgrade();
542− let context_store = cx.new(|_cx| ContextStore::new(project, thread_store.clone()));
540+ let context_store =
541+ cx.new(|_cx| ContextStore::new(workspace.clone(), thread_store.clone()));
543542
544543 let codegen = cx.new(|cx| {
545544 BufferCodegen::new(
@@ -563,7 +562,7 @@ impl InlineAssistant { · 17 unmodified lines
563562 codegen.clone(),
564563 self.fs.clone(),
565564 context_store,
566− workspace.downgrade(),
565+ workspace.clone(),
567566 thread_store,
568567 window,
569568 cx,
@@ -590,7 +589,7 @@ impl InlineAssistant { · 20 unmodified lines
590589 end_block_id,
591590 range,
592591 codegen.clone(),
593− workspace.downgrade(),
592+ workspace.clone(),
594593 window,
595594 cx,
596595 ),
@@ -1780,7 +1779,6 @@ impl CodeActionProvider for AssistantCodeActionProvider { · 1183 unmodified lines
17801779 let workspace = self.workspace.clone();
17811780 let thread_store = self.thread_store.clone();
17821781 window.spawn(cx, async move |cx| {
1783− let workspace = workspace.upgrade().context("workspace was released")?;
17841782 let editor = editor.upgrade().context("editor was released")?;
17851783 let range = editor
17861784 .update(cx, |editor, cx| {
crates/agent/src/terminal_inline_assistant.rs+5−5
@@ -66,7 +66,7 @@ impl TerminalInlineAssistant { · 65 unmodified lines
6666 pub fn assist(
6767 &mut self,
6868 terminal_view: &Entity<TerminalView>,
69− workspace: Entity<Workspace>,
69+ workspace: WeakEntity<Workspace>,
7070 thread_store: Option<WeakEntity<ThreadStore>>,
7171 window: &mut Window,
7272 cx: &mut App,
@@ -75,8 +75,8 @@ impl TerminalInlineAssistant { · 2 unmodified lines
7575 let assist_id = self.next_assist_id.post_inc();
7676 let prompt_buffer =
7777 cx.new(|cx| MultiBuffer::singleton(cx.new(|cx| Buffer::local(String::new(), cx)), cx));
78− let project = workspace.read(cx).project().downgrade();
79− let context_store = cx.new(|_cx| ContextStore::new(project, thread_store.clone()));
78+ let context_store =
79+ cx.new(|_cx| ContextStore::new(workspace.clone(), thread_store.clone()));
8080 let codegen = cx.new(|_| TerminalCodegen::new(terminal, self.telemetry.clone()));
8181
8282 let prompt_editor = cx.new(|cx| {
@@ -87,7 +87,7 @@ impl TerminalInlineAssistant { · 4 unmodified lines
8787 codegen,
8888 self.fs.clone(),
8989 context_store.clone(),
90− workspace.downgrade(),
90+ workspace.clone(),
9191 thread_store.clone(),
9292 window,
9393 cx,
@@ -106,7 +106,7 @@ impl TerminalInlineAssistant { · 12 unmodified lines
106106 assist_id,
107107 terminal_view,
108108 prompt_editor,
109− workspace.downgrade(),
109+ workspace.clone(),
110110 context_store,
111111 window,
112112 cx,
crates/agent/src/thread.rs+1−1
@@ -2266,7 +2266,7 @@ fn main() {{ · 2265 unmodified lines
22662266 });
22672267
22682268 let thread = thread_store.update(cx, |store, cx| store.create_thread(cx));
2269− let context_store = cx.new(|_cx| ContextStore::new(project.downgrade(), None));
2269+ let context_store = cx.new(|_cx| ContextStore::new(workspace.downgrade(), None));
22702270
22712271 (
22722272 workspace,