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

@ -58,9 +58,9 @@ async fn test_toggle_through_settings(cx: &mut gpui::TestAppContext) {
// Selections aren't changed if editor is blurred but vim-mode is still disabled.
cx.cx.set_state("«hjklˇ»");
cx.assert_editor_state("«hjklˇ»");
cx.update_editor(|_, cx| cx.blur());
cx.update_editor(|_, window, _cx| window.blur());
cx.assert_editor_state("«hjklˇ»");
cx.update_editor(|_, cx| cx.focus_self());
cx.update_editor(|_, window, cx| cx.focus_self(window));
cx.assert_editor_state("«hjklˇ»");
// Enabling dynamically sets vim mode again and restores normal mode
@ -116,7 +116,7 @@ async fn test_buffer_search(cx: &mut gpui::TestAppContext) {
);
cx.simulate_keystrokes("/");
let search_bar = cx.workspace(|workspace, cx| {
let search_bar = cx.workspace(|workspace, _, cx| {
workspace
.active_pane()
.read(cx)
@ -126,7 +126,7 @@ async fn test_buffer_search(cx: &mut gpui::TestAppContext) {
.expect("Buffer search bar should be deployed")
});
cx.update_view(search_bar, |bar, cx| {
cx.update_model(search_bar, |bar, _, cx| {
assert_eq!(bar.query(cx), "");
})
}
@ -229,10 +229,12 @@ async fn test_escape_command_palette(cx: &mut gpui::TestAppContext) {
cx.set_state("aˇbc\n", Mode::Normal);
cx.simulate_keystrokes("i cmd-shift-p");
assert!(cx.workspace(|workspace, cx| workspace.active_modal::<CommandPalette>(cx).is_some()));
assert!(cx.workspace(|workspace, _, cx| workspace.active_modal::<CommandPalette>(cx).is_some()));
cx.simulate_keystrokes("escape");
cx.run_until_parked();
assert!(!cx.workspace(|workspace, cx| workspace.active_modal::<CommandPalette>(cx).is_some()));
assert!(
!cx.workspace(|workspace, _, cx| workspace.active_modal::<CommandPalette>(cx).is_some())
);
cx.assert_state("aˇbc\n", Mode::Insert);
}
@ -253,7 +255,7 @@ async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {
cx.set_state(indoc! {"aa\nbˇb\ncc\ncc\ncc\n"}, Mode::Normal);
cx.simulate_keystrokes("/ c c");
let search_bar = cx.workspace(|workspace, cx| {
let search_bar = cx.workspace(|workspace, _, cx| {
workspace
.active_pane()
.read(cx)
@ -263,12 +265,12 @@ async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {
.expect("Buffer search bar should be deployed")
});
cx.update_view(search_bar, |bar, cx| {
cx.update_model(search_bar, |bar, _, cx| {
assert_eq!(bar.query(cx), "cc");
});
cx.update_editor(|editor, cx| {
let highlights = editor.all_text_background_highlights(cx);
cx.update_editor(|editor, window, cx| {
let highlights = editor.all_text_background_highlights(window, cx);
assert_eq!(3, highlights.len());
assert_eq!(
DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 2),
@ -843,7 +845,7 @@ async fn test_select_all_issue_2170(cx: &mut gpui::TestAppContext) {
async fn test_jk(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"j k",
NormalBefore,
@ -861,7 +863,7 @@ async fn test_jk(cx: &mut gpui::TestAppContext) {
async fn test_jk_delay(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"j k",
NormalBefore,
@ -885,7 +887,7 @@ async fn test_jk_delay(cx: &mut gpui::TestAppContext) {
async fn test_comma_w(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
", w",
motion::Down {
@ -952,7 +954,7 @@ async fn test_remap(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
// test moving the cursor
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"g z",
workspace::SendKeystrokes("l l l l".to_string()),
@ -964,7 +966,7 @@ async fn test_remap(cx: &mut gpui::TestAppContext) {
cx.assert_state("1234ˇ56789", Mode::Normal);
// test switching modes
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"g y",
workspace::SendKeystrokes("i f o o escape l".to_string()),
@ -976,7 +978,7 @@ async fn test_remap(cx: &mut gpui::TestAppContext) {
cx.assert_state("fooˇ123456789", Mode::Normal);
// test recursion
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"g x",
workspace::SendKeystrokes("g z g y".to_string()),
@ -990,7 +992,7 @@ async fn test_remap(cx: &mut gpui::TestAppContext) {
cx.executor().allow_parking();
// test command
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"g w",
workspace::SendKeystrokes(": j enter".to_string()),
@ -1002,7 +1004,7 @@ async fn test_remap(cx: &mut gpui::TestAppContext) {
cx.assert_state("1234ˇ 56789", Mode::Normal);
// test leaving command
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"g u",
workspace::SendKeystrokes("g w g z".to_string()),
@ -1014,7 +1016,7 @@ async fn test_remap(cx: &mut gpui::TestAppContext) {
cx.assert_state("1234 567ˇ89", Mode::Normal);
// test leaving command
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"g t",
workspace::SendKeystrokes("i space escape".to_string()),
@ -1341,7 +1343,7 @@ async fn test_find_multibyte(cx: &mut gpui::TestAppContext) {
async fn test_sneak(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
cx.update(|cx| {
cx.update(|_window, cx| {
cx.bind_keys([
KeyBinding::new(
"s",
@ -1437,7 +1439,7 @@ async fn test_command_alias(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_remap_adjacent_dog_cat(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([
KeyBinding::new(
"d o g",
@ -1470,7 +1472,7 @@ async fn test_remap_adjacent_dog_cat(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_remap_nested_pineapple(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([
KeyBinding::new(
"p i n",
@ -1513,7 +1515,7 @@ async fn test_remap_nested_pineapple(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_remap_recursion(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"x",
workspace::SendKeystrokes("\" _ x".to_string()),
@ -1547,7 +1549,7 @@ async fn test_escape_while_waiting(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_ctrl_w_override(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new("ctrl-w", DeleteLine, None)]);
});
cx.neovim.exec("map <c-w> D").await;