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,8 +2,8 @@ use std::{any::Any, sync::Arc};
|
|||
|
||||
use any_vec::AnyVec;
|
||||
use gpui::{
|
||||
AnyView, AnyWeakView, AppContext, EventEmitter, Subscription, Task, View, ViewContext,
|
||||
WeakView, WindowContext,
|
||||
AnyView, AnyWeakEntity, App, Context, Entity, EventEmitter, Subscription, Task, WeakEntity,
|
||||
Window,
|
||||
};
|
||||
use project::search::SearchQuery;
|
||||
|
||||
|
@ -57,31 +57,66 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
|
|||
}
|
||||
}
|
||||
|
||||
fn search_bar_visibility_changed(&mut self, _visible: bool, _cx: &mut ViewContext<Self>) {}
|
||||
fn search_bar_visibility_changed(
|
||||
&mut self,
|
||||
_visible: bool,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn has_filtered_search_ranges(&mut self) -> bool {
|
||||
Self::supported_options().selection
|
||||
}
|
||||
|
||||
fn toggle_filtered_search_ranges(&mut self, _enabled: bool, _cx: &mut ViewContext<Self>) {}
|
||||
fn toggle_filtered_search_ranges(
|
||||
&mut self,
|
||||
_enabled: bool,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn get_matches(&self, _: &mut WindowContext) -> Vec<Self::Match> {
|
||||
fn get_matches(&self, _window: &mut Window, _: &mut App) -> Vec<Self::Match> {
|
||||
Vec::new()
|
||||
}
|
||||
fn clear_matches(&mut self, cx: &mut ViewContext<Self>);
|
||||
fn update_matches(&mut self, matches: &[Self::Match], cx: &mut ViewContext<Self>);
|
||||
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String;
|
||||
fn activate_match(&mut self, index: usize, matches: &[Self::Match], cx: &mut ViewContext<Self>);
|
||||
fn select_matches(&mut self, matches: &[Self::Match], cx: &mut ViewContext<Self>);
|
||||
fn replace(&mut self, _: &Self::Match, _: &SearchQuery, _: &mut ViewContext<Self>);
|
||||
fn clear_matches(&mut self, window: &mut Window, cx: &mut Context<Self>);
|
||||
fn update_matches(
|
||||
&mut self,
|
||||
matches: &[Self::Match],
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
);
|
||||
fn query_suggestion(&mut self, window: &mut Window, cx: &mut Context<Self>) -> String;
|
||||
fn activate_match(
|
||||
&mut self,
|
||||
index: usize,
|
||||
matches: &[Self::Match],
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
);
|
||||
fn select_matches(
|
||||
&mut self,
|
||||
matches: &[Self::Match],
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
);
|
||||
fn replace(
|
||||
&mut self,
|
||||
_: &Self::Match,
|
||||
_: &SearchQuery,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Self>,
|
||||
);
|
||||
fn replace_all(
|
||||
&mut self,
|
||||
matches: &mut dyn Iterator<Item = &Self::Match>,
|
||||
query: &SearchQuery,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
for item in matches {
|
||||
self.replace(item, query, cx);
|
||||
self.replace(item, query, window, cx);
|
||||
}
|
||||
}
|
||||
fn match_index_for_direction(
|
||||
|
@ -90,7 +125,8 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
|
|||
current_index: usize,
|
||||
direction: Direction,
|
||||
count: usize,
|
||||
_: &mut ViewContext<Self>,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Self>,
|
||||
) -> usize {
|
||||
match direction {
|
||||
Direction::Prev => {
|
||||
|
@ -107,12 +143,14 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
|
|||
fn find_matches(
|
||||
&mut self,
|
||||
query: Arc<SearchQuery>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Vec<Self::Match>>;
|
||||
fn active_match_index(
|
||||
&mut self,
|
||||
matches: &[Self::Match],
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<usize>;
|
||||
}
|
||||
|
||||
|
@ -122,25 +160,34 @@ pub trait SearchableItemHandle: ItemHandle {
|
|||
fn supported_options(&self) -> SearchOptions;
|
||||
fn subscribe_to_search_events(
|
||||
&self,
|
||||
cx: &mut WindowContext,
|
||||
handler: Box<dyn Fn(&SearchEvent, &mut WindowContext) + Send>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
handler: Box<dyn Fn(&SearchEvent, &mut Window, &mut App) + Send>,
|
||||
) -> Subscription;
|
||||
fn clear_matches(&self, cx: &mut WindowContext);
|
||||
fn update_matches(&self, matches: &AnyVec<dyn Send>, cx: &mut WindowContext);
|
||||
fn query_suggestion(&self, cx: &mut WindowContext) -> String;
|
||||
fn activate_match(&self, index: usize, matches: &AnyVec<dyn Send>, cx: &mut WindowContext);
|
||||
fn select_matches(&self, matches: &AnyVec<dyn Send>, cx: &mut WindowContext);
|
||||
fn clear_matches(&self, window: &mut Window, cx: &mut App);
|
||||
fn update_matches(&self, matches: &AnyVec<dyn Send>, window: &mut Window, cx: &mut App);
|
||||
fn query_suggestion(&self, window: &mut Window, cx: &mut App) -> String;
|
||||
fn activate_match(
|
||||
&self,
|
||||
index: usize,
|
||||
matches: &AnyVec<dyn Send>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
);
|
||||
fn select_matches(&self, matches: &AnyVec<dyn Send>, window: &mut Window, cx: &mut App);
|
||||
fn replace(
|
||||
&self,
|
||||
_: any_vec::element::ElementRef<'_, dyn Send>,
|
||||
_: &SearchQuery,
|
||||
_: &mut WindowContext,
|
||||
_window: &mut Window,
|
||||
_: &mut App,
|
||||
);
|
||||
fn replace_all(
|
||||
&self,
|
||||
matches: &mut dyn Iterator<Item = any_vec::element::ElementRef<'_, dyn Send>>,
|
||||
query: &SearchQuery,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
);
|
||||
fn match_index_for_direction(
|
||||
&self,
|
||||
|
@ -148,24 +195,27 @@ pub trait SearchableItemHandle: ItemHandle {
|
|||
current_index: usize,
|
||||
direction: Direction,
|
||||
count: usize,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> usize;
|
||||
fn find_matches(
|
||||
&self,
|
||||
query: Arc<SearchQuery>,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Task<AnyVec<dyn Send>>;
|
||||
fn active_match_index(
|
||||
&self,
|
||||
matches: &AnyVec<dyn Send>,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<usize>;
|
||||
fn search_bar_visibility_changed(&self, visible: bool, cx: &mut WindowContext);
|
||||
fn search_bar_visibility_changed(&self, visible: bool, window: &mut Window, cx: &mut App);
|
||||
|
||||
fn toggle_filtered_search_ranges(&mut self, enabled: bool, cx: &mut WindowContext);
|
||||
fn toggle_filtered_search_ranges(&mut self, enabled: bool, window: &mut Window, cx: &mut App);
|
||||
}
|
||||
|
||||
impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
||||
impl<T: SearchableItem> SearchableItemHandle for Entity<T> {
|
||||
fn downgrade(&self) -> Box<dyn WeakSearchableItemHandle> {
|
||||
Box::new(self.downgrade())
|
||||
}
|
||||
|
@ -180,32 +230,45 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
|||
|
||||
fn subscribe_to_search_events(
|
||||
&self,
|
||||
cx: &mut WindowContext,
|
||||
handler: Box<dyn Fn(&SearchEvent, &mut WindowContext) + Send>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
handler: Box<dyn Fn(&SearchEvent, &mut Window, &mut App) + Send>,
|
||||
) -> Subscription {
|
||||
cx.subscribe(self, move |_, event: &SearchEvent, cx| handler(event, cx))
|
||||
window.subscribe(self, cx, move |_, event: &SearchEvent, window, cx| {
|
||||
handler(event, window, cx)
|
||||
})
|
||||
}
|
||||
|
||||
fn clear_matches(&self, cx: &mut WindowContext) {
|
||||
self.update(cx, |this, cx| this.clear_matches(cx));
|
||||
fn clear_matches(&self, window: &mut Window, cx: &mut App) {
|
||||
self.update(cx, |this, cx| this.clear_matches(window, cx));
|
||||
}
|
||||
fn update_matches(&self, matches: &AnyVec<dyn Send>, cx: &mut WindowContext) {
|
||||
let matches = matches.downcast_ref().unwrap();
|
||||
self.update(cx, |this, cx| this.update_matches(matches.as_slice(), cx));
|
||||
}
|
||||
fn query_suggestion(&self, cx: &mut WindowContext) -> String {
|
||||
self.update(cx, |this, cx| this.query_suggestion(cx))
|
||||
}
|
||||
fn activate_match(&self, index: usize, matches: &AnyVec<dyn Send>, cx: &mut WindowContext) {
|
||||
fn update_matches(&self, matches: &AnyVec<dyn Send>, window: &mut Window, cx: &mut App) {
|
||||
let matches = matches.downcast_ref().unwrap();
|
||||
self.update(cx, |this, cx| {
|
||||
this.activate_match(index, matches.as_slice(), cx)
|
||||
this.update_matches(matches.as_slice(), window, cx)
|
||||
});
|
||||
}
|
||||
fn query_suggestion(&self, window: &mut Window, cx: &mut App) -> String {
|
||||
self.update(cx, |this, cx| this.query_suggestion(window, cx))
|
||||
}
|
||||
fn activate_match(
|
||||
&self,
|
||||
index: usize,
|
||||
matches: &AnyVec<dyn Send>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
let matches = matches.downcast_ref().unwrap();
|
||||
self.update(cx, |this, cx| {
|
||||
this.activate_match(index, matches.as_slice(), window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
fn select_matches(&self, matches: &AnyVec<dyn Send>, cx: &mut WindowContext) {
|
||||
fn select_matches(&self, matches: &AnyVec<dyn Send>, window: &mut Window, cx: &mut App) {
|
||||
let matches = matches.downcast_ref().unwrap();
|
||||
self.update(cx, |this, cx| this.select_matches(matches.as_slice(), cx));
|
||||
self.update(cx, |this, cx| {
|
||||
this.select_matches(matches.as_slice(), window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
fn match_index_for_direction(
|
||||
|
@ -214,20 +277,29 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
|||
current_index: usize,
|
||||
direction: Direction,
|
||||
count: usize,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> usize {
|
||||
let matches = matches.downcast_ref().unwrap();
|
||||
self.update(cx, |this, cx| {
|
||||
this.match_index_for_direction(matches.as_slice(), current_index, direction, count, cx)
|
||||
this.match_index_for_direction(
|
||||
matches.as_slice(),
|
||||
current_index,
|
||||
direction,
|
||||
count,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}
|
||||
fn find_matches(
|
||||
&self,
|
||||
query: Arc<SearchQuery>,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Task<AnyVec<dyn Send>> {
|
||||
let matches = self.update(cx, |this, cx| this.find_matches(query, cx));
|
||||
cx.spawn(|_| async {
|
||||
let matches = self.update(cx, |this, cx| this.find_matches(query, window, cx));
|
||||
window.spawn(cx, |_| async {
|
||||
let matches = matches.await;
|
||||
let mut any_matches = AnyVec::with_capacity::<T::Match>(matches.len());
|
||||
{
|
||||
|
@ -242,11 +314,12 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
|||
fn active_match_index(
|
||||
&self,
|
||||
matches: &AnyVec<dyn Send>,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<usize> {
|
||||
let matches = matches.downcast_ref()?;
|
||||
self.update(cx, |this, cx| {
|
||||
this.active_match_index(matches.as_slice(), cx)
|
||||
this.active_match_index(matches.as_slice(), window, cx)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -254,32 +327,39 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
|||
&self,
|
||||
mat: any_vec::element::ElementRef<'_, dyn Send>,
|
||||
query: &SearchQuery,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
let mat = mat.downcast_ref().unwrap();
|
||||
self.update(cx, |this, cx| this.replace(mat, query, cx))
|
||||
self.update(cx, |this, cx| this.replace(mat, query, window, cx))
|
||||
}
|
||||
|
||||
fn replace_all(
|
||||
&self,
|
||||
matches: &mut dyn Iterator<Item = any_vec::element::ElementRef<'_, dyn Send>>,
|
||||
query: &SearchQuery,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
self.update(cx, |this, cx| {
|
||||
this.replace_all(&mut matches.map(|m| m.downcast_ref().unwrap()), query, cx);
|
||||
this.replace_all(
|
||||
&mut matches.map(|m| m.downcast_ref().unwrap()),
|
||||
query,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
fn search_bar_visibility_changed(&self, visible: bool, cx: &mut WindowContext) {
|
||||
fn search_bar_visibility_changed(&self, visible: bool, window: &mut Window, cx: &mut App) {
|
||||
self.update(cx, |this, cx| {
|
||||
this.search_bar_visibility_changed(visible, cx)
|
||||
this.search_bar_visibility_changed(visible, window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
fn toggle_filtered_search_ranges(&mut self, enabled: bool, cx: &mut WindowContext) {
|
||||
fn toggle_filtered_search_ranges(&mut self, enabled: bool, window: &mut Window, cx: &mut App) {
|
||||
self.update(cx, |this, cx| {
|
||||
this.toggle_filtered_search_ranges(enabled, cx)
|
||||
this.toggle_filtered_search_ranges(enabled, window, cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -305,17 +385,17 @@ impl PartialEq for Box<dyn SearchableItemHandle> {
|
|||
impl Eq for Box<dyn SearchableItemHandle> {}
|
||||
|
||||
pub trait WeakSearchableItemHandle: WeakItemHandle {
|
||||
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
|
||||
fn upgrade(&self, cx: &App) -> Option<Box<dyn SearchableItemHandle>>;
|
||||
|
||||
fn into_any(self) -> AnyWeakView;
|
||||
fn into_any(self) -> AnyWeakEntity;
|
||||
}
|
||||
|
||||
impl<T: SearchableItem> WeakSearchableItemHandle for WeakView<T> {
|
||||
fn upgrade(&self, _cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>> {
|
||||
impl<T: SearchableItem> WeakSearchableItemHandle for WeakEntity<T> {
|
||||
fn upgrade(&self, _cx: &App) -> Option<Box<dyn SearchableItemHandle>> {
|
||||
Some(Box::new(self.upgrade()?))
|
||||
}
|
||||
|
||||
fn into_any(self) -> AnyWeakView {
|
||||
fn into_any(self) -> AnyWeakEntity {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue