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
|
@ -7,11 +7,10 @@ use editor::Editor;
|
|||
use extension_host::ExtensionStore;
|
||||
use futures::channel::oneshot;
|
||||
use gpui::{
|
||||
percentage, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext, DismissEvent,
|
||||
EventEmitter, FocusableView, FontFeatures, ParentElement as _, PromptLevel, Render,
|
||||
SemanticVersion, SharedString, Task, TextStyleRefinement, Transformation, View, WeakView,
|
||||
percentage, Animation, AnimationExt, AnyWindowHandle, App, AsyncAppContext, DismissEvent,
|
||||
Entity, EventEmitter, Focusable, FontFeatures, ParentElement as _, PromptLevel, Render,
|
||||
SemanticVersion, SharedString, Task, TextStyleRefinement, Transformation, WeakEntity,
|
||||
};
|
||||
use gpui::{AppContext, Model};
|
||||
|
||||
use language::CursorShape;
|
||||
use markdown::{Markdown, MarkdownStyle};
|
||||
|
@ -23,8 +22,8 @@ use serde::{Deserialize, Serialize};
|
|||
use settings::{Settings, SettingsSources};
|
||||
use theme::ThemeSettings;
|
||||
use ui::{
|
||||
prelude::*, ActiveTheme, Color, Icon, IconName, IconSize, InteractiveElement, IntoElement,
|
||||
Label, LabelCommon, Styled, ViewContext, VisualContext, WindowContext,
|
||||
prelude::*, ActiveTheme, Color, Context, Icon, IconName, IconSize, InteractiveElement,
|
||||
IntoElement, Label, LabelCommon, Styled, Window,
|
||||
};
|
||||
use workspace::{AppState, ModalView, Workspace};
|
||||
|
||||
|
@ -118,7 +117,7 @@ impl Settings for SshSettings {
|
|||
|
||||
type FileContent = RemoteSettingsContent;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
|
||||
sources.json_merge()
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +126,9 @@ pub struct SshPrompt {
|
|||
connection_string: SharedString,
|
||||
nickname: Option<SharedString>,
|
||||
status_message: Option<SharedString>,
|
||||
prompt: Option<(View<Markdown>, oneshot::Sender<Result<String>>)>,
|
||||
prompt: Option<(Entity<Markdown>, oneshot::Sender<Result<String>>)>,
|
||||
cancellation: Option<oneshot::Sender<()>>,
|
||||
editor: View<Editor>,
|
||||
editor: Entity<Editor>,
|
||||
}
|
||||
|
||||
impl Drop for SshPrompt {
|
||||
|
@ -141,7 +140,7 @@ impl Drop for SshPrompt {
|
|||
}
|
||||
|
||||
pub struct SshConnectionModal {
|
||||
pub(crate) prompt: View<SshPrompt>,
|
||||
pub(crate) prompt: Entity<SshPrompt>,
|
||||
paths: Vec<PathBuf>,
|
||||
finished: bool,
|
||||
}
|
||||
|
@ -149,7 +148,8 @@ pub struct SshConnectionModal {
|
|||
impl SshPrompt {
|
||||
pub(crate) fn new(
|
||||
connection_options: &SshConnectionOptions,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let connection_string = connection_options.connection_string().into();
|
||||
let nickname = connection_options.nickname.clone().map(|s| s.into());
|
||||
|
@ -157,7 +157,7 @@ impl SshPrompt {
|
|||
Self {
|
||||
connection_string,
|
||||
nickname,
|
||||
editor: cx.new_view(Editor::single_line),
|
||||
editor: cx.new(|cx| Editor::single_line(window, cx)),
|
||||
status_message: None,
|
||||
cancellation: None,
|
||||
prompt: None,
|
||||
|
@ -172,11 +172,12 @@ impl SshPrompt {
|
|||
&mut self,
|
||||
prompt: String,
|
||||
tx: oneshot::Sender<Result<String>>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let theme = ThemeSettings::get_global(cx);
|
||||
|
||||
let mut text_style = cx.text_style();
|
||||
let mut text_style = window.text_style();
|
||||
let refinement = TextStyleRefinement {
|
||||
font_family: Some(theme.buffer_font.family.clone()),
|
||||
font_features: Some(FontFeatures::disable_ligatures()),
|
||||
|
@ -201,33 +202,32 @@ impl SshPrompt {
|
|||
selection_background_color: cx.theme().players().local().selection,
|
||||
..Default::default()
|
||||
};
|
||||
let markdown = cx.new_view(|cx| Markdown::new_text(prompt, markdown_style, None, None, cx));
|
||||
let markdown =
|
||||
cx.new(|cx| Markdown::new_text(prompt, markdown_style, None, None, window, cx));
|
||||
self.prompt = Some((markdown, tx));
|
||||
self.status_message.take();
|
||||
cx.focus_view(&self.editor);
|
||||
window.focus(&self.editor.focus_handle(cx));
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn set_status(&mut self, status: Option<String>, cx: &mut ViewContext<Self>) {
|
||||
pub fn set_status(&mut self, status: Option<String>, cx: &mut Context<Self>) {
|
||||
self.status_message = status.map(|s| s.into());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn confirm(&mut self, cx: &mut ViewContext<Self>) {
|
||||
pub fn confirm(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some((_, tx)) = self.prompt.take() {
|
||||
self.status_message = Some("Connecting".into());
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
tx.send(Ok(editor.text(cx))).ok();
|
||||
editor.clear(cx);
|
||||
editor.clear(window, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for SshPrompt {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let cx = cx.window_context();
|
||||
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.key_context("PasswordPrompt")
|
||||
.py_2()
|
||||
|
@ -273,25 +273,27 @@ impl SshConnectionModal {
|
|||
pub(crate) fn new(
|
||||
connection_options: &SshConnectionOptions,
|
||||
paths: Vec<PathBuf>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
Self {
|
||||
prompt: cx.new_view(|cx| SshPrompt::new(connection_options, cx)),
|
||||
prompt: cx.new(|cx| SshPrompt::new(connection_options, window, cx)),
|
||||
finished: false,
|
||||
paths,
|
||||
}
|
||||
}
|
||||
|
||||
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
|
||||
self.prompt.update(cx, |prompt, cx| prompt.confirm(cx))
|
||||
fn confirm(&mut self, _: &menu::Confirm, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.prompt
|
||||
.update(cx, |prompt, cx| prompt.confirm(window, cx))
|
||||
}
|
||||
|
||||
pub fn finished(&mut self, cx: &mut ViewContext<Self>) {
|
||||
pub fn finished(&mut self, cx: &mut Context<Self>) {
|
||||
self.finished = true;
|
||||
cx.emit(DismissEvent);
|
||||
}
|
||||
|
||||
fn dismiss(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
||||
fn dismiss(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(tx) = self
|
||||
.prompt
|
||||
.update(cx, |prompt, _cx| prompt.cancellation.take())
|
||||
|
@ -309,7 +311,7 @@ pub(crate) struct SshConnectionHeader {
|
|||
}
|
||||
|
||||
impl RenderOnce for SshConnectionHeader {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
|
||||
let mut header_color = theme.colors().text;
|
||||
|
@ -357,7 +359,7 @@ impl RenderOnce for SshConnectionHeader {
|
|||
}
|
||||
|
||||
impl Render for SshConnectionModal {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl ui::IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
|
||||
let nickname = self.prompt.read(cx).nickname.clone();
|
||||
let connection_string = self.prompt.read(cx).connection_string.clone();
|
||||
|
||||
|
@ -379,7 +381,7 @@ impl Render for SshConnectionModal {
|
|||
connection_string,
|
||||
nickname,
|
||||
}
|
||||
.render(cx),
|
||||
.render(window, cx),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
|
@ -393,8 +395,8 @@ impl Render for SshConnectionModal {
|
|||
}
|
||||
}
|
||||
|
||||
impl FocusableView for SshConnectionModal {
|
||||
fn focus_handle(&self, cx: &gpui::AppContext) -> gpui::FocusHandle {
|
||||
impl Focusable for SshConnectionModal {
|
||||
fn focus_handle(&self, cx: &gpui::App) -> gpui::FocusHandle {
|
||||
self.prompt.read(cx).editor.focus_handle(cx)
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +404,11 @@ impl FocusableView for SshConnectionModal {
|
|||
impl EventEmitter<DismissEvent> for SshConnectionModal {}
|
||||
|
||||
impl ModalView for SshConnectionModal {
|
||||
fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> workspace::DismissDecision {
|
||||
fn on_before_dismiss(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Self>,
|
||||
) -> workspace::DismissDecision {
|
||||
return workspace::DismissDecision::Dismiss(self.finished);
|
||||
}
|
||||
|
||||
|
@ -414,7 +420,7 @@ impl ModalView for SshConnectionModal {
|
|||
#[derive(Clone)]
|
||||
pub struct SshClientDelegate {
|
||||
window: AnyWindowHandle,
|
||||
ui: WeakView<SshPrompt>,
|
||||
ui: WeakEntity<SshPrompt>,
|
||||
known_password: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -430,9 +436,9 @@ impl remote::SshClientDelegate for SshClientDelegate {
|
|||
tx.send(Ok(password)).ok();
|
||||
} else {
|
||||
self.window
|
||||
.update(cx, |_, cx| {
|
||||
.update(cx, |_, window, cx| {
|
||||
self.ui.update(cx, |modal, cx| {
|
||||
modal.set_prompt(prompt, tx, cx);
|
||||
modal.set_prompt(prompt, tx, window, cx);
|
||||
})
|
||||
})
|
||||
.ok();
|
||||
|
@ -498,7 +504,7 @@ impl remote::SshClientDelegate for SshClientDelegate {
|
|||
impl SshClientDelegate {
|
||||
fn update_status(&self, status: Option<&str>, cx: &mut AsyncAppContext) {
|
||||
self.window
|
||||
.update(cx, |_, cx| {
|
||||
.update(cx, |_, _, cx| {
|
||||
self.ui.update(cx, |modal, cx| {
|
||||
modal.set_status(status.map(|s| s.to_string()), cx);
|
||||
})
|
||||
|
@ -507,17 +513,18 @@ impl SshClientDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_connecting_over_ssh(workspace: &Workspace, cx: &AppContext) -> bool {
|
||||
pub fn is_connecting_over_ssh(workspace: &Workspace, cx: &App) -> bool {
|
||||
workspace.active_modal::<SshConnectionModal>(cx).is_some()
|
||||
}
|
||||
|
||||
pub fn connect_over_ssh(
|
||||
unique_identifier: ConnectionIdentifier,
|
||||
connection_options: SshConnectionOptions,
|
||||
ui: View<SshPrompt>,
|
||||
cx: &mut WindowContext,
|
||||
) -> Task<Result<Option<Model<SshRemoteClient>>>> {
|
||||
let window = cx.window_handle();
|
||||
ui: Entity<SshPrompt>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<Option<Entity<SshRemoteClient>>>> {
|
||||
let window = window.window_handle();
|
||||
let known_password = connection_options.password.clone();
|
||||
let (tx, rx) = oneshot::channel();
|
||||
ui.update(cx, |ui, _cx| ui.set_cancellation_tx(tx));
|
||||
|
@ -546,7 +553,7 @@ pub async fn open_ssh_project(
|
|||
window
|
||||
} else {
|
||||
let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
|
||||
cx.open_window(options, |cx| {
|
||||
cx.open_window(options, |window, cx| {
|
||||
let project = project::Project::local(
|
||||
app_state.client.clone(),
|
||||
app_state.node_runtime.clone(),
|
||||
|
@ -556,7 +563,7 @@ pub async fn open_ssh_project(
|
|||
None,
|
||||
cx,
|
||||
);
|
||||
cx.new_view(|cx| Workspace::new(None, project, app_state.clone(), cx))
|
||||
cx.new(|cx| Workspace::new(None, project, app_state.clone(), window, cx))
|
||||
})?
|
||||
};
|
||||
|
||||
|
@ -565,10 +572,10 @@ pub async fn open_ssh_project(
|
|||
let delegate = window.update(cx, {
|
||||
let connection_options = connection_options.clone();
|
||||
let paths = paths.clone();
|
||||
move |workspace, cx| {
|
||||
cx.activate_window();
|
||||
workspace.toggle_modal(cx, |cx| {
|
||||
SshConnectionModal::new(&connection_options, paths, cx)
|
||||
move |workspace, window, cx| {
|
||||
window.activate_window();
|
||||
workspace.toggle_modal(window, cx, |window, cx| {
|
||||
SshConnectionModal::new(&connection_options, paths, window, cx)
|
||||
});
|
||||
|
||||
let ui = workspace
|
||||
|
@ -582,7 +589,7 @@ pub async fn open_ssh_project(
|
|||
});
|
||||
|
||||
Some(Arc::new(SshClientDelegate {
|
||||
window: cx.window_handle(),
|
||||
window: window.window_handle(),
|
||||
ui: ui.downgrade(),
|
||||
known_password: connection_options.password.clone(),
|
||||
}))
|
||||
|
@ -606,7 +613,7 @@ pub async fn open_ssh_project(
|
|||
.await;
|
||||
|
||||
window
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
if let Some(ui) = workspace.active_modal::<SshConnectionModal>(cx) {
|
||||
ui.update(cx, |modal, cx| modal.finished(cx))
|
||||
}
|
||||
|
@ -616,12 +623,13 @@ pub async fn open_ssh_project(
|
|||
if let Err(e) = did_open_ssh_project {
|
||||
log::error!("Failed to open project: {:?}", e);
|
||||
let response = window
|
||||
.update(cx, |_, cx| {
|
||||
cx.prompt(
|
||||
.update(cx, |_, window, cx| {
|
||||
window.prompt(
|
||||
PromptLevel::Critical,
|
||||
"Failed to connect over SSH",
|
||||
Some(&e.to_string()),
|
||||
&["Retry", "Ok"],
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await;
|
||||
|
@ -632,7 +640,7 @@ pub async fn open_ssh_project(
|
|||
}
|
||||
|
||||
window
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
if let Some(client) = workspace.project().read(cx).ssh_client().clone() {
|
||||
ExtensionStore::global(cx)
|
||||
.update(cx, |store, cx| store.register_ssh_client(client, cx));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue