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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue