Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -17,8 +17,8 @@ use futures::{
|
|||
select, select_biased, AsyncReadExt as _, Future, FutureExt as _, StreamExt as _,
|
||||
};
|
||||
use gpui::{
|
||||
AppContext, AsyncAppContext, BorrowAppContext, Context, EventEmitter, Global, Model,
|
||||
ModelContext, SemanticVersion, Task, WeakModel,
|
||||
App, AppContext, AsyncAppContext, BorrowAppContext, Context, Entity, EventEmitter, Global,
|
||||
SemanticVersion, Task, WeakEntity,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use parking_lot::Mutex;
|
||||
|
@ -503,7 +503,7 @@ impl ConnectionIdentifier {
|
|||
// Must be less than about 100 characters
|
||||
// https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars
|
||||
// So our strings should be at most 20 characters or so.
|
||||
fn to_string(&self, cx: &AppContext) -> String {
|
||||
fn to_string(&self, cx: &App) -> String {
|
||||
let identifier_prefix = match ReleaseChannel::global(cx) {
|
||||
ReleaseChannel::Stable => "".to_string(),
|
||||
release_channel => format!("{}-", release_channel.dev_name()),
|
||||
|
@ -523,8 +523,8 @@ impl SshRemoteClient {
|
|||
connection_options: SshConnectionOptions,
|
||||
cancellation: oneshot::Receiver<()>,
|
||||
delegate: Arc<dyn SshClientDelegate>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<Result<Option<Model<Self>>>> {
|
||||
cx: &mut App,
|
||||
) -> Task<Result<Option<Entity<Self>>>> {
|
||||
let unique_identifier = unique_identifier.to_string(cx);
|
||||
cx.spawn(|mut cx| async move {
|
||||
let success = Box::pin(async move {
|
||||
|
@ -534,7 +534,7 @@ impl SshRemoteClient {
|
|||
|
||||
let client =
|
||||
cx.update(|cx| ChannelClient::new(incoming_rx, outgoing_tx, cx, "client"))?;
|
||||
let this = cx.new_model(|_| Self {
|
||||
let this = cx.new(|_| Self {
|
||||
client: client.clone(),
|
||||
unique_identifier: unique_identifier.clone(),
|
||||
connection_options: connection_options.clone(),
|
||||
|
@ -629,7 +629,7 @@ impl SshRemoteClient {
|
|||
})
|
||||
}
|
||||
|
||||
fn reconnect(&mut self, cx: &mut ModelContext<Self>) -> Result<()> {
|
||||
fn reconnect(&mut self, cx: &mut Context<Self>) -> Result<()> {
|
||||
let mut lock = self.state.lock();
|
||||
|
||||
let can_reconnect = lock
|
||||
|
@ -811,7 +811,7 @@ impl SshRemoteClient {
|
|||
}
|
||||
|
||||
fn heartbeat(
|
||||
this: WeakModel<Self>,
|
||||
this: WeakEntity<Self>,
|
||||
mut connection_activity_rx: mpsc::Receiver<()>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Task<Result<()>> {
|
||||
|
@ -886,7 +886,7 @@ impl SshRemoteClient {
|
|||
fn handle_heartbeat_result(
|
||||
&mut self,
|
||||
missed_heartbeats: usize,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> ControlFlow<()> {
|
||||
let state = self.state.lock().take().unwrap();
|
||||
let next_state = if missed_heartbeats > 0 {
|
||||
|
@ -913,7 +913,7 @@ impl SshRemoteClient {
|
|||
}
|
||||
|
||||
fn monitor(
|
||||
this: WeakModel<Self>,
|
||||
this: WeakEntity<Self>,
|
||||
io_task: Task<Result<i32>>,
|
||||
cx: &AsyncAppContext,
|
||||
) -> Task<Result<()>> {
|
||||
|
@ -954,11 +954,7 @@ impl SshRemoteClient {
|
|||
self.state.lock().as_ref().map_or(false, check)
|
||||
}
|
||||
|
||||
fn try_set_state(
|
||||
&self,
|
||||
cx: &mut ModelContext<Self>,
|
||||
map: impl FnOnce(&State) -> Option<State>,
|
||||
) {
|
||||
fn try_set_state(&self, cx: &mut Context<Self>, map: impl FnOnce(&State) -> Option<State>) {
|
||||
let mut lock = self.state.lock();
|
||||
let new_state = lock.as_ref().and_then(map);
|
||||
|
||||
|
@ -968,7 +964,7 @@ impl SshRemoteClient {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_state(&self, state: State, cx: &mut ModelContext<Self>) {
|
||||
fn set_state(&self, state: State, cx: &mut Context<Self>) {
|
||||
log::info!("setting state to '{}'", &state);
|
||||
|
||||
let is_reconnect_exhausted = state.is_reconnect_exhausted();
|
||||
|
@ -981,7 +977,7 @@ impl SshRemoteClient {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn subscribe_to_entity<E: 'static>(&self, remote_id: u64, entity: &Model<E>) {
|
||||
pub fn subscribe_to_entity<E: 'static>(&self, remote_id: u64, entity: &Entity<E>) {
|
||||
self.client.subscribe_to_entity(remote_id, entity);
|
||||
}
|
||||
|
||||
|
@ -997,7 +993,7 @@ impl SshRemoteClient {
|
|||
&self,
|
||||
src_path: PathBuf,
|
||||
dest_path: PathBuf,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Task<Result<()>> {
|
||||
let state = self.state.lock();
|
||||
let Some(connection) = state.as_ref().and_then(|state| state.ssh_connection()) else {
|
||||
|
@ -1031,7 +1027,7 @@ impl SshRemoteClient {
|
|||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn simulate_disconnect(&self, client_cx: &mut AppContext) -> Task<()> {
|
||||
pub fn simulate_disconnect(&self, client_cx: &mut App) -> Task<()> {
|
||||
let opts = self.connection_options();
|
||||
client_cx.spawn(|cx| async move {
|
||||
let connection = cx
|
||||
|
@ -1095,7 +1091,7 @@ impl SshRemoteClient {
|
|||
pub async fn fake_client(
|
||||
opts: SshConnectionOptions,
|
||||
client_cx: &mut gpui::TestAppContext,
|
||||
) -> Model<Self> {
|
||||
) -> Entity<Self> {
|
||||
let (_tx, rx) = oneshot::channel();
|
||||
client_cx
|
||||
.update(|cx| {
|
||||
|
@ -1130,7 +1126,7 @@ impl ConnectionPool {
|
|||
&mut self,
|
||||
opts: SshConnectionOptions,
|
||||
delegate: &Arc<dyn SshClientDelegate>,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut App,
|
||||
) -> Shared<Task<Result<Arc<dyn RemoteConnection>, Arc<anyhow::Error>>>> {
|
||||
let connection = self.connections.get(&opts);
|
||||
match connection {
|
||||
|
@ -1210,12 +1206,8 @@ trait RemoteConnection: Send + Sync {
|
|||
delegate: Arc<dyn SshClientDelegate>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Task<Result<i32>>;
|
||||
fn upload_directory(
|
||||
&self,
|
||||
src_path: PathBuf,
|
||||
dest_path: PathBuf,
|
||||
cx: &AppContext,
|
||||
) -> Task<Result<()>>;
|
||||
fn upload_directory(&self, src_path: PathBuf, dest_path: PathBuf, cx: &App)
|
||||
-> Task<Result<()>>;
|
||||
async fn kill(&self) -> Result<()>;
|
||||
fn has_been_killed(&self) -> bool;
|
||||
fn ssh_args(&self) -> Vec<String>;
|
||||
|
@ -1259,7 +1251,7 @@ impl RemoteConnection for SshRemoteConnection {
|
|||
&self,
|
||||
src_path: PathBuf,
|
||||
dest_path: PathBuf,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Task<Result<()>> {
|
||||
let mut command = util::command::new_smol_command("scp");
|
||||
let output = self
|
||||
|
@ -2071,7 +2063,7 @@ impl ChannelClient {
|
|||
pub fn new(
|
||||
incoming_rx: mpsc::UnboundedReceiver<Envelope>,
|
||||
outgoing_tx: mpsc::UnboundedSender<Envelope>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
name: &'static str,
|
||||
) -> Arc<Self> {
|
||||
Arc::new_cyclic(|this| Self {
|
||||
|
@ -2199,7 +2191,7 @@ impl ChannelClient {
|
|||
*self.task.lock() = Self::start_handling_messages(Arc::downgrade(self), incoming_rx, cx);
|
||||
}
|
||||
|
||||
pub fn subscribe_to_entity<E: 'static>(&self, remote_id: u64, entity: &Model<E>) {
|
||||
pub fn subscribe_to_entity<E: 'static>(&self, remote_id: u64, entity: &Entity<E>) {
|
||||
let id = (TypeId::of::<E>(), remote_id);
|
||||
|
||||
let mut message_handlers = self.message_handlers.lock();
|
||||
|
@ -2373,7 +2365,7 @@ mod fake {
|
|||
},
|
||||
select_biased, FutureExt, SinkExt, StreamExt,
|
||||
};
|
||||
use gpui::{AppContext, AsyncAppContext, SemanticVersion, Task, TestAppContext};
|
||||
use gpui::{App, AsyncAppContext, SemanticVersion, Task, TestAppContext};
|
||||
use release_channel::ReleaseChannel;
|
||||
use rpc::proto::Envelope;
|
||||
|
||||
|
@ -2421,7 +2413,7 @@ mod fake {
|
|||
&self,
|
||||
_src_path: PathBuf,
|
||||
_dest_path: PathBuf,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) -> Task<Result<()>> {
|
||||
unreachable!()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue