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:
Nathan Sobo 2025-01-25 20:02:45 -07:00 committed by GitHub
parent 21b4a0d50e
commit 6fca1d2b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
648 changed files with 36248 additions and 28208 deletions

View file

@ -6,7 +6,7 @@ use futures::{
future::Shared,
stream,
};
use gpui::{AppContext, Model, Task, WindowContext};
use gpui::{App, Entity, Task, Window};
use language::LanguageName;
pub use native_kernel::*;
@ -61,7 +61,7 @@ impl KernelSpecification {
})
}
pub fn icon(&self, cx: &AppContext) -> Icon {
pub fn icon(&self, cx: &App) -> Icon {
let lang_name = match self {
Self::Jupyter(spec) => spec.kernelspec.language.clone(),
Self::PythonEnv(spec) => spec.kernelspec.language.clone(),
@ -76,9 +76,9 @@ impl KernelSpecification {
}
pub fn python_env_kernel_specifications(
project: &Model<Project>,
project: &Entity<Project>,
worktree_id: WorktreeId,
cx: &mut AppContext,
cx: &mut App,
) -> impl Future<Output = Result<Vec<KernelSpecification>>> {
let python_language = LanguageName::new("Python");
let toolchains = project
@ -148,7 +148,7 @@ pub trait RunningKernel: Send + Debug {
fn set_execution_state(&mut self, state: ExecutionState);
fn kernel_info(&self) -> Option<&KernelInfoReply>;
fn set_kernel_info(&mut self, info: KernelInfoReply);
fn force_shutdown(&mut self, cx: &mut WindowContext) -> Task<anyhow::Result<()>>;
fn force_shutdown(&mut self, window: &mut Window, cx: &mut App) -> Task<anyhow::Result<()>>;
}
#[derive(Debug, Clone)]

View file

@ -5,7 +5,7 @@ use futures::{
stream::{SelectAll, StreamExt},
AsyncBufReadExt as _, SinkExt as _,
};
use gpui::{EntityId, Task, View, WindowContext};
use gpui::{App, Entity, EntityId, Task, Window};
use jupyter_protocol::{
connection_info::{ConnectionInfo, Transport},
ExecutionState, JupyterKernelspec, JupyterMessage, JupyterMessageContent, KernelInfoReply,
@ -114,10 +114,11 @@ impl NativeRunningKernel {
working_directory: PathBuf,
fs: Arc<dyn Fs>,
// todo: convert to weak view
session: View<Session>,
cx: &mut WindowContext,
session: Entity<Session>,
window: &mut Window,
cx: &mut App,
) -> Task<Result<Box<dyn RunningKernel>>> {
cx.spawn(|cx| async move {
window.spawn(cx, |cx| async move {
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let ports = peek_ports(ip).await?;
@ -179,8 +180,8 @@ impl NativeRunningKernel {
|mut cx| async move {
while let Some(message) = messages_rx.next().await {
session
.update(&mut cx, |session, cx| {
session.route(&message, cx);
.update_in(&mut cx, |session, window, cx| {
session.route(&message, window, cx);
})
.ok();
}
@ -196,8 +197,8 @@ impl NativeRunningKernel {
|mut cx| async move {
while let Ok(message) = iopub_socket.read().await {
session
.update(&mut cx, |session, cx| {
session.route(&message, cx);
.update_in(&mut cx, |session, window, cx| {
session.route(&message, window, cx);
})
.ok();
}
@ -347,7 +348,7 @@ impl RunningKernel for NativeRunningKernel {
self.kernel_info = Some(info);
}
fn force_shutdown(&mut self, _cx: &mut WindowContext) -> Task<anyhow::Result<()>> {
fn force_shutdown(&mut self, _window: &mut Window, _cx: &mut App) -> Task<anyhow::Result<()>> {
self._process_status_task.take();
self.request_tx.close_channel();

View file

@ -1,5 +1,5 @@
use futures::{channel::mpsc, SinkExt as _};
use gpui::{Task, View, WindowContext};
use gpui::{App, Entity, Task, Window};
use http_client::{AsyncBody, HttpClient, Request};
use jupyter_protocol::{ExecutionState, JupyterKernelspec, JupyterMessage, KernelInfoReply};
@ -137,8 +137,9 @@ impl RemoteRunningKernel {
pub fn new(
kernelspec: RemoteKernelSpecification,
working_directory: std::path::PathBuf,
session: View<Session>,
cx: &mut WindowContext,
session: Entity<Session>,
window: &mut Window,
cx: &mut App,
) -> Task<Result<Box<dyn RunningKernel>>> {
let remote_server = RemoteServer {
base_url: kernelspec.url,
@ -147,7 +148,7 @@ impl RemoteRunningKernel {
let http_client = cx.http_client();
cx.spawn(|cx| async move {
window.spawn(cx, |cx| async move {
let kernel_id = launch_remote_kernel(
&remote_server,
http_client.clone(),
@ -205,8 +206,8 @@ impl RemoteRunningKernel {
match message {
Ok(message) => {
session
.update(&mut cx, |session, cx| {
session.route(&message, cx);
.update_in(&mut cx, |session, window, cx| {
session.route(&message, window, cx);
})
.ok();
}
@ -273,14 +274,14 @@ impl RunningKernel for RemoteRunningKernel {
self.kernel_info = Some(info);
}
fn force_shutdown(&mut self, cx: &mut WindowContext) -> Task<anyhow::Result<()>> {
fn force_shutdown(&mut self, window: &mut Window, cx: &mut App) -> Task<anyhow::Result<()>> {
let url = self
.remote_server
.api_url(&format!("/kernels/{}", self.kernel_id));
let token = self.remote_server.token.clone();
let http_client = self.http_client.clone();
cx.spawn(|_| async move {
window.spawn(cx, |_| async move {
let request = Request::builder()
.method("DELETE")
.uri(&url)