From 014d9dfce15e6825d86b8010780a5022d91e1538 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Tue, 25 Feb 2025 14:24:51 -0500 Subject: [PATCH] assistant_context_editor: Try to fix crash when trying to view patch (#25572) Closes #24571 Attempts to fix crash described in #24571 based on the panic trace provided by the user. In short, the panic seemed to be caused by attempting to read an `Entity` while it was being updated. My assumption is that at some point in `workspace.add_item_to_current_pane` the `ContextEditor` is read. Therefore, I moved the workspace update outside of the ContextEditor update, and replaced another `update` call with a `read` call to clean it up and just in case that was actually the issue. Release Notes: - N/A --- .../src/context_editor.rs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/assistant_context_editor/src/context_editor.rs b/crates/assistant_context_editor/src/context_editor.rs index 12a522f56a..5ecebd3e8d 100644 --- a/crates/assistant_context_editor/src/context_editor.rs +++ b/crates/assistant_context_editor/src/context_editor.rs @@ -1087,7 +1087,7 @@ impl ContextEditor { patch: AssistantPatch, mut cx: AsyncWindowContext, ) -> Result<()> { - let project = this.update(&mut cx, |this, _| this.project.clone())?; + let project = this.read_with(&cx, |this, _| this.project.clone())?; let resolved_patch = patch.resolve(project.clone(), &mut cx).await; let editor = cx.new_window_entity(|window, cx| { @@ -1112,7 +1112,7 @@ impl ContextEditor { editor })?; - this.update_in(&mut cx, |this, window, cx| { + this.update(&mut cx, |this, _| { if let Some(patch_state) = this.patches.get_mut(&patch.range) { patch_state.editor = Some(PatchEditorState { editor: editor.downgrade(), @@ -1120,19 +1120,12 @@ impl ContextEditor { }); patch_state.update_task.take(); } - - this.workspace - .update(cx, |workspace, cx| { - workspace.add_item_to_active_pane( - Box::new(editor.clone()), - None, - false, - window, - cx, - ) - }) - .log_err(); })?; + this.read_with(&cx, |this, _| this.workspace.clone())? + .update_in(&mut cx, |workspace, window, cx| { + workspace.add_item_to_active_pane(Box::new(editor.clone()), None, false, window, cx) + }) + .log_err(); Ok(()) }