Rename other references from "handle" to "model"
Co-Authored-By: Max <max@zed.dev> Co-Authored-By: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
ba789fc0c4
commit
bc4f8fbf4e
13 changed files with 128 additions and 128 deletions
|
@ -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<Room>, Vec<Subscription>)>,
|
||||
pending_room_creation: Option<Shared<Task<Result<Model<Room>, Arc<anyhow::Error>>>>>,
|
||||
location: Option<WeakHandle<Project>>,
|
||||
location: Option<WeakModel<Project>>,
|
||||
pending_invites: HashSet<u64>,
|
||||
incoming_call: (
|
||||
watch::Sender<Option<IncomingCall>>,
|
||||
|
@ -347,7 +347,7 @@ impl ActiveCall {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn location(&self) -> Option<&WeakHandle<Project>> {
|
||||
pub fn location(&self) -> Option<&WeakModel<Project>> {
|
||||
self.location.as_ref()
|
||||
}
|
||||
|
||||
|
|
|
@ -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<proto::ParticipantProject>,
|
||||
pub active_project: Option<WeakHandle<Project>>,
|
||||
pub active_project: Option<WeakModel<Project>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -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<u64>,
|
||||
// live_kit: Option<LiveKitRoom>,
|
||||
status: RoomStatus,
|
||||
shared_projects: HashSet<WeakHandle<Project>>,
|
||||
joined_projects: HashSet<WeakHandle<Project>>,
|
||||
shared_projects: HashSet<WeakModel<Project>>,
|
||||
joined_projects: HashSet<WeakModel<Project>>,
|
||||
local_participant: LocalParticipant,
|
||||
remote_participants: BTreeMap<u64, RemoteParticipant>,
|
||||
pending_participants: Vec<Arc<User>>,
|
||||
|
@ -424,7 +424,7 @@ impl Room {
|
|||
}
|
||||
|
||||
async fn maintain_connection(
|
||||
this: WeakHandle<Self>,
|
||||
this: WeakModel<Self>,
|
||||
client: Arc<Client>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<()> {
|
||||
|
|
|
@ -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<Task<()>>,
|
||||
reconnect_interval: Duration,
|
||||
entities_by_type_and_remote_id: HashMap<(TypeId, u64), WeakSubscriber>,
|
||||
models_by_message_type: HashMap<TypeId, AnyWeakHandle>,
|
||||
models_by_message_type: HashMap<TypeId, AnyWeakModel>,
|
||||
entity_types_by_message_type: HashMap<TypeId, TypeId>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
message_handlers: HashMap<
|
||||
|
@ -236,7 +236,7 @@ struct ClientState {
|
|||
dyn Send
|
||||
+ Sync
|
||||
+ Fn(
|
||||
AnyHandle,
|
||||
AnyModel,
|
||||
Box<dyn AnyTypedEnvelope>,
|
||||
&Arc<Client>,
|
||||
AsyncAppContext,
|
||||
|
@ -246,7 +246,7 @@ struct ClientState {
|
|||
}
|
||||
|
||||
enum WeakSubscriber {
|
||||
Entity { handle: AnyWeakHandle },
|
||||
Entity { handle: AnyWeakModel },
|
||||
Pending(Vec<Box<dyn AnyTypedEnvelope>>),
|
||||
}
|
||||
|
||||
|
@ -552,7 +552,7 @@ impl Client {
|
|||
#[track_caller]
|
||||
pub fn add_message_handler<M, E, H, F>(
|
||||
self: &Arc<Self>,
|
||||
entity: WeakHandle<E>,
|
||||
entity: WeakModel<E>,
|
||||
handler: H,
|
||||
) -> Subscription
|
||||
where
|
||||
|
@ -594,7 +594,7 @@ impl Client {
|
|||
|
||||
pub fn add_request_handler<M, E, H, F>(
|
||||
self: &Arc<Self>,
|
||||
model: WeakHandle<E>,
|
||||
model: WeakModel<E>,
|
||||
handler: H,
|
||||
) -> Subscription
|
||||
where
|
||||
|
@ -628,7 +628,7 @@ impl Client {
|
|||
where
|
||||
M: EntityMessage,
|
||||
E: 'static + Send,
|
||||
H: 'static + Send + Sync + Fn(AnyHandle, TypedEnvelope<M>, Arc<Self>, AsyncAppContext) -> F,
|
||||
H: 'static + Send + Sync + Fn(AnyModel, TypedEnvelope<M>, Arc<Self>, AsyncAppContext) -> F,
|
||||
F: 'static + Future<Output = Result<()>> + Send,
|
||||
{
|
||||
let model_type_id = TypeId::of::<E>();
|
||||
|
|
|
@ -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<dyn HttpClient>,
|
||||
node_runtime: Arc<dyn NodeRuntime>,
|
||||
server: CopilotServer,
|
||||
buffers: HashSet<WeakHandle<Buffer>>,
|
||||
buffers: HashSet<WeakModel<Buffer>>,
|
||||
server_id: LanguageServerId,
|
||||
_subscription: gpui2::Subscription,
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ impl Copilot {
|
|||
new_server_id: LanguageServerId,
|
||||
http: Arc<dyn HttpClient>,
|
||||
node_runtime: Arc<dyn NodeRuntime>,
|
||||
this: WeakHandle<Self>,
|
||||
this: WeakModel<Self>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> impl Future<Output = ()> {
|
||||
async move {
|
||||
|
@ -706,7 +706,7 @@ impl Copilot {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn unregister_buffer(&mut self, buffer: &WeakHandle<Buffer>) {
|
||||
fn unregister_buffer(&mut self, buffer: &WeakModel<Buffer>) {
|
||||
if let Ok(server) = self.server.as_running() {
|
||||
if let Some(buffer) = server.registered_buffers.remove(&buffer.entity_id()) {
|
||||
server
|
||||
|
|
|
@ -711,7 +711,7 @@ impl Context for AppContext {
|
|||
type Result<T> = 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<T: 'static + Send>(
|
||||
&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<T: 'static, R>(
|
||||
&mut self,
|
||||
handle: &Model<T>,
|
||||
model: &Model<T>,
|
||||
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
|
||||
|
|
|
@ -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<T>) -> Lease<'a, T> {
|
||||
self.assert_valid_context(handle);
|
||||
pub fn lease<'a, T>(&mut self, model: &'a Model<T>) -> 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<T>(&mut self, mut lease: Lease<T>) {
|
||||
self.entities
|
||||
.insert(lease.handle.entity_id, lease.entity.take().unwrap());
|
||||
.insert(lease.model.entity_id, lease.entity.take().unwrap());
|
||||
}
|
||||
|
||||
pub fn read<T: 'static>(&self, handle: &Model<T>) -> &T {
|
||||
self.assert_valid_context(handle);
|
||||
self.entities[handle.entity_id].downcast_ref().unwrap()
|
||||
pub fn read<T: 'static>(&self, model: &Model<T>) -> &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<AnyBox>,
|
||||
pub handle: &'a Model<T>,
|
||||
pub model: &'a Model<T>,
|
||||
entity_type: PhantomData<T>,
|
||||
}
|
||||
|
||||
|
@ -145,13 +145,13 @@ impl<'a, T> Drop for Lease<'a, T> {
|
|||
#[derive(Deref, DerefMut)]
|
||||
pub struct Slot<T>(Model<T>);
|
||||
|
||||
pub struct AnyHandle {
|
||||
pub struct AnyModel {
|
||||
pub(crate) entity_id: EntityId,
|
||||
entity_type: TypeId,
|
||||
entity_map: Weak<RwLock<EntityRefCounts>>,
|
||||
}
|
||||
|
||||
impl AnyHandle {
|
||||
impl AnyModel {
|
||||
fn new(id: EntityId, entity_type: TypeId, entity_map: Weak<RwLock<EntityRefCounts>>) -> 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<T: 'static>(&self) -> Option<Model<T>> {
|
||||
if TypeId::of::<T>() == 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<T> From<Model<T>> for AnyHandle {
|
||||
fn from(handle: Model<T>) -> Self {
|
||||
handle.any_handle
|
||||
impl<T> From<Model<T>> for AnyModel {
|
||||
fn from(model: Model<T>) -> Self {
|
||||
model.any_model
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for AnyHandle {
|
||||
impl Hash for AnyModel {
|
||||
fn hash<H: Hasher>(&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<T> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
any_handle: AnyHandle,
|
||||
any_model: AnyModel,
|
||||
entity_type: PhantomData<T>,
|
||||
}
|
||||
|
||||
|
@ -260,14 +260,14 @@ impl<T: 'static> Model<T> {
|
|||
T: 'static,
|
||||
{
|
||||
Self {
|
||||
any_handle: AnyHandle::new(id, TypeId::of::<T>(), entity_map),
|
||||
any_model: AnyModel::new(id, TypeId::of::<T>(), entity_map),
|
||||
entity_type: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn downgrade(&self) -> WeakHandle<T> {
|
||||
WeakHandle {
|
||||
any_handle: self.any_handle.downgrade(),
|
||||
pub fn downgrade(&self) -> WeakModel<T> {
|
||||
WeakModel {
|
||||
any_model: self.any_model.downgrade(),
|
||||
entity_type: self.entity_type,
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ impl<T: 'static> Model<T> {
|
|||
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<T: 'static> Model<T> {
|
|||
impl<T> Clone for Model<T> {
|
||||
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<T> std::fmt::Debug for Model<T> {
|
|||
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::<T>()
|
||||
)
|
||||
}
|
||||
|
@ -315,32 +315,32 @@ impl<T> std::fmt::Debug for Model<T> {
|
|||
|
||||
impl<T> Hash for Model<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.any_handle.hash(state);
|
||||
self.any_model.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Model<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.any_handle == other.any_handle
|
||||
self.any_model == other.any_model
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Model<T> {}
|
||||
|
||||
impl<T> PartialEq<WeakHandle<T>> for Model<T> {
|
||||
fn eq(&self, other: &WeakHandle<T>) -> bool {
|
||||
impl<T> PartialEq<WeakModel<T>> for Model<T> {
|
||||
fn eq(&self, other: &WeakModel<T>) -> 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<RwLock<EntityRefCounts>>,
|
||||
}
|
||||
|
||||
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<AnyHandle> {
|
||||
pub fn upgrade(&self) -> Option<AnyModel> {
|
||||
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<T> From<WeakHandle<T>> for AnyWeakHandle {
|
||||
fn from(handle: WeakHandle<T>) -> Self {
|
||||
handle.any_handle
|
||||
impl<T> From<WeakModel<T>> for AnyWeakModel {
|
||||
fn from(model: WeakModel<T>) -> Self {
|
||||
model.any_model
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for AnyWeakHandle {
|
||||
impl Hash for AnyWeakModel {
|
||||
fn hash<H: Hasher>(&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<T> {
|
||||
pub struct WeakModel<T> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
any_handle: AnyWeakHandle,
|
||||
any_model: AnyWeakModel,
|
||||
entity_type: PhantomData<T>,
|
||||
}
|
||||
|
||||
unsafe impl<T> Send for WeakHandle<T> {}
|
||||
unsafe impl<T> Sync for WeakHandle<T> {}
|
||||
unsafe impl<T> Send for WeakModel<T> {}
|
||||
unsafe impl<T> Sync for WeakModel<T> {}
|
||||
|
||||
impl<T> Clone for WeakHandle<T> {
|
||||
impl<T> Clone for WeakModel<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
any_handle: self.any_handle.clone(),
|
||||
any_model: self.any_model.clone(),
|
||||
entity_type: self.entity_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> WeakHandle<T> {
|
||||
impl<T: 'static> WeakModel<T> {
|
||||
pub fn upgrade(&self) -> Option<Model<T>> {
|
||||
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<T: 'static> WeakHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Hash for WeakHandle<T> {
|
||||
impl<T> Hash for WeakModel<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.any_handle.hash(state);
|
||||
self.any_model.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for WeakHandle<T> {
|
||||
impl<T> PartialEq for WeakModel<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.any_handle == other.any_handle
|
||||
self.any_model == other.any_model
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for WeakHandle<T> {}
|
||||
impl<T> Eq for WeakModel<T> {}
|
||||
|
||||
impl<T> PartialEq<Model<T>> for WeakHandle<T> {
|
||||
impl<T> PartialEq<Model<T>> for WeakModel<T> {
|
||||
fn eq(&self, other: &Model<T>) -> bool {
|
||||
self.entity_id() == other.entity_id()
|
||||
}
|
||||
|
|
|
@ -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<T>,
|
||||
model_state: WeakModel<T>,
|
||||
}
|
||||
|
||||
impl<'a, T: 'static> ModelContext<'a, T> {
|
||||
pub(crate) fn mutable(app: &'a mut AppContext, model_state: WeakHandle<T>) -> Self {
|
||||
pub(crate) fn mutable(app: &'a mut AppContext, model_state: WeakModel<T>) -> 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<T> {
|
||||
pub fn weak_handle(&self) -> WeakModel<T> {
|
||||
self.model_state.clone()
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
|
|||
|
||||
pub fn spawn<Fut, R>(
|
||||
&self,
|
||||
f: impl FnOnce(WeakHandle<T>, AsyncAppContext) -> Fut + Send + 'static,
|
||||
f: impl FnOnce(WeakModel<T>, AsyncAppContext) -> Fut + Send + 'static,
|
||||
) -> Task<R>
|
||||
where
|
||||
T: 'static,
|
||||
|
@ -197,7 +197,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
|
|||
|
||||
pub fn spawn_on_main<Fut, R>(
|
||||
&self,
|
||||
f: impl FnOnce(WeakHandle<T>, MainThread<AsyncAppContext>) -> Fut + Send + 'static,
|
||||
f: impl FnOnce(WeakModel<T>, MainThread<AsyncAppContext>) -> Fut + Send + 'static,
|
||||
) -> Task<R>
|
||||
where
|
||||
Fut: Future<Output = R> + 'static,
|
||||
|
|
|
@ -333,7 +333,7 @@ pub trait StatefulInteractive<V: 'static>: StatelessInteractive<V> {
|
|||
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(),
|
||||
|
|
|
@ -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<V: 'static> Element<()> for View<V> {
|
|||
}
|
||||
|
||||
pub struct WeakView<V> {
|
||||
pub(crate) state: WeakHandle<V>,
|
||||
pub(crate) state: WeakModel<V>,
|
||||
render: Weak<Mutex<dyn Fn(&mut V, &mut ViewContext<V>) -> AnyElement<V> + Send + 'static>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T: 'static, R>(
|
||||
&mut self,
|
||||
handle: &Model<T>,
|
||||
model: &Model<T>,
|
||||
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<V> {
|
||||
pub fn model(&self) -> WeakModel<V> {
|
||||
self.view.state.clone()
|
||||
}
|
||||
|
||||
|
@ -1872,10 +1872,10 @@ impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> {
|
|||
|
||||
fn update_entity<T: 'static, R>(
|
||||
&mut self,
|
||||
handle: &Model<T>,
|
||||
model: &Model<T>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<u64, Option<Model<Buffer>>>,
|
||||
buffer_snapshots: HashMap<u64, HashMap<LanguageServerId, Vec<LspBufferSnapshot>>>, // buffer_id -> server_id -> vec of snapshots
|
||||
buffers_being_formatted: HashSet<u64>,
|
||||
buffers_needing_diff: HashSet<WeakHandle<Buffer>>,
|
||||
buffers_needing_diff: HashSet<WeakModel<Buffer>>,
|
||||
git_diff_debouncer: DelayedDebounced,
|
||||
nonce: u128,
|
||||
_maintain_buffer_languages: Task<()>,
|
||||
|
@ -245,14 +245,14 @@ enum LocalProjectUpdate {
|
|||
|
||||
enum OpenBuffer {
|
||||
Strong(Model<Buffer>),
|
||||
Weak(WeakHandle<Buffer>),
|
||||
Weak(WeakModel<Buffer>),
|
||||
Operations(Vec<Operation>),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum WorktreeHandle {
|
||||
Strong(Model<Worktree>),
|
||||
Weak(WeakHandle<Worktree>),
|
||||
Weak(WeakModel<Worktree>),
|
||||
}
|
||||
|
||||
enum ProjectClientState {
|
||||
|
@ -1671,7 +1671,7 @@ impl Project {
|
|||
&mut self,
|
||||
path: impl Into<ProjectPath>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<(ProjectEntryId, AnyHandle)>> {
|
||||
) -> Task<Result<(ProjectEntryId, AnyModel)>> {
|
||||
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<Self>,
|
||||
this: WeakModel<Self>,
|
||||
rx: UnboundedReceiver<BufferOrderedMessage>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<()> {
|
||||
|
@ -2166,7 +2166,7 @@ impl Project {
|
|||
|
||||
let mut operations_by_buffer_id = HashMap::default();
|
||||
async fn flush_operations(
|
||||
this: &WeakHandle<Project>,
|
||||
this: &WeakModel<Project>,
|
||||
operations_by_buffer_id: &mut HashMap<u64, Vec<proto::Operation>>,
|
||||
needs_resync_with_host: &mut bool,
|
||||
is_local: bool,
|
||||
|
@ -2931,7 +2931,7 @@ impl Project {
|
|||
}
|
||||
|
||||
async fn setup_and_insert_language_server(
|
||||
this: WeakHandle<Self>,
|
||||
this: WeakModel<Self>,
|
||||
initialization_options: Option<serde_json::Value>,
|
||||
pending_server: PendingLanguageServer,
|
||||
adapter: Arc<CachedLspAdapter>,
|
||||
|
@ -2970,7 +2970,7 @@ impl Project {
|
|||
}
|
||||
|
||||
async fn setup_pending_language_server(
|
||||
this: WeakHandle<Self>,
|
||||
this: WeakModel<Self>,
|
||||
initialization_options: Option<serde_json::Value>,
|
||||
pending_server: PendingLanguageServer,
|
||||
adapter: Arc<CachedLspAdapter>,
|
||||
|
@ -3748,7 +3748,7 @@ impl Project {
|
|||
}
|
||||
|
||||
async fn on_lsp_workspace_edit(
|
||||
this: WeakHandle<Self>,
|
||||
this: WeakModel<Self>,
|
||||
params: lsp2::ApplyWorkspaceEditParams,
|
||||
server_id: LanguageServerId,
|
||||
adapter: Arc<CachedLspAdapter>,
|
||||
|
@ -4360,7 +4360,7 @@ impl Project {
|
|||
}
|
||||
|
||||
async fn format_via_lsp(
|
||||
this: &WeakHandle<Self>,
|
||||
this: &WeakModel<Self>,
|
||||
buffer: &Model<Buffer>,
|
||||
abs_path: &Path,
|
||||
language_server: &Arc<LanguageServer>,
|
||||
|
|
|
@ -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<WeakHandle<terminal2::Terminal>>,
|
||||
pub(crate) local_handles: Vec<WeakModel<terminal2::Terminal>>,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
|
@ -121,7 +121,7 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn local_terminal_handles(&self) -> &Vec<WeakHandle<terminal2::Terminal>> {
|
||||
pub fn local_terminal_handles(&self) -> &Vec<WeakModel<terminal2::Terminal>> {
|
||||
&self.terminals.local_handles
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue