diff --git a/crates/call2/src/call2.rs b/crates/call2/src/call2.rs index ffa2e5e9dc6072a543aff43eec5d2582992d2144..d8678b7ed46d155ece9373a161bd59b0322e7bce 100644 --- a/crates/call2/src/call2.rs +++ b/crates/call2/src/call2.rs @@ -13,7 +13,7 @@ use collections::HashSet; use futures::{future::Shared, FutureExt}; use gpui2::{ AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Subscription, Task, - WeakHandle, + WeakModel, }; use postage::watch; use project2::Project; @@ -42,7 +42,7 @@ pub struct IncomingCall { pub struct ActiveCall { room: Option<(Model, Vec)>, pending_room_creation: Option, Arc>>>>, - location: Option>, + location: Option>, pending_invites: HashSet, incoming_call: ( watch::Sender>, @@ -347,7 +347,7 @@ impl ActiveCall { } } - pub fn location(&self) -> Option<&WeakHandle> { + pub fn location(&self) -> Option<&WeakModel> { self.location.as_ref() } diff --git a/crates/call2/src/participant.rs b/crates/call2/src/participant.rs index c5c873a78aa277d045b04da7571e5c9948677c10..7f3e91dbba0116a7b7f7ef5b1c471fb1a768529f 100644 --- a/crates/call2/src/participant.rs +++ b/crates/call2/src/participant.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Result}; use client2::ParticipantIndex; use client2::{proto, User}; -use gpui2::WeakHandle; +use gpui2::WeakModel; pub use live_kit_client::Frame; use project2::Project; use std::{fmt, sync::Arc}; @@ -33,7 +33,7 @@ impl ParticipantLocation { #[derive(Clone, Default)] pub struct LocalParticipant { pub projects: Vec, - pub active_project: Option>, + pub active_project: Option>, } #[derive(Clone, Debug)] diff --git a/crates/call2/src/room.rs b/crates/call2/src/room.rs index 07873c4cd5887bd39cd48b2a48c29cac7fb9dc54..7f51c64d4b62ff4371dab4bffc36196b28843362 100644 --- a/crates/call2/src/room.rs +++ b/crates/call2/src/room.rs @@ -16,7 +16,7 @@ use collections::{BTreeMap, HashMap, HashSet}; use fs::Fs; use futures::{FutureExt, StreamExt}; use gpui2::{ - AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakHandle, + AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel, }; use language2::LanguageRegistry; use live_kit_client::{LocalTrackPublication, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate}; @@ -61,8 +61,8 @@ pub struct Room { channel_id: Option, // live_kit: Option, status: RoomStatus, - shared_projects: HashSet>, - joined_projects: HashSet>, + shared_projects: HashSet>, + joined_projects: HashSet>, local_participant: LocalParticipant, remote_participants: BTreeMap, pending_participants: Vec>, @@ -424,7 +424,7 @@ impl Room { } async fn maintain_connection( - this: WeakHandle, + this: WeakModel, client: Arc, mut cx: AsyncAppContext, ) -> Result<()> { diff --git a/crates/client2/src/client2.rs b/crates/client2/src/client2.rs index dcea6ded4e61beb60ca22dd644b0fd216a3facac..19e8685c28cd55094b064ea0af60bbd6744fa475 100644 --- a/crates/client2/src/client2.rs +++ b/crates/client2/src/client2.rs @@ -14,8 +14,8 @@ use futures::{ future::BoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamExt, TryFutureExt as _, TryStreamExt, }; use gpui2::{ - serde_json, AnyHandle, AnyWeakHandle, AppContext, AsyncAppContext, Model, SemanticVersion, - Task, WeakHandle, + serde_json, AnyModel, AnyWeakModel, AppContext, AsyncAppContext, Model, SemanticVersion, Task, + WeakModel, }; use lazy_static::lazy_static; use parking_lot::RwLock; @@ -227,7 +227,7 @@ struct ClientState { _reconnect_task: Option>, reconnect_interval: Duration, entities_by_type_and_remote_id: HashMap<(TypeId, u64), WeakSubscriber>, - models_by_message_type: HashMap, + models_by_message_type: HashMap, entity_types_by_message_type: HashMap, #[allow(clippy::type_complexity)] message_handlers: HashMap< @@ -236,7 +236,7 @@ struct ClientState { dyn Send + Sync + Fn( - AnyHandle, + AnyModel, Box, &Arc, AsyncAppContext, @@ -246,7 +246,7 @@ struct ClientState { } enum WeakSubscriber { - Entity { handle: AnyWeakHandle }, + Entity { handle: AnyWeakModel }, Pending(Vec>), } @@ -552,7 +552,7 @@ impl Client { #[track_caller] pub fn add_message_handler( self: &Arc, - entity: WeakHandle, + entity: WeakModel, handler: H, ) -> Subscription where @@ -594,7 +594,7 @@ impl Client { pub fn add_request_handler( self: &Arc, - model: WeakHandle, + model: WeakModel, handler: H, ) -> Subscription where @@ -628,7 +628,7 @@ impl Client { where M: EntityMessage, E: 'static + Send, - H: 'static + Send + Sync + Fn(AnyHandle, TypedEnvelope, Arc, AsyncAppContext) -> F, + H: 'static + Send + Sync + Fn(AnyModel, TypedEnvelope, Arc, AsyncAppContext) -> F, F: 'static + Future> + Send, { let model_type_id = TypeId::of::(); diff --git a/crates/copilot2/src/copilot2.rs b/crates/copilot2/src/copilot2.rs index 42b0e3aa41ad154b6b88fa494a2132aa35ba2c97..c3107a2f4731897199eb80677f5bc8857c7beb39 100644 --- a/crates/copilot2/src/copilot2.rs +++ b/crates/copilot2/src/copilot2.rs @@ -8,7 +8,7 @@ use collections::{HashMap, HashSet}; use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt}; use gpui2::{ AppContext, AsyncAppContext, Context, EntityId, EventEmitter, Model, ModelContext, Task, - WeakHandle, + WeakModel, }; use language2::{ language_settings::{all_language_settings, language_settings}, @@ -278,7 +278,7 @@ pub struct Copilot { http: Arc, node_runtime: Arc, server: CopilotServer, - buffers: HashSet>, + buffers: HashSet>, server_id: LanguageServerId, _subscription: gpui2::Subscription, } @@ -383,7 +383,7 @@ impl Copilot { new_server_id: LanguageServerId, http: Arc, node_runtime: Arc, - this: WeakHandle, + this: WeakModel, mut cx: AsyncAppContext, ) -> impl Future { async move { @@ -706,7 +706,7 @@ impl Copilot { Ok(()) } - fn unregister_buffer(&mut self, buffer: &WeakHandle) { + fn unregister_buffer(&mut self, buffer: &WeakModel) { if let Ok(server) = self.server.as_running() { if let Some(buffer) = server.registered_buffers.remove(&buffer.entity_id()) { server diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index c4ba6a472486106fbefa6d0d61625b2aa9d8331f..0a09bb2ff834bfb71d784d6a537c4772d1eb37aa 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -711,7 +711,7 @@ impl Context for AppContext { type Result = T; /// Build an entity that is owned by the application. The given function will be invoked with - /// a `ModelContext` and must return an object representing the entity. A `Handle` will be returned + /// a `ModelContext` and must return an object representing the entity. A `Model` will be returned /// which can be used to access the entity in a context. fn build_model( &mut self, @@ -724,18 +724,18 @@ impl Context for AppContext { }) } - /// Update the entity referenced by the given handle. The function is passed a mutable reference to the + /// Update the entity referenced by the given model. The function is passed a mutable reference to the /// entity along with a `ModelContext` for the entity. fn update_entity( &mut self, - handle: &Model, + model: &Model, update: impl FnOnce(&mut T, &mut Self::ModelContext<'_, T>) -> R, ) -> R { self.update(|cx| { - let mut entity = cx.entities.lease(handle); + let mut entity = cx.entities.lease(model); let result = update( &mut entity, - &mut ModelContext::mutable(cx, handle.downgrade()), + &mut ModelContext::mutable(cx, model.downgrade()), ); cx.entities.end_lease(entity); result diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index 68f0a8fa484b6f25caffb607214e3f70462ab907..bfd457e4fff4df1d6a8e8f4a78b9a76f6cf26e58 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -61,21 +61,21 @@ impl EntityMap { where T: 'static + Send, { - let handle = slot.0; - self.entities.insert(handle.entity_id, Box::new(entity)); - handle + let model = slot.0; + self.entities.insert(model.entity_id, Box::new(entity)); + model } /// Move an entity to the stack. - pub fn lease<'a, T>(&mut self, handle: &'a Model) -> Lease<'a, T> { - self.assert_valid_context(handle); + pub fn lease<'a, T>(&mut self, model: &'a Model) -> Lease<'a, T> { + self.assert_valid_context(model); let entity = Some( self.entities - .remove(handle.entity_id) + .remove(model.entity_id) .expect("Circular entity lease. Is the entity already being updated?"), ); Lease { - handle, + model, entity, entity_type: PhantomData, } @@ -84,18 +84,18 @@ impl EntityMap { /// Return an entity after moving it to the stack. pub fn end_lease(&mut self, mut lease: Lease) { self.entities - .insert(lease.handle.entity_id, lease.entity.take().unwrap()); + .insert(lease.model.entity_id, lease.entity.take().unwrap()); } - pub fn read(&self, handle: &Model) -> &T { - self.assert_valid_context(handle); - self.entities[handle.entity_id].downcast_ref().unwrap() + pub fn read(&self, model: &Model) -> &T { + self.assert_valid_context(model); + self.entities[model.entity_id].downcast_ref().unwrap() } - fn assert_valid_context(&self, handle: &AnyHandle) { + fn assert_valid_context(&self, model: &AnyModel) { debug_assert!( - Weak::ptr_eq(&handle.entity_map, &Arc::downgrade(&self.ref_counts)), - "used a handle with the wrong context" + Weak::ptr_eq(&model.entity_map, &Arc::downgrade(&self.ref_counts)), + "used a model with the wrong context" ); } @@ -115,7 +115,7 @@ impl EntityMap { pub struct Lease<'a, T> { entity: Option, - pub handle: &'a Model, + pub model: &'a Model, entity_type: PhantomData, } @@ -145,13 +145,13 @@ impl<'a, T> Drop for Lease<'a, T> { #[derive(Deref, DerefMut)] pub struct Slot(Model); -pub struct AnyHandle { +pub struct AnyModel { pub(crate) entity_id: EntityId, entity_type: TypeId, entity_map: Weak>, } -impl AnyHandle { +impl AnyModel { fn new(id: EntityId, entity_type: TypeId, entity_map: Weak>) -> Self { Self { entity_id: id, @@ -164,8 +164,8 @@ impl AnyHandle { self.entity_id } - pub fn downgrade(&self) -> AnyWeakHandle { - AnyWeakHandle { + pub fn downgrade(&self) -> AnyWeakModel { + AnyWeakModel { entity_id: self.entity_id, entity_type: self.entity_type, entity_ref_counts: self.entity_map.clone(), @@ -175,7 +175,7 @@ impl AnyHandle { pub fn downcast(&self) -> Option> { if TypeId::of::() == self.entity_type { Some(Model { - any_handle: self.clone(), + any_model: self.clone(), entity_type: PhantomData, }) } else { @@ -184,16 +184,16 @@ impl AnyHandle { } } -impl Clone for AnyHandle { +impl Clone for AnyModel { fn clone(&self) -> Self { if let Some(entity_map) = self.entity_map.upgrade() { let entity_map = entity_map.read(); let count = entity_map .counts .get(self.entity_id) - .expect("detected over-release of a handle"); + .expect("detected over-release of a model"); let prev_count = count.fetch_add(1, SeqCst); - assert_ne!(prev_count, 0, "Detected over-release of a handle."); + assert_ne!(prev_count, 0, "Detected over-release of a model."); } Self { @@ -204,16 +204,16 @@ impl Clone for AnyHandle { } } -impl Drop for AnyHandle { +impl Drop for AnyModel { fn drop(&mut self) { if let Some(entity_map) = self.entity_map.upgrade() { let entity_map = entity_map.upgradable_read(); let count = entity_map .counts .get(self.entity_id) - .expect("Detected over-release of a handle."); + .expect("Detected over-release of a model."); let prev_count = count.fetch_sub(1, SeqCst); - assert_ne!(prev_count, 0, "Detected over-release of a handle."); + assert_ne!(prev_count, 0, "Detected over-release of a model."); if prev_count == 1 { // We were the last reference to this entity, so we can remove it. let mut entity_map = RwLockUpgradableReadGuard::upgrade(entity_map); @@ -223,31 +223,31 @@ impl Drop for AnyHandle { } } -impl From> for AnyHandle { - fn from(handle: Model) -> Self { - handle.any_handle +impl From> for AnyModel { + fn from(model: Model) -> Self { + model.any_model } } -impl Hash for AnyHandle { +impl Hash for AnyModel { fn hash(&self, state: &mut H) { self.entity_id.hash(state); } } -impl PartialEq for AnyHandle { +impl PartialEq for AnyModel { fn eq(&self, other: &Self) -> bool { self.entity_id == other.entity_id } } -impl Eq for AnyHandle {} +impl Eq for AnyModel {} #[derive(Deref, DerefMut)] pub struct Model { #[deref] #[deref_mut] - any_handle: AnyHandle, + any_model: AnyModel, entity_type: PhantomData, } @@ -260,14 +260,14 @@ impl Model { T: 'static, { Self { - any_handle: AnyHandle::new(id, TypeId::of::(), entity_map), + any_model: AnyModel::new(id, TypeId::of::(), entity_map), entity_type: PhantomData, } } - pub fn downgrade(&self) -> WeakHandle { - WeakHandle { - any_handle: self.any_handle.downgrade(), + pub fn downgrade(&self) -> WeakModel { + WeakModel { + any_model: self.any_model.downgrade(), entity_type: self.entity_type, } } @@ -276,7 +276,7 @@ impl Model { cx.entities.read(self) } - /// Update the entity referenced by this handle with the given function. + /// Update the entity referenced by this model with the given function. /// /// The update function receives a context appropriate for its environment. /// When updating in an `AppContext`, it receives a `ModelContext`. @@ -296,7 +296,7 @@ impl Model { impl Clone for Model { fn clone(&self) -> Self { Self { - any_handle: self.any_handle.clone(), + any_model: self.any_model.clone(), entity_type: self.entity_type, } } @@ -306,8 +306,8 @@ impl std::fmt::Debug for Model { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "Handle {{ entity_id: {:?}, entity_type: {:?} }}", - self.any_handle.entity_id, + "Model {{ entity_id: {:?}, entity_type: {:?} }}", + self.any_model.entity_id, type_name::() ) } @@ -315,32 +315,32 @@ impl std::fmt::Debug for Model { impl Hash for Model { fn hash(&self, state: &mut H) { - self.any_handle.hash(state); + self.any_model.hash(state); } } impl PartialEq for Model { fn eq(&self, other: &Self) -> bool { - self.any_handle == other.any_handle + self.any_model == other.any_model } } impl Eq for Model {} -impl PartialEq> for Model { - fn eq(&self, other: &WeakHandle) -> bool { +impl PartialEq> for Model { + fn eq(&self, other: &WeakModel) -> bool { self.entity_id() == other.entity_id() } } #[derive(Clone)] -pub struct AnyWeakHandle { +pub struct AnyWeakModel { pub(crate) entity_id: EntityId, entity_type: TypeId, entity_ref_counts: Weak>, } -impl AnyWeakHandle { +impl AnyWeakModel { pub fn entity_id(&self) -> EntityId { self.entity_id } @@ -354,14 +354,14 @@ impl AnyWeakHandle { ref_count > 0 } - pub fn upgrade(&self) -> Option { + pub fn upgrade(&self) -> Option { let entity_map = self.entity_ref_counts.upgrade()?; entity_map .read() .counts .get(self.entity_id)? .fetch_add(1, SeqCst); - Some(AnyHandle { + Some(AnyModel { entity_id: self.entity_id, entity_type: self.entity_type, entity_map: self.entity_ref_counts.clone(), @@ -369,55 +369,55 @@ impl AnyWeakHandle { } } -impl From> for AnyWeakHandle { - fn from(handle: WeakHandle) -> Self { - handle.any_handle +impl From> for AnyWeakModel { + fn from(model: WeakModel) -> Self { + model.any_model } } -impl Hash for AnyWeakHandle { +impl Hash for AnyWeakModel { fn hash(&self, state: &mut H) { self.entity_id.hash(state); } } -impl PartialEq for AnyWeakHandle { +impl PartialEq for AnyWeakModel { fn eq(&self, other: &Self) -> bool { self.entity_id == other.entity_id } } -impl Eq for AnyWeakHandle {} +impl Eq for AnyWeakModel {} #[derive(Deref, DerefMut)] -pub struct WeakHandle { +pub struct WeakModel { #[deref] #[deref_mut] - any_handle: AnyWeakHandle, + any_model: AnyWeakModel, entity_type: PhantomData, } -unsafe impl Send for WeakHandle {} -unsafe impl Sync for WeakHandle {} +unsafe impl Send for WeakModel {} +unsafe impl Sync for WeakModel {} -impl Clone for WeakHandle { +impl Clone for WeakModel { fn clone(&self) -> Self { Self { - any_handle: self.any_handle.clone(), + any_model: self.any_model.clone(), entity_type: self.entity_type, } } } -impl WeakHandle { +impl WeakModel { pub fn upgrade(&self) -> Option> { Some(Model { - any_handle: self.any_handle.upgrade()?, + any_model: self.any_model.upgrade()?, entity_type: self.entity_type, }) } - /// Update the entity referenced by this handle with the given function if + /// Update the entity referenced by this model with the given function if /// the referenced entity still exists. Returns an error if the entity has /// been released. /// @@ -441,21 +441,21 @@ impl WeakHandle { } } -impl Hash for WeakHandle { +impl Hash for WeakModel { fn hash(&self, state: &mut H) { - self.any_handle.hash(state); + self.any_model.hash(state); } } -impl PartialEq for WeakHandle { +impl PartialEq for WeakModel { fn eq(&self, other: &Self) -> bool { - self.any_handle == other.any_handle + self.any_model == other.any_model } } -impl Eq for WeakHandle {} +impl Eq for WeakModel {} -impl PartialEq> for WeakHandle { +impl PartialEq> for WeakModel { fn eq(&self, other: &Model) -> bool { self.entity_id() == other.entity_id() } diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs index b5f78fbc468a6365f1f3a6dd8f10dfa3efc0d808..463652886b2767c8c155f068c057afd2befe9851 100644 --- a/crates/gpui2/src/app/model_context.rs +++ b/crates/gpui2/src/app/model_context.rs @@ -1,6 +1,6 @@ use crate::{ AppContext, AsyncAppContext, Context, Effect, EntityId, EventEmitter, MainThread, Model, - Reference, Subscription, Task, WeakHandle, + Reference, Subscription, Task, WeakModel, }; use derive_more::{Deref, DerefMut}; use futures::FutureExt; @@ -15,11 +15,11 @@ pub struct ModelContext<'a, T> { #[deref] #[deref_mut] app: Reference<'a, AppContext>, - model_state: WeakHandle, + model_state: WeakModel, } impl<'a, T: 'static> ModelContext<'a, T> { - pub(crate) fn mutable(app: &'a mut AppContext, model_state: WeakHandle) -> Self { + pub(crate) fn mutable(app: &'a mut AppContext, model_state: WeakModel) -> Self { Self { app: Reference::Mutable(app), model_state, @@ -36,7 +36,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { .expect("The entity must be alive if we have a model context") } - pub fn weak_handle(&self) -> WeakHandle { + pub fn weak_handle(&self) -> WeakModel { self.model_state.clone() } @@ -184,7 +184,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn spawn( &self, - f: impl FnOnce(WeakHandle, AsyncAppContext) -> Fut + Send + 'static, + f: impl FnOnce(WeakModel, AsyncAppContext) -> Fut + Send + 'static, ) -> Task where T: 'static, @@ -197,7 +197,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn spawn_on_main( &self, - f: impl FnOnce(WeakHandle, MainThread) -> Fut + Send + 'static, + f: impl FnOnce(WeakModel, MainThread) -> Fut + Send + 'static, ) -> Task where Fut: Future + 'static, diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index a617792bfb88685351c8d9e4eb17652cc49b6dcd..faa7d239757d43f6774610a4544b81f02f61fb17 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -333,7 +333,7 @@ pub trait StatefulInteractive: StatelessInteractive { Some(Box::new(move |view_state, cursor_offset, cx| { let drag = listener(view_state, cx); let drag_handle_view = Some( - View::for_handle(cx.handle().upgrade().unwrap(), move |view_state, cx| { + View::for_handle(cx.model().upgrade().unwrap(), move |view_state, cx| { (drag.render_drag_handle)(view_state, cx) }) .into_any(), diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index c988223fd01ddcd2eed5ad69b5a9c4281fb31519..cacca8b91e2f4f7992bbbcc3dbfd5ea9c31cfbdb 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -1,6 +1,6 @@ use crate::{ AnyBox, AnyElement, AvailableSpace, BorrowWindow, Bounds, Component, Element, ElementId, - EntityId, LayoutId, Model, Pixels, Size, ViewContext, VisualContext, WeakHandle, WindowContext, + EntityId, LayoutId, Model, Pixels, Size, ViewContext, VisualContext, WeakModel, WindowContext, }; use anyhow::{Context, Result}; use parking_lot::Mutex; @@ -116,7 +116,7 @@ impl Element<()> for View { } pub struct WeakView { - pub(crate) state: WeakHandle, + pub(crate) state: WeakModel, render: Weak) -> AnyElement + Send + 'static>>, } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 073ffa56bda384bd7703fa3710e551b022035263..3d6a891dfe21097ab06d0f08666aaf793d012a64 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -7,7 +7,7 @@ use crate::{ MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Quad, Reference, RenderGlyphParams, RenderImageParams, RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription, - TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, WeakHandle, WeakView, + TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, WeakModel, WeakView, WindowOptions, SUBPIXEL_VARIANTS, }; use anyhow::Result; @@ -1257,13 +1257,13 @@ impl Context for WindowContext<'_, '_> { fn update_entity( &mut self, - handle: &Model, + model: &Model, update: impl FnOnce(&mut T, &mut Self::ModelContext<'_, T>) -> R, ) -> R { - let mut entity = self.entities.lease(handle); + let mut entity = self.entities.lease(model); let result = update( &mut *entity, - &mut ModelContext::mutable(&mut *self.app, handle.downgrade()), + &mut ModelContext::mutable(&mut *self.app, model.downgrade()), ); self.entities.end_lease(entity); result @@ -1555,7 +1555,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { self.view.clone() } - pub fn handle(&self) -> WeakHandle { + pub fn model(&self) -> WeakModel { self.view.state.clone() } @@ -1872,10 +1872,10 @@ impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> { fn update_entity( &mut self, - handle: &Model, + model: &Model, update: impl FnOnce(&mut T, &mut Self::ModelContext<'_, T>) -> R, ) -> R { - self.window_cx.update_entity(handle, update) + self.window_cx.update_entity(model, update) } } diff --git a/crates/project2/src/project2.rs b/crates/project2/src/project2.rs index e91c3b72631994c07205920eb4bfa2d5f3f61308..ce97b9cc22d386cbc995d9fb8f7330a096a69eb1 100644 --- a/crates/project2/src/project2.rs +++ b/crates/project2/src/project2.rs @@ -26,8 +26,8 @@ use futures::{ }; use globset::{Glob, GlobSet, GlobSetBuilder}; use gpui2::{ - AnyHandle, AppContext, AsyncAppContext, Context, EventEmitter, Executor, Model, ModelContext, - Task, WeakHandle, + AnyModel, AppContext, AsyncAppContext, Context, EventEmitter, Executor, Model, ModelContext, + Task, WeakModel, }; use itertools::Itertools; use language2::{ @@ -153,7 +153,7 @@ pub struct Project { incomplete_remote_buffers: HashMap>>, buffer_snapshots: HashMap>>, // buffer_id -> server_id -> vec of snapshots buffers_being_formatted: HashSet, - buffers_needing_diff: HashSet>, + buffers_needing_diff: HashSet>, git_diff_debouncer: DelayedDebounced, nonce: u128, _maintain_buffer_languages: Task<()>, @@ -245,14 +245,14 @@ enum LocalProjectUpdate { enum OpenBuffer { Strong(Model), - Weak(WeakHandle), + Weak(WeakModel), Operations(Vec), } #[derive(Clone)] enum WorktreeHandle { Strong(Model), - Weak(WeakHandle), + Weak(WeakModel), } enum ProjectClientState { @@ -1671,7 +1671,7 @@ impl Project { &mut self, path: impl Into, cx: &mut ModelContext, - ) -> Task> { + ) -> Task> { let task = self.open_buffer(path, cx); cx.spawn(move |_, mut cx| async move { let buffer = task.await?; @@ -1681,7 +1681,7 @@ impl Project { })? .ok_or_else(|| anyhow!("no project entry"))?; - let buffer: &AnyHandle = &buffer; + let buffer: &AnyModel = &buffer; Ok((project_entry_id, buffer.clone())) }) } @@ -2158,7 +2158,7 @@ impl Project { } async fn send_buffer_ordered_messages( - this: WeakHandle, + this: WeakModel, rx: UnboundedReceiver, mut cx: AsyncAppContext, ) -> Result<()> { @@ -2166,7 +2166,7 @@ impl Project { let mut operations_by_buffer_id = HashMap::default(); async fn flush_operations( - this: &WeakHandle, + this: &WeakModel, operations_by_buffer_id: &mut HashMap>, needs_resync_with_host: &mut bool, is_local: bool, @@ -2931,7 +2931,7 @@ impl Project { } async fn setup_and_insert_language_server( - this: WeakHandle, + this: WeakModel, initialization_options: Option, pending_server: PendingLanguageServer, adapter: Arc, @@ -2970,7 +2970,7 @@ impl Project { } async fn setup_pending_language_server( - this: WeakHandle, + this: WeakModel, initialization_options: Option, pending_server: PendingLanguageServer, adapter: Arc, @@ -3748,7 +3748,7 @@ impl Project { } async fn on_lsp_workspace_edit( - this: WeakHandle, + this: WeakModel, params: lsp2::ApplyWorkspaceEditParams, server_id: LanguageServerId, adapter: Arc, @@ -4360,7 +4360,7 @@ impl Project { } async fn format_via_lsp( - this: &WeakHandle, + this: &WeakModel, buffer: &Model, abs_path: &Path, language_server: &Arc, diff --git a/crates/project2/src/terminals.rs b/crates/project2/src/terminals.rs index 239cb99d86134ad581bb48eac43cac70ebd0c456..5cd62d5ae61cf145c13fa7b6c6cf0f446bb96ff8 100644 --- a/crates/project2/src/terminals.rs +++ b/crates/project2/src/terminals.rs @@ -1,5 +1,5 @@ use crate::Project; -use gpui2::{AnyWindowHandle, Context, Model, ModelContext, WeakHandle}; +use gpui2::{AnyWindowHandle, Context, Model, ModelContext, WeakModel}; use settings2::Settings; use std::path::{Path, PathBuf}; use terminal2::{ @@ -11,7 +11,7 @@ use terminal2::{ use std::os::unix::ffi::OsStrExt; pub struct Terminals { - pub(crate) local_handles: Vec>, + pub(crate) local_handles: Vec>, } impl Project { @@ -121,7 +121,7 @@ impl Project { } } - pub fn local_terminal_handles(&self) -> &Vec> { + pub fn local_terminal_handles(&self) -> &Vec> { &self.terminals.local_handles } }