Use `read()` over `read_with()` to improve readability in simple cases (#31263)

Joseph T. Lyons created

Release Notes:

- N/A

Change summary

crates/agent/src/profile_selector.rs                              | 11 
crates/collab_ui/src/notifications/project_shared_notification.rs |  4 
crates/debugger_ui/src/debugger_panel.rs                          |  4 
crates/multi_buffer/src/multi_buffer.rs                           |  8 
crates/remote_server/src/headless_project.rs                      |  2 
5 files changed, 11 insertions(+), 18 deletions(-)

Detailed changes

crates/agent/src/profile_selector.rs 🔗

@@ -153,13 +153,10 @@ impl Render for ProfileSelector {
             .map(|profile| profile.name.clone())
             .unwrap_or_else(|| "Unknown".into());
 
-        let configured_model = self
-            .thread
-            .read_with(cx, |thread, _cx| thread.configured_model())
-            .or_else(|| {
-                let model_registry = LanguageModelRegistry::read_global(cx);
-                model_registry.default_model()
-            });
+        let configured_model = self.thread.read(cx).configured_model().or_else(|| {
+            let model_registry = LanguageModelRegistry::read_global(cx);
+            model_registry.default_model()
+        });
         let supports_tools =
             configured_model.map_or(false, |default| default.model.supports_tools());
 

crates/collab_ui/src/notifications/project_shared_notification.rs 🔗

@@ -109,9 +109,7 @@ impl ProjectSharedNotification {
     }
 
     fn dismiss(&mut self, cx: &mut Context<Self>) {
-        if let Some(active_room) =
-            ActiveCall::global(cx).read_with(cx, |call, _| call.room().cloned())
-        {
+        if let Some(active_room) = ActiveCall::global(cx).read(cx).room().cloned() {
             active_room.update(cx, |_, cx| {
                 cx.emit(room::Event::RemoteProjectInvitationDiscarded {
                     project_id: self.project_id,

crates/debugger_ui/src/debugger_panel.rs 🔗

@@ -349,9 +349,7 @@ impl DebugPanel {
         window: &mut Window,
         cx: &mut Context<Self>,
     ) {
-        while let Some(parent_session) =
-            curr_session.read_with(cx, |session, _| session.parent_session().cloned())
-        {
+        while let Some(parent_session) = curr_session.read(cx).parent_session().cloned() {
             curr_session = parent_session;
         }
 

crates/multi_buffer/src/multi_buffer.rs 🔗

@@ -1121,10 +1121,10 @@ impl MultiBuffer {
 
     pub fn last_transaction_id(&self, cx: &App) -> Option<TransactionId> {
         if let Some(buffer) = self.as_singleton() {
-            return buffer.read_with(cx, |b, _| {
-                b.peek_undo_stack()
-                    .map(|history_entry| history_entry.transaction_id())
-            });
+            return buffer
+                .read(cx)
+                .peek_undo_stack()
+                .map(|history_entry| history_entry.transaction_id());
         } else {
             let last_transaction = self.history.undo_stack.last()?;
             return Some(last_transaction.id);

crates/remote_server/src/headless_project.rs 🔗

@@ -536,7 +536,7 @@ impl HeadlessProject {
                 });
             }
 
-            let buffer_id = buffer.read_with(cx, |b, _| b.remote_id());
+            let buffer_id = buffer.read(cx).remote_id();
 
             buffer_store.update(cx, |buffer_store, cx| {
                 buffer_store