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
|
@ -3,13 +3,11 @@ use crate::{
|
|||
summary_index::FileSummary,
|
||||
worktree_index::{WorktreeIndex, WorktreeIndexHandle},
|
||||
};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use collections::HashMap;
|
||||
use fs::Fs;
|
||||
use futures::FutureExt;
|
||||
use gpui::{
|
||||
AppContext, Entity, EntityId, EventEmitter, Model, ModelContext, Subscription, Task, WeakModel,
|
||||
};
|
||||
use gpui::{App, Context, Entity, EntityId, EventEmitter, Subscription, Task, WeakEntity};
|
||||
use language::LanguageRegistry;
|
||||
use log;
|
||||
use project::{Project, Worktree, WorktreeId};
|
||||
|
@ -27,7 +25,7 @@ use util::ResultExt;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct SearchResult {
|
||||
pub worktree: Model<Worktree>,
|
||||
pub worktree: Entity<Worktree>,
|
||||
pub path: Arc<Path>,
|
||||
pub range: Range<usize>,
|
||||
pub score: f32,
|
||||
|
@ -60,7 +58,7 @@ pub enum Status {
|
|||
|
||||
pub struct ProjectIndex {
|
||||
db_connection: heed::Env,
|
||||
project: WeakModel<Project>,
|
||||
project: WeakEntity<Project>,
|
||||
worktree_indices: HashMap<EntityId, WorktreeIndexHandle>,
|
||||
language_registry: Arc<LanguageRegistry>,
|
||||
fs: Arc<dyn Fs>,
|
||||
|
@ -73,10 +71,10 @@ pub struct ProjectIndex {
|
|||
|
||||
impl ProjectIndex {
|
||||
pub fn new(
|
||||
project: Model<Project>,
|
||||
project: Entity<Project>,
|
||||
db_connection: heed::Env,
|
||||
embedding_provider: Arc<dyn EmbeddingProvider>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let language_registry = project.read(cx).languages().clone();
|
||||
let fs = project.read(cx).fs().clone();
|
||||
|
@ -110,7 +108,7 @@ impl ProjectIndex {
|
|||
self.last_status
|
||||
}
|
||||
|
||||
pub fn project(&self) -> WeakModel<Project> {
|
||||
pub fn project(&self) -> WeakEntity<Project> {
|
||||
self.project.clone()
|
||||
}
|
||||
|
||||
|
@ -120,9 +118,9 @@ impl ProjectIndex {
|
|||
|
||||
fn handle_project_event(
|
||||
&mut self,
|
||||
_: Model<Project>,
|
||||
_: Entity<Project>,
|
||||
event: &project::Event,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
match event {
|
||||
project::Event::WorktreeAdded(_) | project::Event::WorktreeRemoved(_) => {
|
||||
|
@ -132,7 +130,7 @@ impl ProjectIndex {
|
|||
}
|
||||
}
|
||||
|
||||
fn update_worktree_indices(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn update_worktree_indices(&mut self, cx: &mut Context<Self>) {
|
||||
let Some(project) = self.project.upgrade() else {
|
||||
return;
|
||||
};
|
||||
|
@ -198,7 +196,7 @@ impl ProjectIndex {
|
|||
self.update_status(cx);
|
||||
}
|
||||
|
||||
fn update_status(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn update_status(&mut self, cx: &mut Context<Self>) {
|
||||
let mut indexing_count = 0;
|
||||
let mut any_loading = false;
|
||||
|
||||
|
@ -232,7 +230,7 @@ impl ProjectIndex {
|
|||
&self,
|
||||
queries: Vec<String>,
|
||||
limit: usize,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Task<Result<Vec<SearchResult>>> {
|
||||
let (chunks_tx, chunks_rx) = channel::bounded(1024);
|
||||
let mut worktree_scan_tasks = Vec::new();
|
||||
|
@ -372,7 +370,7 @@ impl ProjectIndex {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn path_count(&self, cx: &AppContext) -> Result<u64> {
|
||||
pub fn path_count(&self, cx: &App) -> Result<u64> {
|
||||
let mut result = 0;
|
||||
for worktree_index in self.worktree_indices.values() {
|
||||
if let WorktreeIndexHandle::Loaded { index, .. } = worktree_index {
|
||||
|
@ -385,8 +383,8 @@ impl ProjectIndex {
|
|||
pub(crate) fn worktree_index(
|
||||
&self,
|
||||
worktree_id: WorktreeId,
|
||||
cx: &AppContext,
|
||||
) -> Option<Model<WorktreeIndex>> {
|
||||
cx: &App,
|
||||
) -> Option<Entity<WorktreeIndex>> {
|
||||
for index in self.worktree_indices.values() {
|
||||
if let WorktreeIndexHandle::Loaded { index, .. } = index {
|
||||
if index.read(cx).worktree().read(cx).id() == worktree_id {
|
||||
|
@ -397,7 +395,7 @@ impl ProjectIndex {
|
|||
None
|
||||
}
|
||||
|
||||
pub(crate) fn worktree_indices(&self, cx: &AppContext) -> Vec<Model<WorktreeIndex>> {
|
||||
pub(crate) fn worktree_indices(&self, cx: &App) -> Vec<Entity<WorktreeIndex>> {
|
||||
let mut result = self
|
||||
.worktree_indices
|
||||
.values()
|
||||
|
@ -413,7 +411,7 @@ impl ProjectIndex {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn all_summaries(&self, cx: &AppContext) -> Task<Result<Vec<FileSummary>>> {
|
||||
pub fn all_summaries(&self, cx: &App) -> Task<Result<Vec<FileSummary>>> {
|
||||
let (summaries_tx, summaries_rx) = channel::bounded(1024);
|
||||
let mut worktree_scan_tasks = Vec::new();
|
||||
for worktree_index in self.worktree_indices.values() {
|
||||
|
@ -503,7 +501,7 @@ impl ProjectIndex {
|
|||
}
|
||||
|
||||
/// Empty out the backlogs of all the worktrees in the project
|
||||
pub fn flush_summary_backlogs(&self, cx: &AppContext) -> impl Future<Output = ()> {
|
||||
pub fn flush_summary_backlogs(&self, cx: &App) -> impl Future<Output = ()> {
|
||||
let flush_start = std::time::Instant::now();
|
||||
|
||||
futures::future::join_all(self.worktree_indices.values().map(|worktree_index| {
|
||||
|
@ -540,7 +538,7 @@ impl ProjectIndex {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn remaining_summaries(&self, cx: &mut ModelContext<Self>) -> usize {
|
||||
pub fn remaining_summaries(&self, cx: &mut Context<Self>) -> usize {
|
||||
self.worktree_indices(cx)
|
||||
.iter()
|
||||
.map(|index| index.read(cx).summary_index().backlog_len())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue