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
|
@ -1,4 +1,4 @@
|
|||
use gpui::{px, size, Context, UpdateGlobal};
|
||||
use gpui::{px, size, AppContext as _, UpdateGlobal};
|
||||
use indoc::indoc;
|
||||
use settings::SettingsStore;
|
||||
use std::{
|
||||
|
@ -222,7 +222,7 @@ impl NeovimBackedTestContext {
|
|||
.set_option(&format!("columns={}", columns))
|
||||
.await;
|
||||
|
||||
self.update(|cx| {
|
||||
self.update(|_, cx| {
|
||||
SettingsStore::update_global(cx, |settings, cx| {
|
||||
settings.update_user_settings::<AllLanguageSettings>(cx, |settings| {
|
||||
settings.defaults.soft_wrap = Some(SoftWrap::PreferredLineLength);
|
||||
|
@ -237,21 +237,21 @@ impl NeovimBackedTestContext {
|
|||
self.neovim.set_option(&format!("scrolloff={}", 3)).await;
|
||||
// +2 to account for the vim command UI at the bottom.
|
||||
self.neovim.set_option(&format!("lines={}", rows + 2)).await;
|
||||
let (line_height, visible_line_count) = self.editor(|editor, cx| {
|
||||
let (line_height, visible_line_count) = self.editor(|editor, window, _cx| {
|
||||
(
|
||||
editor
|
||||
.style()
|
||||
.unwrap()
|
||||
.text
|
||||
.line_height_in_pixels(cx.rem_size()),
|
||||
.line_height_in_pixels(window.rem_size()),
|
||||
editor.visible_line_count().unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let window = self.window;
|
||||
let margin = self
|
||||
.update_window(window, |_, cx| {
|
||||
cx.viewport_size().height - line_height * visible_line_count
|
||||
.update_window(window, |_, window, _cx| {
|
||||
window.viewport_size().height - line_height * visible_line_count
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
|
@ -286,7 +286,7 @@ impl NeovimBackedTestContext {
|
|||
register,
|
||||
state: self.shared_state().await,
|
||||
neovim: self.neovim.read_register(register).await,
|
||||
editor: self.update(|cx| {
|
||||
editor: self.update(|_, cx| {
|
||||
cx.global::<VimGlobals>()
|
||||
.registers
|
||||
.get(®ister)
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut};
|
|||
|
||||
use assets::Assets;
|
||||
use editor::test::editor_lsp_test_context::EditorLspTestContext;
|
||||
use gpui::{Context, SemanticVersion, UpdateGlobal, View, VisualContext};
|
||||
use gpui::{Context, Entity, SemanticVersion, UpdateGlobal};
|
||||
use search::{project_search::ProjectSearchBar, BufferSearchBar};
|
||||
|
||||
use crate::{state::Operator, *};
|
||||
|
@ -57,7 +57,7 @@ impl VimTestContext {
|
|||
}
|
||||
|
||||
pub fn new_with_lsp(mut cx: EditorLspTestContext, enabled: bool) -> VimTestContext {
|
||||
cx.update(|cx| {
|
||||
cx.update(|_, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store.update_user_settings::<VimModeSetting>(cx, |s| *s = Some(enabled));
|
||||
});
|
||||
|
@ -75,44 +75,46 @@ impl VimTestContext {
|
|||
});
|
||||
|
||||
// Setup search toolbars and keypress hook
|
||||
cx.update_workspace(|workspace, cx| {
|
||||
cx.update_workspace(|workspace, window, cx| {
|
||||
workspace.active_pane().update(cx, |pane, cx| {
|
||||
pane.toolbar().update(cx, |toolbar, cx| {
|
||||
let buffer_search_bar = cx.new_view(BufferSearchBar::new);
|
||||
toolbar.add_item(buffer_search_bar, cx);
|
||||
let buffer_search_bar = cx.new(|cx| BufferSearchBar::new(window, cx));
|
||||
toolbar.add_item(buffer_search_bar, window, cx);
|
||||
|
||||
let project_search_bar = cx.new_view(|_| ProjectSearchBar::new());
|
||||
toolbar.add_item(project_search_bar, cx);
|
||||
let project_search_bar = cx.new(|_| ProjectSearchBar::new());
|
||||
toolbar.add_item(project_search_bar, window, cx);
|
||||
})
|
||||
});
|
||||
workspace.status_bar().update(cx, |status_bar, cx| {
|
||||
let vim_mode_indicator = cx.new_view(ModeIndicator::new);
|
||||
status_bar.add_right_item(vim_mode_indicator, cx);
|
||||
let vim_mode_indicator = cx.new(|cx| ModeIndicator::new(window, cx));
|
||||
status_bar.add_right_item(vim_mode_indicator, window, cx);
|
||||
});
|
||||
});
|
||||
|
||||
Self { cx }
|
||||
}
|
||||
|
||||
pub fn update_view<F, T, R>(&mut self, view: View<T>, update: F) -> R
|
||||
pub fn update_model<F, T, R>(&mut self, model: Entity<T>, update: F) -> R
|
||||
where
|
||||
T: 'static,
|
||||
F: FnOnce(&mut T, &mut ViewContext<T>) -> R + 'static,
|
||||
F: FnOnce(&mut T, &mut Window, &mut Context<T>) -> R + 'static,
|
||||
{
|
||||
let window = self.window;
|
||||
self.update_window(window, move |_, cx| view.update(cx, update))
|
||||
.unwrap()
|
||||
self.update_window(window, move |_, window, cx| {
|
||||
model.update(cx, |t, cx| update(t, window, cx))
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn workspace<F, T>(&mut self, update: F) -> T
|
||||
where
|
||||
F: FnOnce(&mut Workspace, &mut ViewContext<Workspace>) -> T,
|
||||
F: FnOnce(&mut Workspace, &mut Window, &mut Context<Workspace>) -> T,
|
||||
{
|
||||
self.cx.update_workspace(update)
|
||||
}
|
||||
|
||||
pub fn enable_vim(&mut self) {
|
||||
self.cx.update(|cx| {
|
||||
self.cx.update(|_, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store.update_user_settings::<VimModeSetting>(cx, |s| *s = Some(true));
|
||||
});
|
||||
|
@ -120,7 +122,7 @@ impl VimTestContext {
|
|||
}
|
||||
|
||||
pub fn disable_vim(&mut self) {
|
||||
self.cx.update(|cx| {
|
||||
self.cx.update(|_, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store.update_user_settings::<VimModeSetting>(cx, |s| *s = Some(false));
|
||||
});
|
||||
|
@ -128,15 +130,15 @@ impl VimTestContext {
|
|||
}
|
||||
|
||||
pub fn mode(&mut self) -> Mode {
|
||||
self.update_editor(|editor, cx| editor.addon::<VimAddon>().unwrap().view.read(cx).mode)
|
||||
self.update_editor(|editor, _, cx| editor.addon::<VimAddon>().unwrap().model.read(cx).mode)
|
||||
}
|
||||
|
||||
pub fn active_operator(&mut self) -> Option<Operator> {
|
||||
self.update_editor(|editor, cx| {
|
||||
self.update_editor(|editor, _, cx| {
|
||||
editor
|
||||
.addon::<VimAddon>()
|
||||
.unwrap()
|
||||
.view
|
||||
.model
|
||||
.read(cx)
|
||||
.operator_stack
|
||||
.last()
|
||||
|
@ -146,11 +148,12 @@ impl VimTestContext {
|
|||
|
||||
pub fn set_state(&mut self, text: &str, mode: Mode) {
|
||||
self.cx.set_state(text);
|
||||
let vim = self.update_editor(|editor, _cx| editor.addon::<VimAddon>().cloned().unwrap());
|
||||
let vim =
|
||||
self.update_editor(|editor, _window, _cx| editor.addon::<VimAddon>().cloned().unwrap());
|
||||
|
||||
self.update(|cx| {
|
||||
vim.view.update(cx, |vim, cx| {
|
||||
vim.switch_mode(mode, true, cx);
|
||||
self.update(|window, cx| {
|
||||
vim.model.update(cx, |vim, cx| {
|
||||
vim.switch_mode(mode, true, window, cx);
|
||||
});
|
||||
});
|
||||
self.cx.cx.cx.run_until_parked();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue