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,7 +2,7 @@ use anyhow::{anyhow, Result};
|
|||
use extension::ExtensionHostProxy;
|
||||
use extension_host::headless_host::HeadlessExtensionStore;
|
||||
use fs::Fs;
|
||||
use gpui::{AppContext, AsyncAppContext, Context as _, Model, ModelContext, PromptLevel};
|
||||
use gpui::{App, AppContext as _, AsyncAppContext, Context, Entity, PromptLevel};
|
||||
use http_client::HttpClient;
|
||||
use language::{proto::serialize_operation, Buffer, BufferEvent, LanguageRegistry};
|
||||
use node_runtime::NodeRuntime;
|
||||
|
@ -32,14 +32,14 @@ use worktree::Worktree;
|
|||
pub struct HeadlessProject {
|
||||
pub fs: Arc<dyn Fs>,
|
||||
pub session: AnyProtoClient,
|
||||
pub worktree_store: Model<WorktreeStore>,
|
||||
pub buffer_store: Model<BufferStore>,
|
||||
pub lsp_store: Model<LspStore>,
|
||||
pub task_store: Model<TaskStore>,
|
||||
pub settings_observer: Model<SettingsObserver>,
|
||||
pub worktree_store: Entity<WorktreeStore>,
|
||||
pub buffer_store: Entity<BufferStore>,
|
||||
pub lsp_store: Entity<LspStore>,
|
||||
pub task_store: Entity<TaskStore>,
|
||||
pub settings_observer: Entity<SettingsObserver>,
|
||||
pub next_entry_id: Arc<AtomicUsize>,
|
||||
pub languages: Arc<LanguageRegistry>,
|
||||
pub extensions: Model<HeadlessExtensionStore>,
|
||||
pub extensions: Entity<HeadlessExtensionStore>,
|
||||
}
|
||||
|
||||
pub struct HeadlessAppState {
|
||||
|
@ -52,7 +52,7 @@ pub struct HeadlessAppState {
|
|||
}
|
||||
|
||||
impl HeadlessProject {
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
settings::init(cx);
|
||||
language::init(cx);
|
||||
project::Project::init_settings(cx);
|
||||
|
@ -67,22 +67,22 @@ impl HeadlessProject {
|
|||
languages,
|
||||
extension_host_proxy: proxy,
|
||||
}: HeadlessAppState,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
language_extension::init(proxy.clone(), languages.clone());
|
||||
languages::init(languages.clone(), node_runtime.clone(), cx);
|
||||
|
||||
let worktree_store = cx.new_model(|cx| {
|
||||
let worktree_store = cx.new(|cx| {
|
||||
let mut store = WorktreeStore::local(true, fs.clone());
|
||||
store.shared(SSH_PROJECT_ID, session.clone().into(), cx);
|
||||
store
|
||||
});
|
||||
let buffer_store = cx.new_model(|cx| {
|
||||
let buffer_store = cx.new(|cx| {
|
||||
let mut buffer_store = BufferStore::local(worktree_store.clone(), cx);
|
||||
buffer_store.shared(SSH_PROJECT_ID, session.clone().into(), cx);
|
||||
buffer_store
|
||||
});
|
||||
let prettier_store = cx.new_model(|cx| {
|
||||
let prettier_store = cx.new(|cx| {
|
||||
PrettierStore::new(
|
||||
node_runtime.clone(),
|
||||
fs.clone(),
|
||||
|
@ -92,7 +92,7 @@ impl HeadlessProject {
|
|||
)
|
||||
});
|
||||
let environment = project::ProjectEnvironment::new(&worktree_store, None, cx);
|
||||
let toolchain_store = cx.new_model(|cx| {
|
||||
let toolchain_store = cx.new(|cx| {
|
||||
ToolchainStore::local(
|
||||
languages.clone(),
|
||||
worktree_store.clone(),
|
||||
|
@ -101,7 +101,7 @@ impl HeadlessProject {
|
|||
)
|
||||
});
|
||||
|
||||
let task_store = cx.new_model(|cx| {
|
||||
let task_store = cx.new(|cx| {
|
||||
let mut task_store = TaskStore::local(
|
||||
fs.clone(),
|
||||
buffer_store.downgrade(),
|
||||
|
@ -113,7 +113,7 @@ impl HeadlessProject {
|
|||
task_store.shared(SSH_PROJECT_ID, session.clone().into(), cx);
|
||||
task_store
|
||||
});
|
||||
let settings_observer = cx.new_model(|cx| {
|
||||
let settings_observer = cx.new(|cx| {
|
||||
let mut observer = SettingsObserver::new_local(
|
||||
fs.clone(),
|
||||
worktree_store.clone(),
|
||||
|
@ -124,7 +124,7 @@ impl HeadlessProject {
|
|||
observer
|
||||
});
|
||||
|
||||
let lsp_store = cx.new_model(|cx| {
|
||||
let lsp_store = cx.new(|cx| {
|
||||
let mut lsp_store = LspStore::new_local(
|
||||
buffer_store.clone(),
|
||||
worktree_store.clone(),
|
||||
|
@ -166,7 +166,7 @@ impl HeadlessProject {
|
|||
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &worktree_store);
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &buffer_store);
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &cx.handle());
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &cx.model());
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &lsp_store);
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &task_store);
|
||||
session.subscribe_to_entity(SSH_PROJECT_ID, &toolchain_store);
|
||||
|
@ -220,9 +220,9 @@ impl HeadlessProject {
|
|||
|
||||
fn on_buffer_event(
|
||||
&mut self,
|
||||
buffer: Model<Buffer>,
|
||||
buffer: Entity<Buffer>,
|
||||
event: &BufferEvent,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
match event {
|
||||
BufferEvent::Operation {
|
||||
|
@ -242,9 +242,9 @@ impl HeadlessProject {
|
|||
|
||||
fn on_lsp_store_event(
|
||||
&mut self,
|
||||
_lsp_store: Model<LspStore>,
|
||||
_lsp_store: Entity<LspStore>,
|
||||
event: &LspStoreEvent,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
match event {
|
||||
LspStoreEvent::LanguageServerUpdate {
|
||||
|
@ -306,7 +306,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_add_worktree(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
message: TypedEnvelope<proto::AddWorktree>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::AddWorktreeResponse> {
|
||||
|
@ -379,7 +379,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_remove_worktree(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
envelope: TypedEnvelope<proto::RemoveWorktree>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::Ack> {
|
||||
|
@ -393,7 +393,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_open_buffer_by_path(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
message: TypedEnvelope<proto::OpenBufferByPath>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::OpenBufferResponse> {
|
||||
|
@ -426,7 +426,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_open_new_buffer(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
_message: TypedEnvelope<proto::OpenNewBuffer>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::OpenBufferResponse> {
|
||||
|
@ -452,7 +452,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_open_server_settings(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
_: TypedEnvelope<proto::OpenServerSettings>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::OpenBufferResponse> {
|
||||
|
@ -505,7 +505,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_find_search_candidates(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
envelope: TypedEnvelope<proto::FindSearchCandidates>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::FindSearchCandidatesResponse> {
|
||||
|
@ -541,7 +541,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_list_remote_directory(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
envelope: TypedEnvelope<proto::ListRemoteDirectory>,
|
||||
cx: AsyncAppContext,
|
||||
) -> Result<proto::ListRemoteDirectoryResponse> {
|
||||
|
@ -559,7 +559,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_get_path_metadata(
|
||||
this: Model<Self>,
|
||||
this: Entity<Self>,
|
||||
envelope: TypedEnvelope<proto::GetPathMetadata>,
|
||||
cx: AsyncAppContext,
|
||||
) -> Result<proto::GetPathMetadataResponse> {
|
||||
|
@ -577,7 +577,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_shutdown_remote_server(
|
||||
_this: Model<Self>,
|
||||
_this: Entity<Self>,
|
||||
_envelope: TypedEnvelope<proto::ShutdownRemoteServer>,
|
||||
cx: AsyncAppContext,
|
||||
) -> Result<proto::Ack> {
|
||||
|
@ -595,7 +595,7 @@ impl HeadlessProject {
|
|||
}
|
||||
|
||||
pub async fn handle_ping(
|
||||
_this: Model<Self>,
|
||||
_this: Entity<Self>,
|
||||
_envelope: TypedEnvelope<proto::Ping>,
|
||||
_cx: AsyncAppContext,
|
||||
) -> Result<proto::Ack> {
|
||||
|
|
|
@ -3,7 +3,7 @@ use client::{Client, UserStore};
|
|||
use clock::FakeSystemClock;
|
||||
use extension::ExtensionHostProxy;
|
||||
use fs::{FakeFs, Fs};
|
||||
use gpui::{Context, Model, SemanticVersion, TestAppContext};
|
||||
use gpui::{AppContext as _, Entity, SemanticVersion, TestAppContext};
|
||||
use http_client::{BlockedHttpClient, FakeHttpClient};
|
||||
use language::{
|
||||
language_settings::{language_settings, AllLanguageSettings},
|
||||
|
@ -186,7 +186,7 @@ async fn test_remote_project_search(cx: &mut TestAppContext, server_cx: &mut Tes
|
|||
|
||||
cx.run_until_parked();
|
||||
|
||||
async fn do_search(project: &Model<Project>, mut cx: TestAppContext) -> Model<Buffer> {
|
||||
async fn do_search(project: &Entity<Project>, mut cx: TestAppContext) -> Entity<Buffer> {
|
||||
let receiver = project.update(&mut cx, |project, cx| {
|
||||
project.search(
|
||||
SearchQuery::text(
|
||||
|
@ -1275,7 +1275,7 @@ pub async fn init_test(
|
|||
server_fs: &Arc<FakeFs>,
|
||||
cx: &mut TestAppContext,
|
||||
server_cx: &mut TestAppContext,
|
||||
) -> (Model<Project>, Model<HeadlessProject>) {
|
||||
) -> (Entity<Project>, Entity<HeadlessProject>) {
|
||||
let server_fs = server_fs.clone();
|
||||
cx.update(|cx| {
|
||||
release_channel::init(SemanticVersion::default(), cx);
|
||||
|
@ -1291,7 +1291,7 @@ pub async fn init_test(
|
|||
let languages = Arc::new(LanguageRegistry::new(cx.executor()));
|
||||
let proxy = Arc::new(ExtensionHostProxy::new());
|
||||
server_cx.update(HeadlessProject::init);
|
||||
let headless = server_cx.new_model(|cx| {
|
||||
let headless = server_cx.new(|cx| {
|
||||
client::init_settings(cx);
|
||||
|
||||
HeadlessProject::new(
|
||||
|
@ -1324,7 +1324,7 @@ fn init_logger() {
|
|||
}
|
||||
}
|
||||
|
||||
fn build_project(ssh: Model<SshRemoteClient>, cx: &mut TestAppContext) -> Model<Project> {
|
||||
fn build_project(ssh: Entity<SshRemoteClient>, cx: &mut TestAppContext) -> Entity<Project> {
|
||||
cx.update(|cx| {
|
||||
if !cx.has_global::<SettingsStore>() {
|
||||
let settings_store = SettingsStore::test(cx);
|
||||
|
@ -1341,7 +1341,7 @@ fn build_project(ssh: Model<SshRemoteClient>, cx: &mut TestAppContext) -> Model<
|
|||
});
|
||||
|
||||
let node = NodeRuntime::unavailable();
|
||||
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
|
||||
let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
|
||||
let languages = Arc::new(LanguageRegistry::test(cx.executor()));
|
||||
let fs = FakeFs::new(cx.executor());
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::headless_project::HeadlessAppState;
|
||||
use crate::HeadlessProject;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use chrono::Utc;
|
||||
use client::{telemetry, ProxySettings};
|
||||
use extension::ExtensionHostProxy;
|
||||
|
@ -8,7 +8,7 @@ use fs::{Fs, RealFs};
|
|||
use futures::channel::mpsc;
|
||||
use futures::{select, select_biased, AsyncRead, AsyncWrite, AsyncWriteExt, FutureExt, SinkExt};
|
||||
use git::GitHostingProviderRegistry;
|
||||
use gpui::{AppContext, Context as _, Model, ModelContext, SemanticVersion, UpdateGlobal as _};
|
||||
use gpui::{App, AppContext as _, Context, Entity, SemanticVersion, UpdateGlobal as _};
|
||||
use http_client::{read_proxy_from_env, Uri};
|
||||
use language::LanguageRegistry;
|
||||
use node_runtime::{NodeBinaryOptions, NodeRuntime};
|
||||
|
@ -189,7 +189,7 @@ fn init_panic_hook() {
|
|||
}));
|
||||
}
|
||||
|
||||
fn handle_panic_requests(project: &Model<HeadlessProject>, client: &Arc<ChannelClient>) {
|
||||
fn handle_panic_requests(project: &Entity<HeadlessProject>, client: &Arc<ChannelClient>) {
|
||||
let client: AnyProtoClient = client.clone().into();
|
||||
client.add_request_handler(
|
||||
project.downgrade(),
|
||||
|
@ -250,7 +250,7 @@ impl ServerListeners {
|
|||
fn start_server(
|
||||
listeners: ServerListeners,
|
||||
log_rx: Receiver<Vec<u8>>,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut App,
|
||||
) -> Arc<ChannelClient> {
|
||||
// This is the server idle timeout. If no connection comes in in this timeout, the server will shut down.
|
||||
const IDLE_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10 * 60);
|
||||
|
@ -421,7 +421,7 @@ pub fn execute_run(
|
|||
let listeners = ServerListeners::new(stdin_socket, stdout_socket, stderr_socket)?;
|
||||
|
||||
let git_hosting_provider_registry = Arc::new(GitHostingProviderRegistry::new());
|
||||
gpui::App::headless().run(move |cx| {
|
||||
gpui::Application::headless().run(move |cx| {
|
||||
settings::init(cx);
|
||||
let app_version = AppVersion::init(env!("ZED_PKG_VERSION"));
|
||||
release_channel::init(app_version, cx);
|
||||
|
@ -439,7 +439,7 @@ pub fn execute_run(
|
|||
extension::init(cx);
|
||||
let extension_host_proxy = ExtensionHostProxy::global(cx);
|
||||
|
||||
let project = cx.new_model(|cx| {
|
||||
let project = cx.new(|cx| {
|
||||
let fs = Arc::new(RealFs::new(Default::default(), None));
|
||||
let node_settings_rx = initialize_settings(session.clone(), fs.clone(), cx);
|
||||
|
||||
|
@ -740,7 +740,7 @@ async fn write_size_prefixed_buffer<S: AsyncWrite + Unpin>(
|
|||
fn initialize_settings(
|
||||
session: Arc<ChannelClient>,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut App,
|
||||
) -> async_watch::Receiver<Option<NodeBinaryOptions>> {
|
||||
let user_settings_file_rx = watch_config_file(
|
||||
&cx.background_executor(),
|
||||
|
@ -808,8 +808,8 @@ fn initialize_settings(
|
|||
|
||||
pub fn handle_settings_file_changes(
|
||||
mut server_settings_file: mpsc::UnboundedReceiver<String>,
|
||||
cx: &mut AppContext,
|
||||
settings_changed: impl Fn(Option<anyhow::Error>, &mut AppContext) + 'static,
|
||||
cx: &mut App,
|
||||
settings_changed: impl Fn(Option<anyhow::Error>, &mut App) + 'static,
|
||||
) {
|
||||
let server_settings_content = cx
|
||||
.background_executor()
|
||||
|
@ -828,7 +828,7 @@ pub fn handle_settings_file_changes(
|
|||
log::error!("Failed to load server settings: {err}");
|
||||
}
|
||||
settings_changed(result.err(), cx);
|
||||
cx.refresh();
|
||||
cx.refresh_windows();
|
||||
});
|
||||
if result.is_err() {
|
||||
break; // App dropped
|
||||
|
@ -838,7 +838,7 @@ pub fn handle_settings_file_changes(
|
|||
.detach();
|
||||
}
|
||||
|
||||
fn read_proxy_settings(cx: &mut ModelContext<'_, HeadlessProject>) -> Option<Uri> {
|
||||
fn read_proxy_settings(cx: &mut Context<'_, HeadlessProject>) -> Option<Uri> {
|
||||
let proxy_str = ProxySettings::get_global(cx).proxy.to_owned();
|
||||
let proxy_url = proxy_str
|
||||
.as_ref()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue