Zed2 entities (#3189)

Adds an `Entity` trait for abstracting over `View`s and `Model`s, and
implements it for the `subscribe()` and `observe()` APIs.

The last commit also includes a fun experiment I added, using the
`Result` type to return the owned model handles back to the caller in
the case of downcast failure, inspired by the `binary_search*` methods.
This commit is contained in:
Antonio Scandurra 2023-10-31 10:11:25 +01:00 committed by GitHub
commit 88875fd006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 214 additions and 107 deletions

View file

@ -26,8 +26,8 @@ use futures::{
};
use globset::{Glob, GlobSet, GlobSetBuilder};
use gpui2::{
AnyModel, AppContext, AsyncAppContext, Context, EventEmitter, Executor, Model, ModelContext,
Task, WeakModel,
AnyModel, AppContext, AsyncAppContext, Context, Entity, EventEmitter, Executor, Model,
ModelContext, Task, WeakModel,
};
use itertools::Itertools;
use language2::{
@ -2491,7 +2491,7 @@ impl Project {
delay
} else {
if first_insertion {
let this = cx.weak_handle();
let this = cx.weak_model();
cx.defer(move |cx| {
if let Some(this) = this.upgrade() {
this.update(cx, |this, cx| {
@ -8644,7 +8644,7 @@ fn subscribe_for_copilot_events(
// Another event wants to re-add the server that was already added and subscribed to, avoid doing it again.
if !copilot_server.has_notification_handler::<copilot2::request::LogMessage>() {
let new_server_id = copilot_server.server_id();
let weak_project = cx.weak_handle();
let weak_project = cx.weak_model();
let copilot_log_subscription = copilot_server
.on_notification::<copilot2::request::LogMessage, _>(
move |params, mut cx| {

View file

@ -1,5 +1,5 @@
use crate::Project;
use gpui2::{AnyWindowHandle, Context, Model, ModelContext, WeakModel};
use gpui2::{AnyWindowHandle, Context, Entity, Model, ModelContext, WeakModel};
use settings2::Settings;
use std::path::{Path, PathBuf};
use terminal2::{