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
|
@ -2,11 +2,11 @@ use anyhow::Result;
|
|||
use async_recursion::async_recursion;
|
||||
use collections::HashSet;
|
||||
use futures::{stream::FuturesUnordered, StreamExt as _};
|
||||
use gpui::{AsyncWindowContext, Axis, Model, Task, View, WeakView};
|
||||
use gpui::{AppContext as _, AsyncWindowContext, Axis, Entity, Task, WeakEntity};
|
||||
use project::{terminals::TerminalKind, Project};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
use ui::{Pixels, ViewContext, VisualContext as _, WindowContext};
|
||||
use ui::{App, Context, Pixels, Window};
|
||||
use util::ResultExt as _;
|
||||
|
||||
use db::{define_connection, query, sqlez::statement::Statement, sqlez_macros::sql};
|
||||
|
@ -23,16 +23,16 @@ use crate::{
|
|||
|
||||
pub(crate) fn serialize_pane_group(
|
||||
pane_group: &PaneGroup,
|
||||
active_pane: &View<Pane>,
|
||||
cx: &WindowContext,
|
||||
active_pane: &Entity<Pane>,
|
||||
cx: &mut App,
|
||||
) -> SerializedPaneGroup {
|
||||
build_serialized_pane_group(&pane_group.root, active_pane, cx)
|
||||
}
|
||||
|
||||
fn build_serialized_pane_group(
|
||||
pane_group: &Member,
|
||||
active_pane: &View<Pane>,
|
||||
cx: &WindowContext,
|
||||
active_pane: &Entity<Pane>,
|
||||
cx: &mut App,
|
||||
) -> SerializedPaneGroup {
|
||||
match pane_group {
|
||||
Member::Axis(PaneAxis {
|
||||
|
@ -54,7 +54,7 @@ fn build_serialized_pane_group(
|
|||
}
|
||||
}
|
||||
|
||||
fn serialize_pane(pane: &View<Pane>, active: bool, cx: &WindowContext) -> SerializedPane {
|
||||
fn serialize_pane(pane: &Entity<Pane>, active: bool, cx: &mut App) -> SerializedPane {
|
||||
let mut items_to_serialize = HashSet::default();
|
||||
let pane = pane.read(cx);
|
||||
let children = pane
|
||||
|
@ -83,16 +83,17 @@ fn serialize_pane(pane: &View<Pane>, active: bool, cx: &WindowContext) -> Serial
|
|||
}
|
||||
|
||||
pub(crate) fn deserialize_terminal_panel(
|
||||
workspace: WeakView<Workspace>,
|
||||
project: Model<Project>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
project: Entity<Project>,
|
||||
database_id: WorkspaceId,
|
||||
serialized_panel: SerializedTerminalPanel,
|
||||
cx: &mut WindowContext,
|
||||
) -> Task<anyhow::Result<View<TerminalPanel>>> {
|
||||
cx.spawn(move |mut cx| async move {
|
||||
let terminal_panel = workspace.update(&mut cx, |workspace, cx| {
|
||||
cx.new_view(|cx| {
|
||||
let mut panel = TerminalPanel::new(workspace, cx);
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Task<anyhow::Result<Entity<TerminalPanel>>> {
|
||||
window.spawn(cx, move |mut cx| async move {
|
||||
let terminal_panel = workspace.update_in(&mut cx, |workspace, window, cx| {
|
||||
cx.new(|cx| {
|
||||
let mut panel = TerminalPanel::new(workspace, window, cx);
|
||||
panel.height = serialized_panel.height.map(|h| h.round());
|
||||
panel.width = serialized_panel.width.map(|w| w.round());
|
||||
panel
|
||||
|
@ -109,9 +110,9 @@ pub(crate) fn deserialize_terminal_panel(
|
|||
)
|
||||
.await;
|
||||
let active_item = serialized_panel.active_item_id;
|
||||
terminal_panel.update(&mut cx, |terminal_panel, cx| {
|
||||
terminal_panel.update_in(&mut cx, |terminal_panel, window, cx| {
|
||||
terminal_panel.active_pane.update(cx, |pane, cx| {
|
||||
populate_pane_items(pane, items, active_item, cx);
|
||||
populate_pane_items(pane, items, active_item, window, cx);
|
||||
});
|
||||
})?;
|
||||
}
|
||||
|
@ -141,9 +142,10 @@ pub(crate) fn deserialize_terminal_panel(
|
|||
|
||||
fn populate_pane_items(
|
||||
pane: &mut Pane,
|
||||
items: Vec<View<TerminalView>>,
|
||||
items: Vec<Entity<TerminalView>>,
|
||||
active_item: Option<u64>,
|
||||
cx: &mut ViewContext<Pane>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Pane>,
|
||||
) {
|
||||
let mut item_index = pane.items_len();
|
||||
let mut active_item_index = None;
|
||||
|
@ -151,23 +153,23 @@ fn populate_pane_items(
|
|||
if Some(item.item_id().as_u64()) == active_item {
|
||||
active_item_index = Some(item_index);
|
||||
}
|
||||
pane.add_item(Box::new(item), false, false, None, cx);
|
||||
pane.add_item(Box::new(item), false, false, None, window, cx);
|
||||
item_index += 1;
|
||||
}
|
||||
if let Some(index) = active_item_index {
|
||||
pane.activate_item(index, false, false, cx);
|
||||
pane.activate_item(index, false, false, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
#[async_recursion(?Send)]
|
||||
async fn deserialize_pane_group(
|
||||
workspace: WeakView<Workspace>,
|
||||
project: Model<Project>,
|
||||
panel: View<TerminalPanel>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
project: Entity<Project>,
|
||||
panel: Entity<TerminalPanel>,
|
||||
workspace_id: WorkspaceId,
|
||||
serialized: &SerializedPaneGroup,
|
||||
cx: &mut AsyncWindowContext,
|
||||
) -> Option<(Member, Option<View<Pane>>)> {
|
||||
) -> Option<(Member, Option<Entity<Pane>>)> {
|
||||
match serialized {
|
||||
SerializedPaneGroup::Group {
|
||||
axis,
|
||||
|
@ -217,11 +219,12 @@ async fn deserialize_pane_group(
|
|||
.await;
|
||||
|
||||
let pane = panel
|
||||
.update(cx, |terminal_panel, cx| {
|
||||
.update_in(cx, |terminal_panel, window, cx| {
|
||||
new_terminal_pane(
|
||||
workspace.clone(),
|
||||
project.clone(),
|
||||
terminal_panel.active_pane.read(cx).is_zoomed(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
|
@ -229,8 +232,8 @@ async fn deserialize_pane_group(
|
|||
let active_item = serialized_pane.active_item;
|
||||
|
||||
let terminal = pane
|
||||
.update(cx, |pane, cx| {
|
||||
populate_pane_items(pane, new_items, active_item, cx);
|
||||
.update_in(cx, |pane, window, cx| {
|
||||
populate_pane_items(pane, new_items, active_item, window, cx);
|
||||
// Avoid blank panes in splits
|
||||
if pane.items_len() == 0 {
|
||||
let working_directory = workspace
|
||||
|
@ -240,7 +243,7 @@ async fn deserialize_pane_group(
|
|||
let kind = TerminalKind::Shell(
|
||||
working_directory.as_deref().map(Path::to_path_buf),
|
||||
);
|
||||
let window = cx.window_handle();
|
||||
let window = window.window_handle();
|
||||
let terminal = project
|
||||
.update(cx, |project, cx| project.create_terminal(kind, window, cx));
|
||||
Some(Some(terminal))
|
||||
|
@ -252,17 +255,18 @@ async fn deserialize_pane_group(
|
|||
.flatten()?;
|
||||
if let Some(terminal) = terminal {
|
||||
let terminal = terminal.await.ok()?;
|
||||
pane.update(cx, |pane, cx| {
|
||||
let terminal_view = Box::new(cx.new_view(|cx| {
|
||||
pane.update_in(cx, |pane, window, cx| {
|
||||
let terminal_view = Box::new(cx.new(|cx| {
|
||||
TerminalView::new(
|
||||
terminal,
|
||||
workspace.clone(),
|
||||
Some(workspace_id),
|
||||
project.downgrade(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
}));
|
||||
pane.add_item(terminal_view, true, false, None, cx);
|
||||
pane.add_item(terminal_view, true, false, None, window, cx);
|
||||
})
|
||||
.ok()?;
|
||||
}
|
||||
|
@ -273,21 +277,22 @@ async fn deserialize_pane_group(
|
|||
|
||||
async fn deserialize_terminal_views(
|
||||
workspace_id: WorkspaceId,
|
||||
project: Model<Project>,
|
||||
workspace: WeakView<Workspace>,
|
||||
project: Entity<Project>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
item_ids: &[u64],
|
||||
cx: &mut AsyncWindowContext,
|
||||
) -> Vec<View<TerminalView>> {
|
||||
) -> Vec<Entity<TerminalView>> {
|
||||
let mut items = Vec::with_capacity(item_ids.len());
|
||||
let mut deserialized_items = item_ids
|
||||
.iter()
|
||||
.map(|item_id| {
|
||||
cx.update(|cx| {
|
||||
cx.update(|window, cx| {
|
||||
TerminalView::deserialize(
|
||||
project.clone(),
|
||||
workspace.clone(),
|
||||
workspace_id,
|
||||
*item_id,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue