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
|
@ -311,7 +311,7 @@ async fn get_cached_server_binary(container_dir: PathBuf) -> Option<LanguageServ
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{BorrowAppContext, Context, TestAppContext};
|
||||
use gpui::{AppContext as _, BorrowAppContext, TestAppContext};
|
||||
use language::{language_settings::AllLanguageSettings, AutoindentMode, Buffer};
|
||||
use settings::SettingsStore;
|
||||
use std::num::NonZeroU32;
|
||||
|
@ -331,7 +331,7 @@ mod tests {
|
|||
});
|
||||
let language = crate::language("c", tree_sitter_c::LANGUAGE.into());
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("", cx).with_language(language, cx);
|
||||
|
||||
// empty function
|
||||
|
|
|
@ -151,7 +151,7 @@ async fn get_cached_server_binary(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{Context, TestAppContext};
|
||||
use gpui::{AppContext as _, TestAppContext};
|
||||
use unindent::Unindent;
|
||||
|
||||
#[gpui::test]
|
||||
|
@ -183,8 +183,7 @@ mod tests {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| language::Buffer::local(text, cx).with_language(language, cx));
|
||||
let buffer = cx.new(|cx| language::Buffer::local(text, cx).with_language(language, cx));
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None).unwrap());
|
||||
assert_eq!(
|
||||
outline
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use async_trait::async_trait;
|
||||
use collections::HashMap;
|
||||
use futures::StreamExt;
|
||||
use gpui::{AppContext, AsyncAppContext, Task};
|
||||
use gpui::{App, AsyncAppContext, Task};
|
||||
use http_client::github::latest_github_release;
|
||||
pub use language::*;
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
|
@ -443,7 +443,7 @@ impl ContextProvider for GoContextProvider {
|
|||
location: &Location,
|
||||
_: Option<HashMap<String, String>>,
|
||||
_: Arc<dyn LanguageToolchainStore>,
|
||||
cx: &mut gpui::AppContext,
|
||||
cx: &mut gpui::App,
|
||||
) -> Task<Result<TaskVariables>> {
|
||||
let local_abs_path = location
|
||||
.buffer
|
||||
|
@ -506,7 +506,7 @@ impl ContextProvider for GoContextProvider {
|
|||
fn associated_tasks(
|
||||
&self,
|
||||
_: Option<Arc<dyn language::File>>,
|
||||
_: &AppContext,
|
||||
_: &App,
|
||||
) -> Option<TaskTemplates> {
|
||||
let package_cwd = if GO_PACKAGE_TASK_VARIABLE.template_value() == "." {
|
||||
None
|
||||
|
|
|
@ -4,7 +4,7 @@ use async_tar::Archive;
|
|||
use async_trait::async_trait;
|
||||
use collections::HashMap;
|
||||
use futures::StreamExt;
|
||||
use gpui::{AppContext, AsyncAppContext};
|
||||
use gpui::{App, AsyncAppContext};
|
||||
use http_client::github::{latest_github_release, GitHubLspBinaryVersion};
|
||||
use language::{LanguageRegistry, LanguageToolchainStore, LspAdapter, LspAdapterDelegate};
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
|
@ -74,7 +74,7 @@ impl JsonLspAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_workspace_config(language_names: Vec<String>, cx: &mut AppContext) -> Value {
|
||||
fn get_workspace_config(language_names: Vec<String>, cx: &mut App) -> Value {
|
||||
let keymap_schema = KeymapFile::generate_json_schema_for_registered_actions(cx);
|
||||
let font_names = &cx.text_system().all_font_names();
|
||||
let settings_schema = cx.global::<SettingsStore>().json_schema(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Context;
|
||||
use gpui::{AppContext, UpdateGlobal};
|
||||
use anyhow::Context as _;
|
||||
use gpui::{App, UpdateGlobal};
|
||||
use json::json_task_context;
|
||||
pub use language::*;
|
||||
use lsp::LanguageServerName;
|
||||
|
@ -31,7 +31,7 @@ mod yaml;
|
|||
#[exclude = "*.rs"]
|
||||
struct LanguageDir;
|
||||
|
||||
pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mut AppContext) {
|
||||
pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mut App) {
|
||||
#[cfg(feature = "load-grammars")]
|
||||
languages.register_native_grammars([
|
||||
("bash", tree_sitter_bash::LANGUAGE),
|
||||
|
|
|
@ -2,7 +2,7 @@ use anyhow::ensure;
|
|||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use collections::HashMap;
|
||||
use gpui::{AppContext, Task};
|
||||
use gpui::{App, Task};
|
||||
use gpui::{AsyncAppContext, SharedString};
|
||||
use language::language_settings::language_settings;
|
||||
use language::LanguageName;
|
||||
|
@ -317,7 +317,7 @@ impl ContextProvider for PythonContextProvider {
|
|||
location: &project::Location,
|
||||
_: Option<HashMap<String, String>>,
|
||||
toolchains: Arc<dyn LanguageToolchainStore>,
|
||||
cx: &mut gpui::AppContext,
|
||||
cx: &mut gpui::App,
|
||||
) -> Task<Result<task::TaskVariables>> {
|
||||
let test_target = {
|
||||
let test_runner = selected_test_runner(location.buffer.read(cx).file(), cx);
|
||||
|
@ -350,7 +350,7 @@ impl ContextProvider for PythonContextProvider {
|
|||
fn associated_tasks(
|
||||
&self,
|
||||
file: Option<Arc<dyn language::File>>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<TaskTemplates> {
|
||||
let test_runner = selected_test_runner(file.as_ref(), cx);
|
||||
|
||||
|
@ -441,7 +441,7 @@ impl ContextProvider for PythonContextProvider {
|
|||
}
|
||||
}
|
||||
|
||||
fn selected_test_runner(location: Option<&Arc<dyn language::File>>, cx: &AppContext) -> TestRunner {
|
||||
fn selected_test_runner(location: Option<&Arc<dyn language::File>>, cx: &App) -> TestRunner {
|
||||
const TEST_RUNNER_VARIABLE: &str = "TEST_RUNNER";
|
||||
language_settings(Some(LanguageName::new("Python")), location, cx)
|
||||
.tasks
|
||||
|
@ -1005,7 +1005,7 @@ impl LspAdapter for PyLspAdapter {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{BorrowAppContext, Context, ModelContext, TestAppContext};
|
||||
use gpui::{AppContext as _, BorrowAppContext, Context, TestAppContext};
|
||||
use language::{language_settings::AllLanguageSettings, AutoindentMode, Buffer};
|
||||
use settings::SettingsStore;
|
||||
use std::num::NonZeroU32;
|
||||
|
@ -1025,9 +1025,9 @@ mod tests {
|
|||
});
|
||||
});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("", cx).with_language(language, cx);
|
||||
let append = |buffer: &mut Buffer, text: &str, cx: &mut ModelContext<Buffer>| {
|
||||
let append = |buffer: &mut Buffer, text: &str, cx: &mut Context<Buffer>| {
|
||||
let ix = buffer.len();
|
||||
buffer.edit([(ix..ix, text)], Some(AutoindentMode::EachLine), cx);
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use async_compression::futures::bufread::GzipDecoder;
|
||||
use async_trait::async_trait;
|
||||
use collections::HashMap;
|
||||
use futures::{io::BufReader, StreamExt};
|
||||
use gpui::{AppContext, AsyncAppContext, Task};
|
||||
use gpui::{App, AsyncAppContext, Task};
|
||||
use http_client::github::AssetKind;
|
||||
use http_client::github::{latest_github_release, GitHubLspBinaryVersion};
|
||||
pub use language::*;
|
||||
|
@ -462,7 +462,7 @@ impl ContextProvider for RustContextProvider {
|
|||
location: &Location,
|
||||
project_env: Option<HashMap<String, String>>,
|
||||
_: Arc<dyn LanguageToolchainStore>,
|
||||
cx: &mut gpui::AppContext,
|
||||
cx: &mut gpui::App,
|
||||
) -> Task<Result<TaskVariables>> {
|
||||
let local_abs_path = location
|
||||
.buffer
|
||||
|
@ -507,7 +507,7 @@ impl ContextProvider for RustContextProvider {
|
|||
fn associated_tasks(
|
||||
&self,
|
||||
file: Option<Arc<dyn language::File>>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<TaskTemplates> {
|
||||
const DEFAULT_RUN_NAME_STR: &str = "RUST_DEFAULT_PACKAGE_RUN";
|
||||
let package_to_run = language_settings(Some("Rust".into()), file.as_ref(), cx)
|
||||
|
@ -813,7 +813,7 @@ mod tests {
|
|||
|
||||
use super::*;
|
||||
use crate::language;
|
||||
use gpui::{BorrowAppContext, Context, Hsla, TestAppContext};
|
||||
use gpui::{AppContext as _, BorrowAppContext, Hsla, TestAppContext};
|
||||
use language::language_settings::AllLanguageSettings;
|
||||
use lsp::CompletionItemLabelDetails;
|
||||
use settings::SettingsStore;
|
||||
|
@ -1042,7 +1042,7 @@ mod tests {
|
|||
|
||||
let language = crate::language("rust", tree_sitter_rust::LANGUAGE.into());
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("", cx).with_language(language, cx);
|
||||
|
||||
// indent between braces
|
||||
|
|
|
@ -593,7 +593,7 @@ async fn handle_symlink(src_dir: PathBuf, dest_dir: PathBuf) -> Result<()> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{Context, TestAppContext};
|
||||
use gpui::{AppContext as _, TestAppContext};
|
||||
use unindent::Unindent;
|
||||
|
||||
#[gpui::test]
|
||||
|
@ -618,8 +618,7 @@ mod tests {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| language::Buffer::local(text, cx).with_language(language, cx));
|
||||
let buffer = cx.new(|cx| language::Buffer::local(text, cx).with_language(language, cx));
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None).unwrap());
|
||||
assert_eq!(
|
||||
outline
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue