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