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
Unified · Split
| @@ -227,14 +227,14 @@ impl AssistantPanel { · 226 unmodified lines | ||
| 227 | 227 | ) -> Self { |
| 228 | 228 | let thread = thread_store.update(cx, |this, cx| this.create_thread(cx)); |
| 229 | 229 | let fs = workspace.app_state().fs.clone(); |
| 230 | − let project = workspace.project(); | |
| 230 | + let project = workspace.project().clone(); | |
| 231 | 231 | let language_registry = project.read(cx).languages().clone(); |
| 232 | 232 | let workspace = workspace.weak_handle(); |
| 233 | 233 | let weak_self = cx.entity().downgrade(); |
| 234 | 234 | |
| 235 | 235 | let message_editor_context_store = cx.new(|_cx| { |
| 236 | 236 | crate::context_store::ContextStore::new( |
| 237 | − project.downgrade(), | |
| 237 | + workspace.clone(), | |
| 238 | 238 | Some(thread_store.downgrade()), |
| 239 | 239 | ) |
| 240 | 240 | }); |
| @@ -344,7 +344,7 @@ impl AssistantPanel { · 103 unmodified lines | ||
| 344 | 344 | |
| 345 | 345 | let message_editor_context_store = cx.new(|_cx| { |
| 346 | 346 | crate::context_store::ContextStore::new( |
| 347 | − self.project.downgrade(), | |
| 347 | + self.workspace.clone(), | |
| 348 | 348 | Some(self.thread_store.downgrade()), |
| 349 | 349 | ) |
| 350 | 350 | }); |
| @@ -521,7 +521,7 @@ impl AssistantPanel { · 170 unmodified lines | ||
| 521 | 521 | this.set_active_view(thread_view, window, cx); |
| 522 | 522 | let message_editor_context_store = cx.new(|_cx| { |
| 523 | 523 | crate::context_store::ContextStore::new( |
| 524 | − this.project.downgrade(), | |
| 524 | + this.workspace.clone(), | |
| 525 | 525 | Some(this.thread_store.downgrade()), |
| 526 | 526 | ) |
| 527 | 527 | }); |
| @@ -867,7 +867,7 @@ mod tests { · 866 unmodified lines | ||
| 867 | 867 | .expect("Opened test file wasn't an editor") |
| 868 | 868 | }); |
| 869 | 869 | |
| 870 | − let context_store = cx.new(|_| ContextStore::new(project.downgrade(), None)); | |
| 870 | + let context_store = cx.new(|_| ContextStore::new(workspace.downgrade(), None)); | |
| 871 | 871 | |
| 872 | 872 | let editor_entity = editor.downgrade(); |
| 873 | 873 | editor.update_in(&mut cx, |editor, window, cx| { |
| @@ -8,10 +8,11 @@ use futures::future::join_all; · 7 unmodified lines | ||
| 8 | 8 | use futures::{self, Future, FutureExt, future}; |
| 9 | 9 | use gpui::{App, AppContext as _, Context, Entity, SharedString, Task, WeakEntity}; |
| 10 | 10 | use language::{Buffer, File}; |
| 11 | −use project::{Project, ProjectItem, ProjectPath, Worktree}; | |
| 11 | +use project::{ProjectItem, ProjectPath, Worktree}; | |
| 12 | 12 | use rope::Rope; |
| 13 | 13 | use text::{Anchor, BufferId, OffsetRangeExt}; |
| 14 | 14 | use util::{ResultExt as _, maybe}; |
| 15 | +use workspace::Workspace; | |
| 15 | 16 | |
| 16 | 17 | use crate::ThreadStore; |
| 17 | 18 | use crate::context::{ |
| @@ -22,7 +23,7 @@ use crate::context_strip::SuggestedContext; · 4 unmodified lines | ||
| 22 | 23 | use crate::thread::{Thread, ThreadId}; |
| 23 | 24 | |
| 24 | 25 | pub struct ContextStore { |
| 25 | − project: WeakEntity<Project>, | |
| 26 | + workspace: WeakEntity<Workspace>, | |
| 26 | 27 | context: Vec<AssistantContext>, |
| 27 | 28 | thread_store: Option<WeakEntity<ThreadStore>>, |
| 28 | 29 | // 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 | ||
| 39 | 40 | |
| 40 | 41 | impl ContextStore { |
| 41 | 42 | pub fn new( |
| 42 | − project: WeakEntity<Project>, | |
| 43 | + workspace: WeakEntity<Workspace>, | |
| 43 | 44 | thread_store: Option<WeakEntity<ThreadStore>>, |
| 44 | 45 | ) -> Self { |
| 45 | 46 | Self { |
| 46 | − project, | |
| 47 | + workspace, | |
| 47 | 48 | thread_store, |
| 48 | 49 | context: Vec::new(), |
| 49 | 50 | next_context_id: ContextId(0), |
| @@ -80,7 +81,12 @@ impl ContextStore { · 30 unmodified lines | ||
| 80 | 81 | remove_if_exists: bool, |
| 81 | 82 | cx: &mut Context<Self>, |
| 82 | 83 | ) -> 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 { | |
| 84 | 90 | return Task::ready(Err(anyhow!("failed to read project"))); |
| 85 | 91 | }; |
| 86 | 92 | |
| @@ -155,7 +161,11 @@ impl ContextStore { · 68 unmodified lines | ||
| 155 | 161 | remove_if_exists: bool, |
| 156 | 162 | cx: &mut Context<Self>, |
| 157 | 163 | ) -> 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 { | |
| 159 | 169 | return Task::ready(Err(anyhow!("failed to read project"))); |
| 160 | 170 | }; |
| 161 | 171 | |
| @@ -262,7 +262,13 @@ impl InlineAssistant { · 261 unmodified lines | ||
| 262 | 262 | } |
| 263 | 263 | InlineAssistTarget::Terminal(active_terminal) => { |
| 264 | 264 | 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 | + ) | |
| 266 | 272 | }) |
| 267 | 273 | } |
| 268 | 274 | }; |
| @@ -316,13 +322,6 @@ impl InlineAssistant { · 47 unmodified lines | ||
| 316 | 322 | window: &mut Window, |
| 317 | 323 | cx: &mut App, |
| 318 | 324 | ) { |
| 319 | − let Some(project) = workspace | |
| 320 | − .upgrade() | |
| 321 | − .map(|workspace| workspace.read(cx).project().downgrade()) | |
| 322 | − else { | |
| 323 | − return; | |
| 324 | − }; | |
| 325 | − | |
| 326 | 325 | let (snapshot, initial_selections) = editor.update(cx, |editor, cx| { |
| 327 | 326 | ( |
| 328 | 327 | editor.snapshot(window, cx), |
| @@ -426,7 +425,7 @@ impl InlineAssistant { · 97 unmodified lines | ||
| 426 | 425 | for range in codegen_ranges { |
| 427 | 426 | let assist_id = self.next_assist_id.post_inc(); |
| 428 | 427 | 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())); | |
| 430 | 429 | let codegen = cx.new(|cx| { |
| 431 | 430 | BufferCodegen::new( |
| 432 | 431 | editor.read(cx).buffer().clone(), |
| @@ -520,7 +519,7 @@ impl InlineAssistant { · 87 unmodified lines | ||
| 520 | 519 | initial_prompt: String, |
| 521 | 520 | initial_transaction_id: Option<TransactionId>, |
| 522 | 521 | focus: bool, |
| 523 | − workspace: Entity<Workspace>, | |
| 522 | + workspace: WeakEntity<Workspace>, | |
| 524 | 523 | thread_store: Option<WeakEntity<ThreadStore>>, |
| 525 | 524 | window: &mut Window, |
| 526 | 525 | cx: &mut App, |
| @@ -538,8 +537,8 @@ impl InlineAssistant { · 11 unmodified lines | ||
| 538 | 537 | range.end = range.end.bias_right(&snapshot); |
| 539 | 538 | } |
| 540 | 539 | |
| 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())); | |
| 543 | 542 | |
| 544 | 543 | let codegen = cx.new(|cx| { |
| 545 | 544 | BufferCodegen::new( |
| @@ -563,7 +562,7 @@ impl InlineAssistant { · 17 unmodified lines | ||
| 563 | 562 | codegen.clone(), |
| 564 | 563 | self.fs.clone(), |
| 565 | 564 | context_store, |
| 566 | − workspace.downgrade(), | |
| 565 | + workspace.clone(), | |
| 567 | 566 | thread_store, |
| 568 | 567 | window, |
| 569 | 568 | cx, |
| @@ -590,7 +589,7 @@ impl InlineAssistant { · 20 unmodified lines | ||
| 590 | 589 | end_block_id, |
| 591 | 590 | range, |
| 592 | 591 | codegen.clone(), |
| 593 | − workspace.downgrade(), | |
| 592 | + workspace.clone(), | |
| 594 | 593 | window, |
| 595 | 594 | cx, |
| 596 | 595 | ), |
| @@ -1780,7 +1779,6 @@ impl CodeActionProvider for AssistantCodeActionProvider { · 1183 unmodified lines | ||
| 1780 | 1779 | let workspace = self.workspace.clone(); |
| 1781 | 1780 | let thread_store = self.thread_store.clone(); |
| 1782 | 1781 | window.spawn(cx, async move |cx| { |
| 1783 | − let workspace = workspace.upgrade().context("workspace was released")?; | |
| 1784 | 1782 | let editor = editor.upgrade().context("editor was released")?; |
| 1785 | 1783 | let range = editor |
| 1786 | 1784 | .update(cx, |editor, cx| { |
| @@ -66,7 +66,7 @@ impl TerminalInlineAssistant { · 65 unmodified lines | ||
| 66 | 66 | pub fn assist( |
| 67 | 67 | &mut self, |
| 68 | 68 | terminal_view: &Entity<TerminalView>, |
| 69 | − workspace: Entity<Workspace>, | |
| 69 | + workspace: WeakEntity<Workspace>, | |
| 70 | 70 | thread_store: Option<WeakEntity<ThreadStore>>, |
| 71 | 71 | window: &mut Window, |
| 72 | 72 | cx: &mut App, |
| @@ -75,8 +75,8 @@ impl TerminalInlineAssistant { · 2 unmodified lines | ||
| 75 | 75 | let assist_id = self.next_assist_id.post_inc(); |
| 76 | 76 | let prompt_buffer = |
| 77 | 77 | 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())); | |
| 80 | 80 | let codegen = cx.new(|_| TerminalCodegen::new(terminal, self.telemetry.clone())); |
| 81 | 81 | |
| 82 | 82 | let prompt_editor = cx.new(|cx| { |
| @@ -87,7 +87,7 @@ impl TerminalInlineAssistant { · 4 unmodified lines | ||
| 87 | 87 | codegen, |
| 88 | 88 | self.fs.clone(), |
| 89 | 89 | context_store.clone(), |
| 90 | − workspace.downgrade(), | |
| 90 | + workspace.clone(), | |
| 91 | 91 | thread_store.clone(), |
| 92 | 92 | window, |
| 93 | 93 | cx, |
| @@ -106,7 +106,7 @@ impl TerminalInlineAssistant { · 12 unmodified lines | ||
| 106 | 106 | assist_id, |
| 107 | 107 | terminal_view, |
| 108 | 108 | prompt_editor, |
| 109 | − workspace.downgrade(), | |
| 109 | + workspace.clone(), | |
| 110 | 110 | context_store, |
| 111 | 111 | window, |
| 112 | 112 | cx, |
| @@ -2266,7 +2266,7 @@ fn main() {{ · 2265 unmodified lines | ||
| 2266 | 2266 | }); |
| 2267 | 2267 | |
| 2268 | 2268 | 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)); | |
| 2270 | 2270 | |
| 2271 | 2271 | ( |
| 2272 | 2272 | workspace, |