Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use read-only access methods for read-only entity operations (#31254)
Joseph T. Lyonsf435304209e0
diff --git a/crates/agent/src/context_picker/completion_provider.rs b/crates/agent/src/context_picker/completion_provider.rsindex ebdd984d48b..49c31e8af22 100644--- a/crates/agent/src/context_picker/completion_provider.rs+++ b/crates/agent/src/context_picker/completion_provider.rs@@ -1213,7 +1213,7 @@ mod tests {assert_eq!(worktrees.len(), 1);worktrees.pop().unwrap()});- let worktree_id = worktree.update(cx, |worktree, _| worktree.id());+ let worktree_id = worktree.read_with(cx, |worktree, _| worktree.id());let mut cx = VisualTestContext::from_window(*window.deref(), cx);diff --git a/crates/agent/src/inline_prompt_editor.rs b/crates/agent/src/inline_prompt_editor.rsindex ea80a91945b..b47f9ac01a8 100644--- a/crates/agent/src/inline_prompt_editor.rs+++ b/crates/agent/src/inline_prompt_editor.rs@@ -326,9 +326,7 @@ impl<T: 'static> PromptEditor<T> {EditorEvent::Edited { .. } => {if let Some(workspace) = window.root::<Workspace>().flatten() {workspace.update(cx, |workspace, cx| {- let is_via_ssh = workspace- .project()- .update(cx, |project, _| project.is_via_ssh());+ let is_via_ssh = workspace.project().read(cx).is_via_ssh();workspace.client()diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rsindex 98f505f074a..f87e8e7d764 100644--- a/crates/agent/src/thread.rs+++ b/crates/agent/src/thread.rs@@ -2851,7 +2851,8 @@ mod tests {.await.unwrap();- let context = context_store.update(cx, |store, _| store.context().next().cloned().unwrap());+ let context =+ context_store.read_with(cx, |store, _| store.context().next().cloned().unwrap());let loaded_context = cx.update(|cx| load_context(vec![context], &project, &None, cx)).await;@@ -3162,7 +3163,8 @@ fn main() {{.await.unwrap();- let context = context_store.update(cx, |store, _| store.context().next().cloned().unwrap());+ let context =+ context_store.read_with(cx, |store, _| store.context().next().cloned().unwrap());let loaded_context = cx.update(|cx| load_context(vec![context], &project, &None, cx)).await;diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rsindex 2c158b88316..29159bbc01a 100644--- a/crates/auto_update/src/auto_update.rs+++ b/crates/auto_update/src/auto_update.rs@@ -493,7 +493,7 @@ impl AutoUpdater {async fn update(this: Entity<Self>, mut cx: AsyncApp) -> Result<()> {let (client, installed_version, previous_status, release_channel) =- this.update(&mut cx, |this, cx| {+ this.read_with(&mut cx, |this, cx| {(this.http_client.clone(),this.current_version,diff --git a/crates/channel/src/channel_store_tests.rs b/crates/channel/src/channel_store_tests.rsindex b7bed8a1a93..20afdf0ec66 100644--- a/crates/channel/src/channel_store_tests.rs+++ b/crates/channel/src/channel_store_tests.rs@@ -137,7 +137,7 @@ async fn test_channel_messages(cx: &mut TestAppContext) {let user_id = 5;let channel_id = 5;let channel_store = cx.update(init_test);- let client = channel_store.update(cx, |s, _| s.client());+ let client = channel_store.read_with(cx, |s, _| s.client());let server = FakeServer::for_client(user_id, &client, cx).await;// Get the available channels.diff --git a/crates/collab/src/tests/following_tests.rs b/crates/collab/src/tests/following_tests.rsindex 0f5bdd53260..18ad066993c 100644--- a/crates/collab/src/tests/following_tests.rs+++ b/crates/collab/src/tests/following_tests.rs@@ -2066,7 +2066,7 @@ async fn share_workspace(workspace: &Entity<Workspace>,cx: &mut VisualTestContext,) -> anyhow::Result<u64> {- let project = workspace.update(cx, |workspace, _| workspace.project().clone());+ let project = workspace.read_with(cx, |workspace, _| workspace.project().clone());cx.read(ActiveCall::global).update(cx, |call, cx| call.share_project(project, cx)).awaitdiff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rsindex ae0dbc37a57..af8ea382655 100644--- a/crates/collab/src/tests/integration_tests.rs+++ b/crates/collab/src/tests/integration_tests.rs@@ -6416,7 +6416,7 @@ async fn test_join_after_restart(cx1: &mut TestAppContext, cx2: &mut TestAppContasync fn test_preview_tabs(cx: &mut TestAppContext) {let (_server, client) = TestServer::start1(cx).await;let (workspace, cx) = client.build_test_workspace(cx).await;- let project = workspace.update(cx, |workspace, _| workspace.project().clone());+ let project = workspace.read_with(cx, |workspace, _| workspace.project().clone());let worktree_id = project.update(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()@@ -6435,7 +6435,7 @@ async fn test_preview_tabs(cx: &mut TestAppContext) {path: Path::new("3.rs").into(),};- let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone());+ let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());let get_path = |pane: &Pane, idx: usize, cx: &App| {pane.item_for_index(idx).unwrap().project_path(cx).unwrap()@@ -6588,7 +6588,7 @@ async fn test_preview_tabs(cx: &mut TestAppContext) {pane.split(workspace::SplitDirection::Right, cx);});- let right_pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone());+ let right_pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());pane.update(cx, |pane, cx| {assert_eq!(pane.items_len(), 1);diff --git a/crates/debugger_ui/src/tests/console.rs b/crates/debugger_ui/src/tests/console.rsindex 65912181a0b..2c31c87f546 100644--- a/crates/debugger_ui/src/tests/console.rs+++ b/crates/debugger_ui/src/tests/console.rs@@ -33,7 +33,7 @@ async fn test_handle_output_event(executor: BackgroundExecutor, cx: &mut TestApp.unwrap();let session = start_debug_session(&workspace, cx, |_| {}).unwrap();- let client = session.update(cx, |session, _| session.adapter_client().unwrap());+ let client = session.read_with(cx, |session, _| session.adapter_client().unwrap());client.on_request::<StackTrace, _>(move |_, _| {Ok(dap::StackTraceResponse {diff --git a/crates/debugger_ui/src/tests/debugger_panel.rs b/crates/debugger_ui/src/tests/debugger_panel.rsindex 9edfd240c46..f802d804cd1 100644--- a/crates/debugger_ui/src/tests/debugger_panel.rs+++ b/crates/debugger_ui/src/tests/debugger_panel.rs@@ -1015,7 +1015,7 @@ async fn test_debug_panel_item_thread_status_reset_on_failure(cx.run_until_parked();let running_state = active_debug_session_panel(workspace, cx)- .update(cx, |item, _| item.running_state().clone());+ .read_with(cx, |item, _| item.running_state().clone());cx.run_until_parked();let thread_id = ThreadId(1);diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rsindex 20d6e4006c5..18b5cde0568 100644--- a/crates/search/src/buffer_search.rs+++ b/crates/search/src/buffer_search.rs@@ -2397,7 +2397,7 @@ mod tests {search_bar.replace_all(&ReplaceAll, window, cx)});assert_eq!(- editor.update(cx, |this, cx| { this.text(cx) }),+ editor.read_with(cx, |this, cx| { this.text(cx) }),r#"A regular expr$1 (shortened as regex or regexp;[1] also referred to asrational expr$1[2][3]) is a sequence of characters that specifies a search@@ -2423,7 +2423,7 @@ mod tests {});// Notice how the first or in the text (shORtened) is not replaced. Neither are the remaining hits of `or` in the text.assert_eq!(- editor.update(cx, |this, cx| { this.text(cx) }),+ editor.read_with(cx, |this, cx| { this.text(cx) }),r#"A regular expr$1 (shortened as regex banana regexp;[1] also referred to asrational expr$1[2][3]) is a sequence of characters that specifies a search@@ -2446,7 +2446,7 @@ mod tests {search_bar.replace_all(&ReplaceAll, window, cx)});assert_eq!(- editor.update(cx, |this, cx| { this.text(cx) }),+ editor.read_with(cx, |this, cx| { this.text(cx) }),r#"A regular expr$1 (shortened as regex banana regexp;1number also referred to asrational expr$12number3number) is a sequence of characters that specifies a search@@ -2476,7 +2476,7 @@ mod tests {// The only word affected by this edit should be `algorithms`, even though there's a bunch// of words in this text that would match this regex if not for WHOLE_WORD.assert_eq!(- editor.update(cx, |this, cx| { this.text(cx) }),+ editor.read_with(cx, |this, cx| { this.text(cx) }),r#"A regular expr$1 (shortened as regex banana regexp;1number also referred to asrational expr$12number3number) is a sequence of characters that specifies a search@@ -2527,7 +2527,7 @@ mod tests {assert_eq!(options.editor- .update(options.cx, |this, cx| { this.text(cx) }),+ .read_with(options.cx, |this, cx| { this.text(cx) }),options.expected_text);}diff --git a/crates/tab_switcher/src/tab_switcher_tests.rs b/crates/tab_switcher/src/tab_switcher_tests.rsindex a1b53faf58f..2ea9d6d817b 100644--- a/crates/tab_switcher/src/tab_switcher_tests.rs+++ b/crates/tab_switcher/src/tab_switcher_tests.rs@@ -326,7 +326,7 @@ async fn open_buffer(workspace: &Entity<Workspace>,cx: &mut gpui::VisualTestContext,) -> Box<dyn ItemHandle> {- let project = workspace.update(cx, |workspace, _| workspace.project().clone());+ let project = workspace.read_with(cx, |workspace, _| workspace.project().clone());let worktree_id = project.update(cx, |project, cx| {let worktree = project.worktrees(cx).last().expect("worktree not found");worktree.read(cx).id()