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
|
@ -19,9 +19,9 @@ use fs::{Fs, RealFs};
|
|||
use futures::{future, StreamExt};
|
||||
use git::GitHostingProviderRegistry;
|
||||
use gpui::{
|
||||
Action, App, AppContext, AsyncAppContext, Context, DismissEvent, UpdateGlobal as _,
|
||||
VisualContext,
|
||||
Action, App, AppContext as _, Application, AsyncAppContext, DismissEvent, UpdateGlobal as _,
|
||||
};
|
||||
|
||||
use http_client::{read_proxy_from_env, Uri};
|
||||
use language::LanguageRegistry;
|
||||
use log::LevelFilter;
|
||||
|
@ -102,22 +102,23 @@ fn files_not_created_on_launch(errors: HashMap<io::ErrorKind, Vec<&Path>>) {
|
|||
.collect::<Vec<_>>().join("\n\n");
|
||||
|
||||
eprintln!("{message}: {error_details}");
|
||||
App::new().run(move |cx| {
|
||||
if let Ok(window) = cx.open_window(gpui::WindowOptions::default(), |cx| {
|
||||
cx.new_view(|_| gpui::Empty)
|
||||
Application::new().run(move |cx| {
|
||||
if let Ok(window) = cx.open_window(gpui::WindowOptions::default(), |_, cx| {
|
||||
cx.new(|_| gpui::Empty)
|
||||
}) {
|
||||
window
|
||||
.update(cx, |_, cx| {
|
||||
let response = cx.prompt(
|
||||
.update(cx, |_, window, cx| {
|
||||
let response = window.prompt(
|
||||
gpui::PromptLevel::Critical,
|
||||
message,
|
||||
Some(&error_details),
|
||||
&["Exit"],
|
||||
cx,
|
||||
);
|
||||
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.spawn_in(window, |_, mut cx| async move {
|
||||
response.await?;
|
||||
cx.update(|cx| cx.quit())
|
||||
cx.update(|_, cx| cx.quit())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
})
|
||||
|
@ -132,7 +133,7 @@ fn fail_to_open_window_async(e: anyhow::Error, cx: &mut AsyncAppContext) {
|
|||
cx.update(|cx| fail_to_open_window(e, cx)).log_err();
|
||||
}
|
||||
|
||||
fn fail_to_open_window(e: anyhow::Error, _cx: &mut AppContext) {
|
||||
fn fail_to_open_window(e: anyhow::Error, _cx: &mut App) {
|
||||
eprintln!(
|
||||
"Zed failed to open a window: {e:?}. See https://zed.dev/docs/linux for troubleshooting steps."
|
||||
);
|
||||
|
@ -188,7 +189,7 @@ fn main() {
|
|||
|
||||
log::info!("========== starting zed ==========");
|
||||
|
||||
let app = App::new().with_assets(Assets);
|
||||
let app = Application::new().with_assets(Assets);
|
||||
|
||||
let system_id = app.background_executor().block(system_id()).ok();
|
||||
let installation_id = app.background_executor().block(installation_id()).ok();
|
||||
|
@ -359,8 +360,8 @@ fn main() {
|
|||
language::init(cx);
|
||||
language_extension::init(extension_host_proxy.clone(), languages.clone());
|
||||
languages::init(languages.clone(), node_runtime.clone(), cx);
|
||||
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
|
||||
let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
|
||||
let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
|
||||
let workspace_store = cx.new(|cx| WorkspaceStore::new(client.clone(), cx));
|
||||
|
||||
Client::set_global(client.clone(), cx);
|
||||
|
||||
|
@ -390,7 +391,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
let app_session = cx.new_model(|cx| AppSession::new(session, cx));
|
||||
let app_session = cx.new(|cx| AppSession::new(session, cx));
|
||||
|
||||
let app_state = Arc::new(AppState {
|
||||
languages: languages.clone(),
|
||||
|
@ -522,8 +523,8 @@ fn main() {
|
|||
for &mut window in cx.windows().iter_mut() {
|
||||
let background_appearance = cx.theme().window_background_appearance();
|
||||
window
|
||||
.update(cx, |_, cx| {
|
||||
cx.set_background_appearance(background_appearance)
|
||||
.update(cx, |_, window, _| {
|
||||
window.set_background_appearance(background_appearance)
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
@ -615,13 +616,13 @@ fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
|
||||
fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut App) {
|
||||
struct SettingsParseErrorNotification;
|
||||
let id = NotificationId::unique::<SettingsParseErrorNotification>();
|
||||
|
||||
for workspace in workspace::local_workspace_windows(cx) {
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
match error.as_ref() {
|
||||
Some(error) => {
|
||||
if let Some(InvalidSettingsError::LocalSettings { .. }) =
|
||||
|
@ -630,13 +631,16 @@ fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
|
|||
// Local settings will be displayed by the projects
|
||||
} else {
|
||||
workspace.show_notification(id.clone(), cx, |cx| {
|
||||
cx.new_view(|_| {
|
||||
cx.new(|_cx| {
|
||||
MessageNotification::new(format!(
|
||||
"Invalid user settings file\n{error}"
|
||||
))
|
||||
.with_click_message("Open settings file")
|
||||
.on_click(|cx| {
|
||||
cx.dispatch_action(zed_actions::OpenSettings.boxed_clone());
|
||||
.on_click(|window, cx| {
|
||||
window.dispatch_action(
|
||||
zed_actions::OpenSettings.boxed_clone(),
|
||||
cx,
|
||||
);
|
||||
cx.emit(DismissEvent);
|
||||
})
|
||||
})
|
||||
|
@ -650,7 +654,7 @@ fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||
fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut App) {
|
||||
if let Some(connection) = request.cli_connection {
|
||||
let app_state = app_state.clone();
|
||||
cx.spawn(move |cx| handle_cli_connection(connection, app_state, cx))
|
||||
|
@ -722,15 +726,16 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
|
|||
|
||||
let workspace_window =
|
||||
workspace::get_any_active_workspace(app_state, cx.clone()).await?;
|
||||
let workspace = workspace_window.root_view(&cx)?;
|
||||
let workspace = workspace_window.root_model(&cx)?;
|
||||
|
||||
let mut promises = Vec::new();
|
||||
for (channel_id, heading) in request.open_channel_notes {
|
||||
promises.push(cx.update_window(workspace_window.into(), |_, cx| {
|
||||
promises.push(cx.update_window(workspace_window.into(), |_, window, cx| {
|
||||
ChannelView::open(
|
||||
client::ChannelId(channel_id),
|
||||
heading,
|
||||
workspace.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
.log_err()
|
||||
|
@ -853,9 +858,14 @@ async fn restore_or_create_workspace(
|
|||
cx.update(|cx| show_welcome_view(app_state, cx))?.await?;
|
||||
} else {
|
||||
cx.update(|cx| {
|
||||
workspace::open_new(Default::default(), app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
workspace::open_new(
|
||||
Default::default(),
|
||||
app_state,
|
||||
cx,
|
||||
|workspace, window, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), window, cx)
|
||||
},
|
||||
)
|
||||
})?
|
||||
.await?;
|
||||
}
|
||||
|
@ -1053,7 +1063,7 @@ impl ToString for IdType {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_url_arg(arg: &str, cx: &AppContext) -> Result<String> {
|
||||
fn parse_url_arg(arg: &str, cx: &App) -> Result<String> {
|
||||
match std::fs::canonicalize(Path::new(&arg)) {
|
||||
Ok(path) => Ok(format!("file://{}", path.display())),
|
||||
Err(error) => {
|
||||
|
@ -1070,7 +1080,7 @@ fn parse_url_arg(arg: &str, cx: &AppContext) -> Result<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_embedded_fonts(cx: &AppContext) {
|
||||
fn load_embedded_fonts(cx: &App) {
|
||||
let asset_source = cx.asset_source();
|
||||
let font_paths = asset_source.list("fonts").unwrap();
|
||||
let embedded_fonts = Mutex::new(Vec::new());
|
||||
|
@ -1095,7 +1105,7 @@ fn load_embedded_fonts(cx: &AppContext) {
|
|||
}
|
||||
|
||||
/// Spawns a background task to load the user themes from the themes directory.
|
||||
fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||
fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
cx.spawn({
|
||||
let fs = fs.clone();
|
||||
|cx| async move {
|
||||
|
@ -1129,7 +1139,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
/// Spawns a background task to watch the themes directory for changes.
|
||||
fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||
fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
use std::time::Duration;
|
||||
cx.spawn(|cx| async move {
|
||||
let (mut events, _) = fs
|
||||
|
@ -1158,7 +1168,7 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &mut AppContext) {
|
||||
fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &mut App) {
|
||||
use std::time::Duration;
|
||||
|
||||
let path = {
|
||||
|
@ -1188,10 +1198,10 @@ fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &m
|
|||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn watch_languages(_fs: Arc<dyn fs::Fs>, _languages: Arc<LanguageRegistry>, _cx: &mut AppContext) {}
|
||||
fn watch_languages(_fs: Arc<dyn fs::Fs>, _languages: Arc<LanguageRegistry>, _cx: &mut App) {}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||
fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
use std::time::Duration;
|
||||
|
||||
use file_icons::FileIcons;
|
||||
|
@ -1220,4 +1230,4 @@ fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut AppContext) {}
|
||||
fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut App) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue