From 03c84466c22390bce5802c6ba4f27108d2ab5d61 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 7 Oct 2024 01:29:58 +0200 Subject: [PATCH] chore: Fix some violations of 'needless_pass_by_ref_mut' lint (#18795) While this lint is allow-by-default, it seems pretty useful to get rid of mutable borrows when they're not needed. Closes #ISSUE Release Notes: - N/A --- clippy.toml | 1 + crates/assistant/src/context.rs | 2 +- crates/client/src/client.rs | 2 +- crates/client/src/telemetry.rs | 2 +- crates/client/src/user.rs | 38 ++++----- crates/db/src/db.rs | 2 +- .../src/git_hosting_providers.rs | 2 +- crates/gpui/src/app.rs | 22 +++-- crates/gpui/src/app/async_context.rs | 4 +- crates/gpui/src/app/model_context.rs | 6 +- crates/gpui/src/elements/div.rs | 4 +- crates/gpui/src/elements/text.rs | 6 +- crates/gpui/src/elements/uniform_list.rs | 2 +- crates/gpui/src/geometry.rs | 8 +- crates/gpui/src/key_dispatch.rs | 4 +- crates/gpui/src/platform/app_menu.rs | 2 +- .../gpui/src/platform/mac/metal_renderer.rs | 18 ++--- crates/gpui/src/platform/mac/platform.rs | 2 +- crates/gpui/src/window.rs | 44 +++++----- crates/language/src/buffer.rs | 24 ++---- crates/markdown/src/markdown.rs | 18 ++--- crates/multi_buffer/src/multi_buffer.rs | 14 ++-- crates/project/src/project_settings.rs | 2 +- crates/remote/src/ssh_session.rs | 6 +- crates/session/src/session.rs | 2 +- crates/settings/src/settings_file.rs | 2 +- crates/snippet_provider/src/lib.rs | 2 +- crates/task/src/static_source.rs | 4 +- crates/terminal/src/terminal.rs | 19 ++--- crates/theme/src/registry.rs | 2 +- crates/theme/src/settings.rs | 6 +- crates/worktree/src/worktree.rs | 80 ++++++++----------- crates/zed/src/reliability.rs | 2 +- crates/zed/src/zed.rs | 4 +- .../zed/src/zed/inline_completion_registry.rs | 2 +- crates/zed/src/zed/open_listener.rs | 2 +- 36 files changed, 158 insertions(+), 204 deletions(-) diff --git a/clippy.toml b/clippy.toml index 787620d865..8c8da03a26 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,2 @@ allow-private-module-inception = true +avoid-breaking-exported-api = false diff --git a/crates/assistant/src/context.rs b/crates/assistant/src/context.rs index c360c0cb69..c27d17f8c5 100644 --- a/crates/assistant/src/context.rs +++ b/crates/assistant/src/context.rs @@ -549,7 +549,7 @@ impl Context { cx: &mut ModelContext, ) -> Self { let buffer = cx.new_model(|_cx| { - let mut buffer = Buffer::remote( + let buffer = Buffer::remote( language::BufferId::new(1).unwrap(), replica_id, capability, diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 819bd7551f..03d81b117f 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -394,7 +394,7 @@ pub struct PendingEntitySubscription { } impl PendingEntitySubscription { - pub fn set_model(mut self, model: &Model, cx: &mut AsyncAppContext) -> Subscription { + pub fn set_model(mut self, model: &Model, cx: &AsyncAppContext) -> Subscription { self.consumed = true; let mut handlers = self.client.handler_set.lock(); let id = (TypeId::of::(), self.remote_id); diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 5ec2e5b1aa..ee6da64d22 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -288,7 +288,7 @@ impl Telemetry { system_id: Option, installation_id: Option, session_id: String, - cx: &mut AppContext, + cx: &AppContext, ) { let mut state = self.state.lock(); state.system_id = system_id.map(|id| id.into()); diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index 0f53b35fc1..a312dd3495 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -138,7 +138,7 @@ enum UpdateContacts { } impl UserStore { - pub fn new(client: Arc, cx: &mut ModelContext) -> Self { + pub fn new(client: Arc, cx: &ModelContext) -> Self { let (mut current_user_tx, current_user_rx) = watch::channel(); let (update_contacts_tx, mut update_contacts_rx) = mpsc::unbounded(); let rpc_subscriptions = vec![ @@ -310,7 +310,7 @@ impl UserStore { fn update_contacts( &mut self, message: UpdateContacts, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { match message { UpdateContacts::Wait(barrier) => { @@ -525,9 +525,9 @@ impl UserStore { } pub fn dismiss_contact_request( - &mut self, + &self, requester_id: u64, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let client = self.client.upgrade(); cx.spawn(move |_, _| async move { @@ -573,7 +573,7 @@ impl UserStore { }) } - pub fn clear_contacts(&mut self) -> impl Future { + pub fn clear_contacts(&self) -> impl Future { let (tx, mut rx) = postage::barrier::channel(); self.update_contacts_tx .unbounded_send(UpdateContacts::Clear(tx)) @@ -583,7 +583,7 @@ impl UserStore { } } - pub fn contact_updates_done(&mut self) -> impl Future { + pub fn contact_updates_done(&self) -> impl Future { let (tx, mut rx) = postage::barrier::channel(); self.update_contacts_tx .unbounded_send(UpdateContacts::Wait(tx)) @@ -594,9 +594,9 @@ impl UserStore { } pub fn get_users( - &mut self, + &self, user_ids: Vec, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>>> { let mut user_ids_to_fetch = user_ids.clone(); user_ids_to_fetch.retain(|id| !self.users.contains_key(id)); @@ -629,9 +629,9 @@ impl UserStore { } pub fn fuzzy_search_users( - &mut self, + &self, query: String, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>>> { self.load_users(proto::FuzzySearchUsers { query }, cx) } @@ -640,11 +640,7 @@ impl UserStore { self.users.get(&user_id).cloned() } - pub fn get_user_optimistic( - &mut self, - user_id: u64, - cx: &mut ModelContext, - ) -> Option> { + pub fn get_user_optimistic(&self, user_id: u64, cx: &ModelContext) -> Option> { if let Some(user) = self.users.get(&user_id).cloned() { return Some(user); } @@ -653,11 +649,7 @@ impl UserStore { None } - pub fn get_user( - &mut self, - user_id: u64, - cx: &mut ModelContext, - ) -> Task>> { + pub fn get_user(&self, user_id: u64, cx: &ModelContext) -> Task>> { if let Some(user) = self.users.get(&user_id).cloned() { return Task::ready(Ok(user)); } @@ -697,7 +689,7 @@ impl UserStore { .map(|accepted_tos_at| accepted_tos_at.is_some()) } - pub fn accept_terms_of_service(&mut self, cx: &mut ModelContext) -> Task> { + pub fn accept_terms_of_service(&self, cx: &ModelContext) -> Task> { if self.current_user().is_none() { return Task::ready(Err(anyhow!("no current user"))); }; @@ -726,9 +718,9 @@ impl UserStore { } fn load_users( - &mut self, + &self, request: impl RequestMessage, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>>> { let client = self.client.clone(); cx.spawn(|this, mut cx| async move { diff --git a/crates/db/src/db.rs b/crates/db/src/db.rs index 4d87222c77..98fca60d63 100644 --- a/crates/db/src/db.rs +++ b/crates/db/src/db.rs @@ -188,7 +188,7 @@ macro_rules! define_connection { }; } -pub fn write_and_log(cx: &mut AppContext, db_write: impl FnOnce() -> F + Send + 'static) +pub fn write_and_log(cx: &AppContext, db_write: impl FnOnce() -> F + Send + 'static) where F: Future> + Send, { diff --git a/crates/git_hosting_providers/src/git_hosting_providers.rs b/crates/git_hosting_providers/src/git_hosting_providers.rs index 7bb77c0307..864faa9b49 100644 --- a/crates/git_hosting_providers/src/git_hosting_providers.rs +++ b/crates/git_hosting_providers/src/git_hosting_providers.rs @@ -8,7 +8,7 @@ use gpui::AppContext; pub use crate::providers::*; /// Initializes the Git hosting providers. -pub fn init(cx: &mut AppContext) { +pub fn init(cx: &AppContext) { let provider_registry = GitHostingProviderRegistry::global(cx); // The providers are stored in a `BTreeMap`, so insertion order matters. diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 540e459ce1..bba5f857b4 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -348,7 +348,7 @@ impl AppContext { } /// Gracefully quit the application via the platform's standard routine. - pub fn quit(&mut self) { + pub fn quit(&self) { self.platform.quit(); } @@ -1004,11 +1004,7 @@ impl AppContext { self.globals_by_type.insert(global_type, lease.global); } - pub(crate) fn new_view_observer( - &mut self, - key: TypeId, - value: NewViewListener, - ) -> Subscription { + pub(crate) fn new_view_observer(&self, key: TypeId, value: NewViewListener) -> Subscription { let (subscription, activate) = self.new_view_observers.insert(key, value); activate(); subscription @@ -1016,7 +1012,7 @@ impl AppContext { /// Arrange for the given function to be invoked whenever a view of the specified type is created. /// The function will be passed a mutable reference to the view along with an appropriate context. pub fn observe_new_views( - &mut self, + &self, on_new: impl 'static + Fn(&mut V, &mut ViewContext), ) -> Subscription { self.new_view_observer( @@ -1035,7 +1031,7 @@ impl AppContext { /// Observe the release of a model or view. The callback is invoked after the model or view /// has no more strong references but before it has been dropped. pub fn observe_release( - &mut self, + &self, handle: &E, on_release: impl FnOnce(&mut T, &mut AppContext) + 'static, ) -> Subscription @@ -1062,7 +1058,7 @@ impl AppContext { mut f: impl FnMut(&KeystrokeEvent, &mut WindowContext) + 'static, ) -> Subscription { fn inner( - keystroke_observers: &mut SubscriberSet<(), KeystrokeObserver>, + keystroke_observers: &SubscriberSet<(), KeystrokeObserver>, handler: KeystrokeObserver, ) -> Subscription { let (subscription, activate) = keystroke_observers.insert((), handler); @@ -1140,7 +1136,7 @@ impl AppContext { /// Register a callback to be invoked when the application is about to quit. /// It is not possible to cancel the quit event at this point. pub fn on_app_quit( - &mut self, + &self, mut on_quit: impl FnMut(&mut AppContext) -> Fut + 'static, ) -> Subscription where @@ -1186,7 +1182,7 @@ impl AppContext { } /// Sets the menu bar for this application. This will replace any existing menu bar. - pub fn set_menus(&mut self, menus: Vec) { + pub fn set_menus(&self, menus: Vec) { self.platform.set_menus(menus, &self.keymap.borrow()); } @@ -1196,7 +1192,7 @@ impl AppContext { } /// Sets the right click menu for the app icon in the dock - pub fn set_dock_menu(&mut self, menus: Vec) { + pub fn set_dock_menu(&self, menus: Vec) { self.platform.set_dock_menu(menus, &self.keymap.borrow()); } @@ -1204,7 +1200,7 @@ impl AppContext { /// The list is usually shown on the application icon's context menu in the dock, /// and allows to open the recent files via that context menu. /// If the path is already in the list, it will be moved to the bottom of the list. - pub fn add_recent_document(&mut self, path: &Path) { + pub fn add_recent_document(&self, path: &Path) { self.platform.add_recent_document(path); } diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rs index 06e44e71a3..be35776595 100644 --- a/crates/gpui/src/app/async_context.rs +++ b/crates/gpui/src/app/async_context.rs @@ -107,7 +107,7 @@ impl Context for AsyncAppContext { impl AsyncAppContext { /// Schedules all windows in the application to be redrawn. - pub fn refresh(&mut self) -> Result<()> { + pub fn refresh(&self) -> Result<()> { let app = self .app .upgrade() @@ -205,7 +205,7 @@ impl AsyncAppContext { /// A convenience method for [AppContext::update_global] /// for updating the global state of the specified type. pub fn update_global( - &mut self, + &self, update: impl FnOnce(&mut G, &mut AppContext) -> R, ) -> Result { let app = self diff --git a/crates/gpui/src/app/model_context.rs b/crates/gpui/src/app/model_context.rs index 3aebf88539..d3f07b25eb 100644 --- a/crates/gpui/src/app/model_context.rs +++ b/crates/gpui/src/app/model_context.rs @@ -91,7 +91,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { /// Register a callback to be invoked when GPUI releases this model. pub fn on_release( - &mut self, + &self, on_release: impl FnOnce(&mut T, &mut AppContext) + 'static, ) -> Subscription where @@ -110,7 +110,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { /// Register a callback to be run on the release of another model or view pub fn observe_release( - &mut self, + &self, entity: &E, on_release: impl FnOnce(&mut T, &mut T2, &mut ModelContext<'_, T>) + 'static, ) -> Subscription @@ -154,7 +154,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { /// Arrange for the given function to be invoked whenever the application is quit. /// The future returned from this callback will be polled for up to [crate::SHUTDOWN_TIMEOUT] until the app fully quits. pub fn on_app_quit( - &mut self, + &self, mut on_quit: impl FnMut(&mut T, &mut ModelContext) -> Fut + 'static, ) -> Subscription where diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 284e574627..d24c5d25da 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -1418,7 +1418,7 @@ impl Interactivity { } fn clamp_scroll_position( - &mut self, + &self, bounds: Bounds, style: &Style, cx: &mut WindowContext, @@ -1547,7 +1547,7 @@ impl Interactivity { #[cfg(debug_assertions)] fn paint_debug_info( - &mut self, + &self, global_id: Option<&GlobalElementId>, hitbox: &Hitbox, style: &Style, diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index 3fa142de96..56b551737a 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -252,7 +252,7 @@ impl TextLayout { } fn layout( - &mut self, + &self, text: SharedString, runs: Option>, cx: &mut WindowContext, @@ -350,7 +350,7 @@ impl TextLayout { layout_id } - fn prepaint(&mut self, bounds: Bounds, text: &str) { + fn prepaint(&self, bounds: Bounds, text: &str) { let mut element_state = self.lock(); let element_state = element_state .as_mut() @@ -359,7 +359,7 @@ impl TextLayout { element_state.bounds = Some(bounds); } - fn paint(&mut self, text: &str, cx: &mut WindowContext) { + fn paint(&self, text: &str, cx: &mut WindowContext) { let element_state = self.lock(); let element_state = element_state .as_ref() diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index d17d078184..b6fcf91e53 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -115,7 +115,7 @@ impl UniformListScrollHandle { } /// Scroll the list to the given item index. - pub fn scroll_to_item(&mut self, ix: usize) { + pub fn scroll_to_item(&self, ix: usize) { self.0.borrow_mut().deferred_scroll_to_item = Some(ix); } diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index 9b9b169804..9e0b9b9014 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -706,11 +706,7 @@ pub struct Bounds { impl Bounds { /// Generate a centered bounds for the given display or primary display if none is provided - pub fn centered( - display_id: Option, - size: Size, - cx: &mut AppContext, - ) -> Self { + pub fn centered(display_id: Option, size: Size, cx: &AppContext) -> Self { let display = display_id .and_then(|id| cx.find_display(id)) .or_else(|| cx.primary_display()); @@ -730,7 +726,7 @@ impl Bounds { } /// Generate maximized bounds for the given display or primary display if none is provided - pub fn maximized(display_id: Option, cx: &mut AppContext) -> Self { + pub fn maximized(display_id: Option, cx: &AppContext) -> Self { let display = display_id .and_then(|id| cx.find_display(id)) .or_else(|| cx.primary_display()); diff --git a/crates/gpui/src/key_dispatch.rs b/crates/gpui/src/key_dispatch.rs index d11b4b2cab..cb40a56367 100644 --- a/crates/gpui/src/key_dispatch.rs +++ b/crates/gpui/src/key_dispatch.rs @@ -219,7 +219,7 @@ impl DispatchTree { self.focusable_node_ids.insert(focus_id, node_id); } - pub fn parent_view_id(&mut self) -> Option { + pub fn parent_view_id(&self) -> Option { self.view_stack.last().copied() } @@ -484,7 +484,7 @@ impl DispatchTree { /// Converts the longest prefix of input to a replay event and returns the rest. fn replay_prefix( - &mut self, + &self, mut input: SmallVec<[Keystroke; 1]>, dispatch_path: &SmallVec<[DispatchNodeId; 32]>, ) -> (SmallVec<[Keystroke; 1]>, SmallVec<[Replay; 1]>) { diff --git a/crates/gpui/src/platform/app_menu.rs b/crates/gpui/src/platform/app_menu.rs index 15686956f2..401cc1899c 100644 --- a/crates/gpui/src/platform/app_menu.rs +++ b/crates/gpui/src/platform/app_menu.rs @@ -171,7 +171,7 @@ pub enum OsAction { Redo, } -pub(crate) fn init_app_menus(platform: &dyn Platform, cx: &mut AppContext) { +pub(crate) fn init_app_menus(platform: &dyn Platform, cx: &AppContext) { platform.on_will_open_app_menu(Box::new({ let cx = cx.to_async(); move || { diff --git a/crates/gpui/src/platform/mac/metal_renderer.rs b/crates/gpui/src/platform/mac/metal_renderer.rs index 401734e253..f42a2e2df7 100644 --- a/crates/gpui/src/platform/mac/metal_renderer.rs +++ b/crates/gpui/src/platform/mac/metal_renderer.rs @@ -284,11 +284,11 @@ impl MetalRenderer { } } - pub fn update_transparency(&mut self, _transparent: bool) { + pub fn update_transparency(&self, _transparent: bool) { // todo(mac)? } - pub fn destroy(&mut self) { + pub fn destroy(&self) { // nothing to do } @@ -486,7 +486,7 @@ impl MetalRenderer { } fn rasterize_paths( - &mut self, + &self, paths: &[Path], instance_buffer: &mut InstanceBuffer, instance_offset: &mut usize, @@ -576,7 +576,7 @@ impl MetalRenderer { } fn draw_shadows( - &mut self, + &self, shadows: &[Shadow], instance_buffer: &mut InstanceBuffer, instance_offset: &mut usize, @@ -639,7 +639,7 @@ impl MetalRenderer { } fn draw_quads( - &mut self, + &self, quads: &[Quad], instance_buffer: &mut InstanceBuffer, instance_offset: &mut usize, @@ -698,7 +698,7 @@ impl MetalRenderer { } fn draw_paths( - &mut self, + &self, paths: &[Path], tiles_by_path_id: &HashMap, instance_buffer: &mut InstanceBuffer, @@ -808,7 +808,7 @@ impl MetalRenderer { } fn draw_underlines( - &mut self, + &self, underlines: &[Underline], instance_buffer: &mut InstanceBuffer, instance_offset: &mut usize, @@ -871,7 +871,7 @@ impl MetalRenderer { } fn draw_monochrome_sprites( - &mut self, + &self, texture_id: AtlasTextureId, sprites: &[MonochromeSprite], instance_buffer: &mut InstanceBuffer, @@ -945,7 +945,7 @@ impl MetalRenderer { } fn draw_polychrome_sprites( - &mut self, + &self, texture_id: AtlasTextureId, sprites: &[PolychromeSprite], instance_buffer: &mut InstanceBuffer, diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index 5873d8fe39..50ef6dcf0f 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -1432,7 +1432,7 @@ impl UTType { self.0 } - fn inner_mut(&mut self) -> *mut Object { + fn inner_mut(&self) -> *mut Object { self.0 as *mut _ } } diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index af968c5a2c..98349f8c49 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -835,10 +835,7 @@ impl Window { prompt: None, }) } - fn new_focus_listener( - &mut self, - value: AnyWindowFocusListener, - ) -> (Subscription, impl FnOnce()) { + fn new_focus_listener(&self, value: AnyWindowFocusListener) -> (Subscription, impl FnOnce()) { self.focus_listeners.insert((), value) } } @@ -929,7 +926,7 @@ impl<'a> WindowContext<'a> { /// Obtain a new [`FocusHandle`], which allows you to track and manipulate the keyboard focus /// for elements rendered within this window. - pub fn focus_handle(&mut self) -> FocusHandle { + pub fn focus_handle(&self) -> FocusHandle { FocusHandle::new(&self.window.focus_handles) } @@ -1127,7 +1124,7 @@ impl<'a> WindowContext<'a> { /// Register a callback to be invoked when the given Model or View is released. pub fn observe_release( - &mut self, + &self, entity: &E, mut on_release: impl FnOnce(&mut T, &mut WindowContext) + 'static, ) -> Subscription @@ -1155,7 +1152,7 @@ impl<'a> WindowContext<'a> { } /// Schedule the given closure to be run directly after the current frame is rendered. - pub fn on_next_frame(&mut self, callback: impl FnOnce(&mut WindowContext) + 'static) { + pub fn on_next_frame(&self, callback: impl FnOnce(&mut WindowContext) + 'static) { RefCell::borrow_mut(&self.window.next_frame_callbacks).push(Box::new(callback)); } @@ -1165,7 +1162,7 @@ impl<'a> WindowContext<'a> { /// It will cause the window to redraw on the next frame, even if no other changes have occurred. /// /// If called from within a view, it will notify that view on the next frame. Otherwise, it will refresh the entire window. - pub fn request_animation_frame(&mut self) { + pub fn request_animation_frame(&self) { let parent_id = self.parent_view_id(); self.on_next_frame(move |cx| { if let Some(parent_id) = parent_id { @@ -1179,7 +1176,7 @@ impl<'a> WindowContext<'a> { /// Spawn the future returned by the given closure on the application thread pool. /// The closure is provided a handle to the current window and an `AsyncWindowContext` for /// use within your future. - pub fn spawn(&mut self, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task + pub fn spawn(&self, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task where R: 'static, Fut: Future + 'static, @@ -2865,7 +2862,7 @@ impl<'a> WindowContext<'a> { } /// Get the last view id for the current element - pub fn parent_view_id(&mut self) -> Option { + pub fn parent_view_id(&self) -> Option { self.window.next_frame.dispatch_tree.parent_view_id() } @@ -3606,7 +3603,7 @@ impl<'a> WindowContext<'a> { } /// Updates the IME panel position suggestions for languages like japanese, chinese. - pub fn invalidate_character_coordinates(&mut self) { + pub fn invalidate_character_coordinates(&self) { self.on_next_frame(|cx| { if let Some(mut input_handler) = cx.window.platform_window.take_input_handler() { if let Some(bounds) = input_handler.selected_bounds(cx) { @@ -3752,7 +3749,7 @@ impl<'a> WindowContext<'a> { /// Register a callback that can interrupt the closing of the current window based the returned boolean. /// If the callback returns false, the window won't be closed. - pub fn on_window_should_close(&mut self, f: impl Fn(&mut WindowContext) -> bool + 'static) { + pub fn on_window_should_close(&self, f: impl Fn(&mut WindowContext) -> bool + 'static) { let mut this = self.to_async(); self.window .platform_window @@ -4070,7 +4067,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { } /// Sets a given callback to be run on the next frame. - pub fn on_next_frame(&mut self, f: impl FnOnce(&mut V, &mut ViewContext) + 'static) + pub fn on_next_frame(&self, f: impl FnOnce(&mut V, &mut ViewContext) + 'static) where V: 'static, { @@ -4162,7 +4159,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// The callback receives a handle to the view's window. This handle may be /// invalid, if the window was closed before the view was released. pub fn on_release( - &mut self, + &self, on_release: impl FnOnce(&mut V, AnyWindowHandle, &mut AppContext) + 'static, ) -> Subscription { let window_handle = self.window.handle; @@ -4179,7 +4176,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// Register a callback to be invoked when the given Model or View is released. pub fn observe_release( - &mut self, + &self, entity: &E, mut on_release: impl FnMut(&mut V, &mut V2, &mut ViewContext<'_, V>) + 'static, ) -> Subscription @@ -4212,7 +4209,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// Register a callback to be invoked when the window is resized. pub fn observe_window_bounds( - &mut self, + &self, mut callback: impl FnMut(&mut V, &mut ViewContext) + 'static, ) -> Subscription { let view = self.view.downgrade(); @@ -4226,7 +4223,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// Register a callback to be invoked when the window is activated or deactivated. pub fn observe_window_activation( - &mut self, + &self, mut callback: impl FnMut(&mut V, &mut ViewContext) + 'static, ) -> Subscription { let view = self.view.downgrade(); @@ -4240,7 +4237,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// Registers a callback to be invoked when the window appearance changes. pub fn observe_window_appearance( - &mut self, + &self, mut callback: impl FnMut(&mut V, &mut ViewContext) + 'static, ) -> Subscription { let view = self.view.downgrade(); @@ -4260,7 +4257,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { mut f: impl FnMut(&mut V, &KeystrokeEvent, &mut ViewContext) + 'static, ) -> Subscription { fn inner( - keystroke_observers: &mut SubscriberSet<(), KeystrokeObserver>, + keystroke_observers: &SubscriberSet<(), KeystrokeObserver>, handler: KeystrokeObserver, ) -> Subscription { let (subscription, activate) = keystroke_observers.insert((), handler); @@ -4284,7 +4281,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// Register a callback to be invoked when the window's pending input changes. pub fn observe_pending_input( - &mut self, + &self, mut callback: impl FnMut(&mut V, &mut ViewContext) + 'static, ) -> Subscription { let view = self.view.downgrade(); @@ -4372,7 +4369,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// and this callback lets you chose a default place to restore the users focus. /// Returns a subscription and persists until the subscription is dropped. pub fn on_focus_lost( - &mut self, + &self, mut listener: impl FnMut(&mut V, &mut ViewContext) + 'static, ) -> Subscription { let view = self.view.downgrade(); @@ -4418,10 +4415,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { /// The given callback is invoked with a [`WeakView`] to avoid leaking the view for a long-running process. /// It's also given an [`AsyncWindowContext`], which can be used to access the state of the view across await points. /// The returned future will be polled on the main thread. - pub fn spawn( - &mut self, - f: impl FnOnce(WeakView, AsyncWindowContext) -> Fut, - ) -> Task + pub fn spawn(&self, f: impl FnOnce(WeakView, AsyncWindowContext) -> Fut) -> Task where R: 'static, Fut: Future + 'static, diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 1f4c56ecc8..4990b9074f 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -588,7 +588,7 @@ impl IndentGuide { impl Buffer { /// Create a new buffer with the given base text. - pub fn local>(base_text: T, cx: &mut ModelContext) -> Self { + pub fn local>(base_text: T, cx: &ModelContext) -> Self { Self::build( TextBuffer::new(0, cx.entity_id().as_non_zero_u64().into(), base_text.into()), None, @@ -601,7 +601,7 @@ impl Buffer { pub fn local_normalized( base_text_normalized: Rope, line_ending: LineEnding, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Self { Self::build( TextBuffer::new_normalized( @@ -934,7 +934,7 @@ impl Buffer { /// Assign a language registry to the buffer. This allows the buffer to retrieve /// other languages if parts of the buffer are written in different languages. - pub fn set_language_registry(&mut self, language_registry: Arc) { + pub fn set_language_registry(&self, language_registry: Arc) { self.syntax_map .lock() .set_language_registry(language_registry); @@ -967,16 +967,13 @@ impl Buffer { } /// This method is called to signal that the buffer has been discarded. - pub fn discarded(&mut self, cx: &mut ModelContext) { + pub fn discarded(&self, cx: &mut ModelContext) { cx.emit(BufferEvent::Discarded); cx.notify(); } /// Reloads the contents of the buffer from disk. - pub fn reload( - &mut self, - cx: &mut ModelContext, - ) -> oneshot::Receiver> { + pub fn reload(&mut self, cx: &ModelContext) -> oneshot::Receiver> { let (tx, rx) = futures::channel::oneshot::channel(); let prev_version = self.text.version(); self.reload_task = Some(cx.spawn(|this, mut cx| async move { @@ -1085,7 +1082,7 @@ impl Buffer { /// Sets the text that will be used to compute a Git diff /// against the buffer text. - pub fn set_diff_base(&mut self, diff_base: Option, cx: &mut ModelContext) { + pub fn set_diff_base(&mut self, diff_base: Option, cx: &ModelContext) { self.diff_base = diff_base.map(|mut raw_diff_base| { LineEnding::normalize(&mut raw_diff_base); BufferDiffBase::Git(Rope::from(raw_diff_base)) @@ -1117,7 +1114,7 @@ impl Buffer { } /// Recomputes the diff. - pub fn recalculate_diff(&mut self, cx: &mut ModelContext) -> Option> { + pub fn recalculate_diff(&self, cx: &ModelContext) -> Option> { let diff_base_rope = match self.diff_base.as_ref()? { BufferDiffBase::Git(rope) => rope.clone(), BufferDiffBase::PastBufferVersion { buffer, .. } => buffer.read(cx).as_rope().clone(), @@ -2249,12 +2246,7 @@ impl Buffer { } } - fn send_operation( - &mut self, - operation: Operation, - is_local: bool, - cx: &mut ModelContext, - ) { + fn send_operation(&self, operation: Operation, is_local: bool, cx: &mut ModelContext) { cx.emit(BufferEvent::Operation { operation, is_local, diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs index 7fff489540..47a0e03c2a 100644 --- a/crates/markdown/src/markdown.rs +++ b/crates/markdown/src/markdown.rs @@ -71,7 +71,7 @@ impl Markdown { source: String, style: MarkdownStyle, language_registry: Option>, - cx: &mut ViewContext, + cx: &ViewContext, fallback_code_block_language: Option, ) -> Self { let focus_handle = cx.focus_handle(); @@ -97,7 +97,7 @@ impl Markdown { source: String, style: MarkdownStyle, language_registry: Option>, - cx: &mut ViewContext, + cx: &ViewContext, fallback_code_block_language: Option, ) -> Self { let focus_handle = cx.focus_handle(); @@ -119,12 +119,12 @@ impl Markdown { this } - pub fn append(&mut self, text: &str, cx: &mut ViewContext) { + pub fn append(&mut self, text: &str, cx: &ViewContext) { self.source.push_str(text); self.parse(cx); } - pub fn reset(&mut self, source: String, cx: &mut ViewContext) { + pub fn reset(&mut self, source: String, cx: &ViewContext) { if source == self.source() { return; } @@ -145,7 +145,7 @@ impl Markdown { &self.parsed_markdown } - fn copy(&self, text: &RenderedText, cx: &mut ViewContext) { + fn copy(&self, text: &RenderedText, cx: &ViewContext) { if self.selection.end <= self.selection.start { return; } @@ -153,7 +153,7 @@ impl Markdown { cx.write_to_clipboard(ClipboardItem::new_string(text)); } - fn parse(&mut self, cx: &mut ViewContext) { + fn parse(&mut self, cx: &ViewContext) { if self.source.is_empty() { return; } @@ -319,7 +319,7 @@ impl MarkdownElement { } fn paint_selection( - &mut self, + &self, bounds: Bounds, rendered_text: &RenderedText, cx: &mut WindowContext, @@ -382,7 +382,7 @@ impl MarkdownElement { } fn paint_mouse_listeners( - &mut self, + &self, hitbox: &Hitbox, rendered_text: &RenderedText, cx: &mut WindowContext, @@ -487,7 +487,7 @@ impl MarkdownElement { }); } - fn autoscroll(&mut self, rendered_text: &RenderedText, cx: &mut WindowContext) -> Option<()> { + fn autoscroll(&self, rendered_text: &RenderedText, cx: &mut WindowContext) -> Option<()> { let autoscroll_index = self .markdown .update(cx, |markdown, _| markdown.autoscroll_request.take())?; diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 7aa733ba8f..18af28498f 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -515,7 +515,7 @@ impl MultiBuffer { } pub fn edit( - &mut self, + &self, edits: I, mut autoindent_mode: Option, cx: &mut ModelContext, @@ -664,7 +664,7 @@ impl MultiBuffer { drop(snapshot); // Non-generic part of edit, hoisted out to avoid blowing up LLVM IR. fn tail( - this: &mut MultiBuffer, + this: &MultiBuffer, buffer_edits: HashMap>, autoindent_mode: Option, edited_excerpt_ids: Vec, @@ -928,7 +928,7 @@ impl MultiBuffer { } } - pub fn push_transaction<'a, T>(&mut self, buffer_transactions: T, cx: &mut ModelContext) + pub fn push_transaction<'a, T>(&mut self, buffer_transactions: T, cx: &ModelContext) where T: IntoIterator, &'a language::Transaction)>, { @@ -952,7 +952,7 @@ impl MultiBuffer { } pub fn set_active_selections( - &mut self, + &self, selections: &[Selection], line_mode: bool, cursor_shape: CursorShape, @@ -1028,7 +1028,7 @@ impl MultiBuffer { } } - pub fn remove_active_selections(&mut self, cx: &mut ModelContext) { + pub fn remove_active_selections(&self, cx: &mut ModelContext) { for buffer in self.buffers.borrow().values() { buffer .buffer @@ -1180,7 +1180,7 @@ impl MultiBuffer { } pub fn push_multiple_excerpts_with_context_lines( - &mut self, + &self, buffers_with_ranges: Vec<(Model, Vec>)>, context_line_count: u32, cx: &mut ModelContext, @@ -4208,7 +4208,7 @@ impl History { &mut self, buffer_transactions: T, now: Instant, - cx: &mut ModelContext, + cx: &ModelContext, ) where T: IntoIterator, &'a language::Transaction)>, { diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index 87150587b3..e956f67260 100644 --- a/crates/project/src/project_settings.rs +++ b/crates/project/src/project_settings.rs @@ -321,7 +321,7 @@ impl SettingsObserver { pub async fn handle_update_user_settings( _: Model, envelope: TypedEnvelope, - mut cx: AsyncAppContext, + cx: AsyncAppContext, ) -> anyhow::Result<()> { cx.update_global(move |settings_store: &mut SettingsStore, cx| { settings_store.set_user_settings(&envelope.payload.content, cx) diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index 89ec5db949..32d5536b32 100644 --- a/crates/remote/src/ssh_session.rs +++ b/crates/remote/src/ssh_session.rs @@ -188,7 +188,7 @@ impl ChannelForwarder { fn new( mut incoming_tx: UnboundedSender, mut outgoing_rx: UnboundedReceiver, - cx: &mut AsyncAppContext, + cx: &AsyncAppContext, ) -> (Self, UnboundedSender, UnboundedReceiver) { let (quit_tx, mut quit_rx) = mpsc::unbounded::<()>(); @@ -298,7 +298,7 @@ impl SshRemoteClient { Ok(this) } - fn reconnect(this: Arc, cx: &mut AsyncAppContext) -> Result<()> { + fn reconnect(this: Arc, cx: &AsyncAppContext) -> Result<()> { let Some(state) = this.inner_state.lock().take() else { return Err(anyhow!("reconnect is already in progress")); }; @@ -355,7 +355,7 @@ impl SshRemoteClient { mut ssh_process: Child, incoming_tx: UnboundedSender, mut outgoing_rx: UnboundedReceiver, - cx: &mut AsyncAppContext, + cx: &AsyncAppContext, ) -> Task> { let mut child_stderr = ssh_process.stderr.take().unwrap(); let mut child_stdout = ssh_process.stdout.take().unwrap(); diff --git a/crates/session/src/session.rs b/crates/session/src/session.rs index 01646b6f7a..47b4a2e181 100644 --- a/crates/session/src/session.rs +++ b/crates/session/src/session.rs @@ -64,7 +64,7 @@ pub struct AppSession { } impl AppSession { - pub fn new(session: Session, cx: &mut ModelContext) -> Self { + pub fn new(session: Session, cx: &ModelContext) -> Self { let _subscriptions = vec![cx.on_app_quit(Self::app_will_quit)]; let _serialization_task = Some(cx.spawn(|_, cx| async move { diff --git a/crates/settings/src/settings_file.rs b/crates/settings/src/settings_file.rs index 823b75ef42..2c46732fbc 100644 --- a/crates/settings/src/settings_file.rs +++ b/crates/settings/src/settings_file.rs @@ -77,7 +77,7 @@ pub fn handle_settings_file_changes( .set_user_settings(&user_settings_content, cx) .log_err(); }); - cx.spawn(move |mut cx| async move { + cx.spawn(move |cx| async move { while let Some(user_settings_content) = user_settings_file_rx.next().await { let result = cx.update_global(|store: &mut SettingsStore, cx| { let result = store.set_user_settings(&user_settings_content, cx); diff --git a/crates/snippet_provider/src/lib.rs b/crates/snippet_provider/src/lib.rs index a18f9ff1b6..17d60d25a0 100644 --- a/crates/snippet_provider/src/lib.rs +++ b/crates/snippet_provider/src/lib.rs @@ -179,7 +179,7 @@ impl SnippetProvider { } /// Add directory to be watched for content changes - fn watch_directory(&mut self, path: &Path, cx: &mut ModelContext) { + fn watch_directory(&mut self, path: &Path, cx: &ModelContext) { let path: Arc = Arc::from(path); self.watch_tasks.push(cx.spawn(|this, mut cx| async move { diff --git a/crates/task/src/static_source.rs b/crates/task/src/static_source.rs index 3ae9ee0b70..48f8fdfa01 100644 --- a/crates/task/src/static_source.rs +++ b/crates/task/src/static_source.rs @@ -27,7 +27,7 @@ impl TrackedFile { pub fn new( mut tracker: UnboundedReceiver, notification_outlet: UnboundedSender<()>, - cx: &mut AppContext, + cx: &AppContext, ) -> Self where T: for<'a> Deserialize<'a> + Default + Send, @@ -69,7 +69,7 @@ impl TrackedFile { pub fn new_convertible Deserialize<'a> + TryInto>( mut tracker: UnboundedReceiver, notification_outlet: UnboundedSender<()>, - cx: &mut AppContext, + cx: &AppContext, ) -> Self where T: Default + Send, diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index b51308df37..9412999cbf 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -320,7 +320,7 @@ impl TerminalBuilder { max_scroll_history_lines: Option, window: AnyWindowHandle, completion_tx: Sender<()>, - cx: &mut AppContext, + cx: &AppContext, ) -> Result { // TODO: Properly set the current locale, env.entry("LC_ALL".to_string()) @@ -455,7 +455,7 @@ impl TerminalBuilder { }) } - pub fn subscribe(mut self, cx: &mut ModelContext) -> Terminal { + pub fn subscribe(mut self, cx: &ModelContext) -> Terminal { //Event loop cx.spawn(|terminal, mut cx| async move { while let Some(event) = self.events_rx.next().await { @@ -1280,7 +1280,7 @@ impl Terminal { } } - fn drag_line_delta(&mut self, e: &MouseMoveEvent, region: Bounds) -> Option { + fn drag_line_delta(&self, e: &MouseMoveEvent, region: Bounds) -> Option { //TODO: Why do these need to be doubled? Probably the same problem that the IME has let top = region.origin.y + (self.last_content.size.line_height * 2.); let bottom = region.lower_left().y - (self.last_content.size.line_height * 2.); @@ -1351,12 +1351,7 @@ impl Terminal { } } - pub fn mouse_up( - &mut self, - e: &MouseUpEvent, - origin: Point, - cx: &mut ModelContext, - ) { + pub fn mouse_up(&mut self, e: &MouseUpEvent, origin: Point, cx: &ModelContext) { let setting = TerminalSettings::get_global(cx); let position = e.position - origin; @@ -1458,9 +1453,9 @@ impl Terminal { } pub fn find_matches( - &mut self, + &self, mut searcher: RegexSearch, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { let term = self.term.clone(); cx.background_executor().spawn(async move { @@ -1530,7 +1525,7 @@ impl Terminal { self.task.as_ref() } - pub fn wait_for_completed_task(&self, cx: &mut AppContext) -> Task<()> { + pub fn wait_for_completed_task(&self, cx: &AppContext) -> Task<()> { if let Some(task) = self.task() { if task.status == TaskStatus::Running { let mut completion_receiver = task.completion_rx.clone(); diff --git a/crates/theme/src/registry.rs b/crates/theme/src/registry.rs index 771511973f..9f95d19937 100644 --- a/crates/theme/src/registry.rs +++ b/crates/theme/src/registry.rs @@ -189,7 +189,7 @@ impl ThemeRegistry { } /// Removes all themes from the registry. - pub fn clear(&mut self) { + pub fn clear(&self) { self.state.write().themes.clear(); } diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index d126ec058c..e4be957a1b 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -498,7 +498,7 @@ pub fn observe_buffer_font_size_adjustment( } /// Sets the adjusted buffer font size. -pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels { +pub fn adjusted_font_size(size: Pixels, cx: &AppContext) -> Pixels { if let Some(AdjustedBufferFontSize(adjusted_size)) = cx.try_global::() { let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size; let delta = *adjusted_size - buffer_font_size; @@ -530,7 +530,7 @@ pub fn adjust_buffer_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) { } /// Returns whether the buffer font size has been adjusted. -pub fn has_adjusted_buffer_font_size(cx: &mut AppContext) -> bool { +pub fn has_adjusted_buffer_font_size(cx: &AppContext) -> bool { cx.has_global::() } @@ -576,7 +576,7 @@ pub fn adjust_ui_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) { } /// Returns whether the UI font size has been adjusted. -pub fn has_adjusted_ui_font_size(cx: &mut AppContext) -> bool { +pub fn has_adjusted_ui_font_size(cx: &AppContext) -> bool { cx.has_global::() } diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 40cd465d9b..3a5ba2c276 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -622,7 +622,7 @@ impl Worktree { } } - pub fn root_file(&self, cx: &mut ModelContext) -> Option> { + pub fn root_file(&self, cx: &ModelContext) -> Option> { let entry = self.root_entry()?; Some(File::for_entry(entry.clone(), cx.handle())) } @@ -630,7 +630,7 @@ impl Worktree { pub fn observe_updates( &mut self, project_id: u64, - cx: &mut ModelContext, + cx: &ModelContext, callback: F, ) where F: 'static + Send + Fn(proto::UpdateWorktree) -> Fut, @@ -661,11 +661,7 @@ impl Worktree { } } - pub fn load_file( - &self, - path: &Path, - cx: &mut ModelContext, - ) -> Task> { + pub fn load_file(&self, path: &Path, cx: &ModelContext) -> Task> { match self { Worktree::Local(this) => this.load_file(path, cx), Worktree::Remote(_) => { @@ -679,7 +675,7 @@ impl Worktree { path: &Path, text: Rope, line_ending: LineEnding, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { match self { Worktree::Local(this) => this.write_file(path, text, line_ending, cx), @@ -693,7 +689,7 @@ impl Worktree { &mut self, path: impl Into>, is_directory: bool, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let path = path.into(); let worktree_id = self.id(); @@ -773,7 +769,7 @@ impl Worktree { &mut self, entry_id: ProjectEntryId, new_path: impl Into>, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let new_path = new_path.into(); match self { @@ -787,7 +783,7 @@ impl Worktree { entry_id: ProjectEntryId, relative_worktree_source_path: Option, new_path: impl Into>, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { let new_path = new_path.into(); match self { @@ -830,7 +826,7 @@ impl Worktree { target_directory: PathBuf, paths: Vec>, overwrite_existing_files: bool, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { match self { Worktree::Local(this) => { @@ -845,7 +841,7 @@ impl Worktree { pub fn expand_entry( &mut self, entry_id: ProjectEntryId, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Option>> { match self { Worktree::Local(this) => this.expand_entry(entry_id, cx), @@ -987,7 +983,7 @@ impl LocalWorktree { !self.share_private_files && self.settings.is_path_private(path) } - fn restart_background_scanners(&mut self, cx: &mut ModelContext) { + fn restart_background_scanners(&mut self, cx: &ModelContext) { let (scan_requests_tx, scan_requests_rx) = channel::unbounded(); let (path_prefixes_to_scan_tx, path_prefixes_to_scan_rx) = channel::unbounded(); self.scan_requests_tx = scan_requests_tx; @@ -999,7 +995,7 @@ impl LocalWorktree { &mut self, scan_requests_rx: channel::Receiver, path_prefixes_to_scan_rx: channel::Receiver>, - cx: &mut ModelContext, + cx: &ModelContext, ) { let snapshot = self.snapshot(); let share_private_files = self.share_private_files; @@ -1236,7 +1232,7 @@ impl LocalWorktree { self.git_repositories.get(&repo.work_directory.0) } - fn load_file(&self, path: &Path, cx: &mut ModelContext) -> Task> { + fn load_file(&self, path: &Path, cx: &ModelContext) -> Task> { let path = Arc::from(path); let abs_path = self.absolutize(&path); let fs = self.fs.clone(); @@ -1318,7 +1314,7 @@ impl LocalWorktree { &self, path: impl Into>, is_dir: bool, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let path = path.into(); let abs_path = match self.absolutize(&path) { @@ -1383,7 +1379,7 @@ impl LocalWorktree { path: impl Into>, text: Rope, line_ending: LineEnding, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { let path = path.into(); let fs = self.fs.clone(); @@ -1437,7 +1433,7 @@ impl LocalWorktree { &self, entry_id: ProjectEntryId, trash: bool, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Option>> { let entry = self.entry_for_id(entry_id)?.clone(); let abs_path = self.absolutize(&entry.path); @@ -1489,7 +1485,7 @@ impl LocalWorktree { &self, entry_id: ProjectEntryId, new_path: impl Into>, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let old_path = match self.entry_for_id(entry_id) { Some(entry) => entry.path.clone(), @@ -1547,7 +1543,7 @@ impl LocalWorktree { entry_id: ProjectEntryId, relative_worktree_source_path: Option, new_path: impl Into>, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { let old_path = match self.entry_for_id(entry_id) { Some(entry) => entry.path.clone(), @@ -1584,11 +1580,11 @@ impl LocalWorktree { } pub fn copy_external_entries( - &mut self, + &self, target_directory: PathBuf, paths: Vec>, overwrite_existing_files: bool, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { let worktree_path = self.abs_path().clone(); let fs = self.fs.clone(); @@ -1665,9 +1661,9 @@ impl LocalWorktree { } fn expand_entry( - &mut self, + &self, entry_id: ProjectEntryId, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Option>> { let path = self.entry_for_id(entry_id)?.path.clone(); let mut refresh = self.refresh_entries_for_paths(vec![path]); @@ -1696,7 +1692,7 @@ impl LocalWorktree { &self, path: Arc, old_path: Option>, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task>> { if self.settings.is_path_excluded(&path) { return Task::ready(Ok(None)); @@ -1720,12 +1716,8 @@ impl LocalWorktree { }) } - fn observe_updates( - &mut self, - project_id: u64, - cx: &mut ModelContext, - callback: F, - ) where + fn observe_updates(&mut self, project_id: u64, cx: &ModelContext, callback: F) + where F: 'static + Send + Fn(proto::UpdateWorktree) -> Fut, Fut: Send + Future, { @@ -1784,7 +1776,7 @@ impl LocalWorktree { }); } - pub fn share_private_files(&mut self, cx: &mut ModelContext) { + pub fn share_private_files(&mut self, cx: &ModelContext) { self.share_private_files = true; self.restart_background_scanners(cx); } @@ -1805,7 +1797,7 @@ impl RemoteWorktree { self.disconnected = true; } - pub fn update_from_remote(&mut self, update: proto::UpdateWorktree) { + pub fn update_from_remote(&self, update: proto::UpdateWorktree) { if let Some(updates_tx) = &self.updates_tx { updates_tx .unbounded_send(update) @@ -1813,12 +1805,8 @@ impl RemoteWorktree { } } - fn observe_updates( - &mut self, - project_id: u64, - cx: &mut ModelContext, - callback: F, - ) where + fn observe_updates(&mut self, project_id: u64, cx: &ModelContext, callback: F) + where F: 'static + Send + Fn(proto::UpdateWorktree) -> Fut, Fut: 'static + Send + Future, { @@ -1879,7 +1867,7 @@ impl RemoteWorktree { &mut self, entry: proto::Entry, scan_id: usize, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let wait_for_snapshot = self.wait_for_snapshot(scan_id); cx.spawn(|this, mut cx| async move { @@ -1895,10 +1883,10 @@ impl RemoteWorktree { } fn delete_entry( - &mut self, + &self, entry_id: ProjectEntryId, trash: bool, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Option>> { let response = self.client.request(proto::DeleteProjectEntry { project_id: self.project_id, @@ -1924,10 +1912,10 @@ impl RemoteWorktree { } fn rename_entry( - &mut self, + &self, entry_id: ProjectEntryId, new_path: impl Into>, - cx: &mut ModelContext, + cx: &ModelContext, ) -> Task> { let new_path = new_path.into(); let response = self.client.request(proto::RenameProjectEntry { @@ -3692,7 +3680,7 @@ impl BackgroundScanner { self.send_status_update(scanning, request.done) } - async fn process_events(&mut self, mut abs_paths: Vec) { + async fn process_events(&self, mut abs_paths: Vec) { let root_path = self.state.lock().snapshot.abs_path.clone(); let root_canonical_path = match self.fs.canonicalize(&root_path).await { Ok(path) => path, diff --git a/crates/zed/src/reliability.rs b/crates/zed/src/reliability.rs index b40bbc78bd..9d76a6c47f 100644 --- a/crates/zed/src/reliability.rs +++ b/crates/zed/src/reliability.rs @@ -347,7 +347,7 @@ pub fn monitor_main_thread_hangs( fn upload_panics_and_crashes( http: Arc, installation_id: Option, - cx: &mut AppContext, + cx: &AppContext, ) { let telemetry_settings = *client::TelemetrySettings::get_global(cx); cx.background_executor() diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 4dc378a755..eb60ab9fa8 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -573,7 +573,7 @@ fn feature_gate_zed_pro_actions(cx: &mut AppContext) { .detach(); } -fn initialize_pane(workspace: &mut Workspace, pane: &View, cx: &mut ViewContext) { +fn initialize_pane(workspace: &Workspace, pane: &View, cx: &mut ViewContext) { pane.update(cx, |pane, cx| { pane.toolbar().update(cx, |toolbar, cx| { let multibuffer_hint = cx.new_view(|_| MultibufferHint::new()); @@ -981,7 +981,7 @@ fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext, title: &'static str, language: &'static str, diff --git a/crates/zed/src/zed/inline_completion_registry.rs b/crates/zed/src/zed/inline_completion_registry.rs index ff84297b58..aa0707d851 100644 --- a/crates/zed/src/zed/inline_completion_registry.rs +++ b/crates/zed/src/zed/inline_completion_registry.rs @@ -64,7 +64,7 @@ pub fn init(telemetry: Arc, cx: &mut AppContext) { .detach(); } -fn register_backward_compatible_actions(editor: &mut Editor, cx: &mut ViewContext) { +fn register_backward_compatible_actions(editor: &mut Editor, cx: &ViewContext) { // We renamed some of these actions to not be copilot-specific, but that // would have not been backwards-compatible. So here we are re-registering // the actions with the old names to not break people's keymaps. diff --git a/crates/zed/src/zed/open_listener.rs b/crates/zed/src/zed/open_listener.rs index c5fd2b2e78..7746337df1 100644 --- a/crates/zed/src/zed/open_listener.rs +++ b/crates/zed/src/zed/open_listener.rs @@ -661,7 +661,7 @@ mod tests { path: &str, open_new_workspace: Option, app_state: Arc, - cx: &mut TestAppContext, + cx: &TestAppContext, ) { let (response_tx, _) = ipc::channel::().unwrap();