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