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
|
@ -1,23 +1,23 @@
|
|||
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
||||
use gpui::{
|
||||
actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render, Styled,
|
||||
View, ViewContext, VisualContext, WeakView,
|
||||
actions, App, Context, DismissEvent, Entity, EventEmitter, Focusable, ParentElement, Render,
|
||||
Styled, WeakEntity, Window,
|
||||
};
|
||||
use language::LanguageRegistry;
|
||||
use paths::config_dir;
|
||||
use picker::{Picker, PickerDelegate};
|
||||
use std::{borrow::Borrow, fs, sync::Arc};
|
||||
use ui::{prelude::*, HighlightedLabel, ListItem, ListItemSpacing, WindowContext};
|
||||
use ui::{prelude::*, HighlightedLabel, ListItem, ListItemSpacing};
|
||||
use util::ResultExt;
|
||||
use workspace::{notifications::NotifyResultExt, ModalView, Workspace};
|
||||
|
||||
actions!(snippets, [ConfigureSnippets, OpenFolder]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(register).detach();
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.observe_new(register).detach();
|
||||
}
|
||||
|
||||
fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
||||
fn register(workspace: &mut Workspace, _window: Option<&mut Window>, _: &mut Context<Workspace>) {
|
||||
workspace.register_action(configure_snippets);
|
||||
workspace.register_action(open_folder);
|
||||
}
|
||||
|
@ -25,35 +25,42 @@ fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
|||
fn configure_snippets(
|
||||
workspace: &mut Workspace,
|
||||
_: &ConfigureSnippets,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
let language_registry = workspace.app_state().languages.clone();
|
||||
let workspace_handle = workspace.weak_handle();
|
||||
|
||||
workspace.toggle_modal(cx, move |cx| {
|
||||
ScopeSelector::new(language_registry, workspace_handle, cx)
|
||||
workspace.toggle_modal(window, cx, move |window, cx| {
|
||||
ScopeSelector::new(language_registry, workspace_handle, window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
fn open_folder(workspace: &mut Workspace, _: &OpenFolder, cx: &mut ViewContext<Workspace>) {
|
||||
fn open_folder(
|
||||
workspace: &mut Workspace,
|
||||
_: &OpenFolder,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
fs::create_dir_all(config_dir().join("snippets")).notify_err(workspace, cx);
|
||||
cx.open_with_system(config_dir().join("snippets").borrow());
|
||||
}
|
||||
|
||||
pub struct ScopeSelector {
|
||||
picker: View<Picker<ScopeSelectorDelegate>>,
|
||||
picker: Entity<Picker<ScopeSelectorDelegate>>,
|
||||
}
|
||||
|
||||
impl ScopeSelector {
|
||||
fn new(
|
||||
language_registry: Arc<LanguageRegistry>,
|
||||
workspace: WeakView<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let delegate =
|
||||
ScopeSelectorDelegate::new(workspace, cx.view().downgrade(), language_registry);
|
||||
ScopeSelectorDelegate::new(workspace, cx.model().downgrade(), language_registry);
|
||||
|
||||
let picker = cx.new_view(|cx| Picker::uniform_list(delegate, cx));
|
||||
let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx));
|
||||
|
||||
Self { picker }
|
||||
}
|
||||
|
@ -63,21 +70,21 @@ impl ModalView for ScopeSelector {}
|
|||
|
||||
impl EventEmitter<DismissEvent> for ScopeSelector {}
|
||||
|
||||
impl FocusableView for ScopeSelector {
|
||||
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
|
||||
impl Focusable for ScopeSelector {
|
||||
fn focus_handle(&self, cx: &App) -> gpui::FocusHandle {
|
||||
self.picker.focus_handle(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ScopeSelector {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex().w(rems(34.)).child(self.picker.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScopeSelectorDelegate {
|
||||
workspace: WeakView<Workspace>,
|
||||
scope_selector: WeakView<ScopeSelector>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
scope_selector: WeakEntity<ScopeSelector>,
|
||||
language_registry: Arc<LanguageRegistry>,
|
||||
candidates: Vec<StringMatchCandidate>,
|
||||
matches: Vec<StringMatch>,
|
||||
|
@ -86,8 +93,8 @@ pub struct ScopeSelectorDelegate {
|
|||
|
||||
impl ScopeSelectorDelegate {
|
||||
fn new(
|
||||
workspace: WeakView<Workspace>,
|
||||
scope_selector: WeakView<ScopeSelector>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
scope_selector: WeakEntity<ScopeSelector>,
|
||||
language_registry: Arc<LanguageRegistry>,
|
||||
) -> Self {
|
||||
let candidates = Vec::from(["Global".to_string()]).into_iter();
|
||||
|
@ -113,7 +120,7 @@ impl ScopeSelectorDelegate {
|
|||
impl PickerDelegate for ScopeSelectorDelegate {
|
||||
type ListItem = ListItem;
|
||||
|
||||
fn placeholder_text(&self, _: &mut WindowContext) -> Arc<str> {
|
||||
fn placeholder_text(&self, _window: &mut Window, _: &mut App) -> Arc<str> {
|
||||
"Select snippet scope...".into()
|
||||
}
|
||||
|
||||
|
@ -121,23 +128,24 @@ impl PickerDelegate for ScopeSelectorDelegate {
|
|||
self.matches.len()
|
||||
}
|
||||
|
||||
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) {
|
||||
fn confirm(&mut self, _: bool, window: &mut Window, cx: &mut Context<Picker<Self>>) {
|
||||
if let Some(mat) = self.matches.get(self.selected_index) {
|
||||
let scope_name = self.candidates[mat.candidate_id].string.clone();
|
||||
let language = self.language_registry.language_for_name(&scope_name);
|
||||
|
||||
if let Some(workspace) = self.workspace.upgrade() {
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.spawn_in(window, |_, mut cx| async move {
|
||||
let scope = match scope_name.as_str() {
|
||||
"Global" => "snippets".to_string(),
|
||||
_ => language.await?.lsp_id(),
|
||||
};
|
||||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
workspace.update_in(&mut cx, |workspace, window, cx| {
|
||||
workspace
|
||||
.open_abs_path(
|
||||
config_dir().join("snippets").join(scope + ".json"),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
.detach();
|
||||
|
@ -146,10 +154,10 @@ impl PickerDelegate for ScopeSelectorDelegate {
|
|||
.detach_and_log_err(cx);
|
||||
};
|
||||
}
|
||||
self.dismissed(cx);
|
||||
self.dismissed(window, cx);
|
||||
}
|
||||
|
||||
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
|
||||
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<Self>>) {
|
||||
self.scope_selector
|
||||
.update(cx, |_, cx| cx.emit(DismissEvent))
|
||||
.log_err();
|
||||
|
@ -159,18 +167,24 @@ impl PickerDelegate for ScopeSelectorDelegate {
|
|||
self.selected_index
|
||||
}
|
||||
|
||||
fn set_selected_index(&mut self, ix: usize, _: &mut ViewContext<Picker<Self>>) {
|
||||
fn set_selected_index(
|
||||
&mut self,
|
||||
ix: usize,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Picker<Self>>,
|
||||
) {
|
||||
self.selected_index = ix;
|
||||
}
|
||||
|
||||
fn update_matches(
|
||||
&mut self,
|
||||
query: String,
|
||||
cx: &mut ViewContext<Picker<Self>>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) -> gpui::Task<()> {
|
||||
let background = cx.background_executor().clone();
|
||||
let candidates = self.candidates.clone();
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
let matches = if query.is_empty() {
|
||||
candidates
|
||||
.into_iter()
|
||||
|
@ -210,7 +224,8 @@ impl PickerDelegate for ScopeSelectorDelegate {
|
|||
&self,
|
||||
ix: usize,
|
||||
selected: bool,
|
||||
_: &mut ViewContext<Picker<Self>>,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let mat = &self.matches[ix];
|
||||
let label = mat.string.clone();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue