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,7 +3,7 @@ use std::sync::Arc;
|
|||
|
||||
use editor::{Editor, EditorMode, MultiBuffer};
|
||||
use futures::future::Shared;
|
||||
use gpui::{prelude::*, AppContext, Hsla, Task, TextStyleRefinement, View};
|
||||
use gpui::{prelude::*, App, Entity, Hsla, Task, TextStyleRefinement};
|
||||
use language::{Buffer, Language, LanguageRegistry};
|
||||
use markdown_preview::{markdown_parser::parse_markdown, markdown_renderer::render_markdown_block};
|
||||
use nbformat::v4::{CellId, CellMetadata, CellType};
|
||||
|
@ -62,7 +62,10 @@ impl CellControl {
|
|||
}
|
||||
|
||||
impl Clickable for CellControl {
|
||||
fn on_click(self, handler: impl Fn(&gpui::ClickEvent, &mut WindowContext) + 'static) -> Self {
|
||||
fn on_click(
|
||||
self,
|
||||
handler: impl Fn(&gpui::ClickEvent, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
let button = self.button.on_click(handler);
|
||||
Self { button }
|
||||
}
|
||||
|
@ -75,28 +78,33 @@ impl Clickable for CellControl {
|
|||
/// A notebook cell
|
||||
#[derive(Clone)]
|
||||
pub enum Cell {
|
||||
Code(View<CodeCell>),
|
||||
Markdown(View<MarkdownCell>),
|
||||
Raw(View<RawCell>),
|
||||
Code(Entity<CodeCell>),
|
||||
Markdown(Entity<MarkdownCell>),
|
||||
Raw(Entity<RawCell>),
|
||||
}
|
||||
|
||||
fn convert_outputs(outputs: &Vec<nbformat::v4::Output>, cx: &mut WindowContext) -> Vec<Output> {
|
||||
fn convert_outputs(
|
||||
outputs: &Vec<nbformat::v4::Output>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Vec<Output> {
|
||||
outputs
|
||||
.into_iter()
|
||||
.map(|output| match output {
|
||||
nbformat::v4::Output::Stream { text, .. } => Output::Stream {
|
||||
content: cx.new_view(|cx| TerminalOutput::from(&text.0, cx)),
|
||||
content: cx.new(|cx| TerminalOutput::from(&text.0, window, cx)),
|
||||
},
|
||||
nbformat::v4::Output::DisplayData(display_data) => {
|
||||
Output::new(&display_data.data, None, cx)
|
||||
Output::new(&display_data.data, None, window, cx)
|
||||
}
|
||||
nbformat::v4::Output::ExecuteResult(execute_result) => {
|
||||
Output::new(&execute_result.data, None, cx)
|
||||
Output::new(&execute_result.data, None, window, cx)
|
||||
}
|
||||
nbformat::v4::Output::Error(error) => Output::ErrorOutput(ErrorView {
|
||||
ename: error.ename.clone(),
|
||||
evalue: error.evalue.clone(),
|
||||
traceback: cx.new_view(|cx| TerminalOutput::from(&error.traceback.join("\n"), cx)),
|
||||
traceback: cx
|
||||
.new(|cx| TerminalOutput::from(&error.traceback.join("\n"), window, cx)),
|
||||
}),
|
||||
})
|
||||
.collect()
|
||||
|
@ -107,7 +115,8 @@ impl Cell {
|
|||
cell: &nbformat::v4::Cell,
|
||||
languages: &Arc<LanguageRegistry>,
|
||||
notebook_language: Shared<Task<Option<Arc<Language>>>>,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Self {
|
||||
match cell {
|
||||
nbformat::v4::Cell::Markdown {
|
||||
|
@ -118,12 +127,12 @@ impl Cell {
|
|||
} => {
|
||||
let source = source.join("");
|
||||
|
||||
let view = cx.new_view(|cx| {
|
||||
let model = cx.new(|cx| {
|
||||
let markdown_parsing_task = {
|
||||
let languages = languages.clone();
|
||||
let source = source.clone();
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
let parsed_markdown = cx
|
||||
.background_executor()
|
||||
.spawn(async move {
|
||||
|
@ -150,7 +159,7 @@ impl Cell {
|
|||
}
|
||||
});
|
||||
|
||||
Cell::Markdown(view)
|
||||
Cell::Markdown(model)
|
||||
}
|
||||
nbformat::v4::Cell::Code {
|
||||
id,
|
||||
|
@ -158,18 +167,19 @@ impl Cell {
|
|||
execution_count,
|
||||
source,
|
||||
outputs,
|
||||
} => Cell::Code(cx.new_view(|cx| {
|
||||
} => Cell::Code(cx.new(|cx| {
|
||||
let text = source.join("");
|
||||
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text.clone(), cx));
|
||||
let multi_buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text.clone(), cx));
|
||||
let multi_buffer = cx.new(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
|
||||
let editor_view = cx.new_view(|cx| {
|
||||
let editor_view = cx.new(|cx| {
|
||||
let mut editor = Editor::new(
|
||||
EditorMode::AutoHeight { max_lines: 1024 },
|
||||
multi_buffer,
|
||||
None,
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
|
||||
|
@ -183,7 +193,7 @@ impl Cell {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
editor.set_text(text, cx);
|
||||
editor.set_text(text, window, cx);
|
||||
editor.set_show_gutter(false, cx);
|
||||
editor.set_text_style_refinement(refinement);
|
||||
|
||||
|
@ -192,7 +202,7 @@ impl Cell {
|
|||
});
|
||||
|
||||
let buffer = buffer.clone();
|
||||
let language_task = cx.spawn(|this, mut cx| async move {
|
||||
let language_task = cx.spawn_in(window, |this, mut cx| async move {
|
||||
let language = notebook_language.await;
|
||||
|
||||
buffer.update(&mut cx, |buffer, cx| {
|
||||
|
@ -206,7 +216,7 @@ impl Cell {
|
|||
execution_count: *execution_count,
|
||||
source: source.join(""),
|
||||
editor: editor_view,
|
||||
outputs: convert_outputs(outputs, cx),
|
||||
outputs: convert_outputs(outputs, window, cx),
|
||||
selected: false,
|
||||
language_task,
|
||||
cell_position: None,
|
||||
|
@ -216,7 +226,7 @@ impl Cell {
|
|||
id,
|
||||
metadata,
|
||||
source,
|
||||
} => Cell::Raw(cx.new_view(|_| RawCell {
|
||||
} => Cell::Raw(cx.new(|_| RawCell {
|
||||
id: id.clone(),
|
||||
metadata: metadata.clone(),
|
||||
source: source.join(""),
|
||||
|
@ -236,7 +246,7 @@ pub trait RenderableCell: Render {
|
|||
fn source(&self) -> &String;
|
||||
fn selected(&self) -> bool;
|
||||
fn set_selected(&mut self, selected: bool) -> &mut Self;
|
||||
fn selected_bg_color(&self, cx: &ViewContext<Self>) -> Hsla {
|
||||
fn selected_bg_color(&self, window: &mut Window, cx: &mut Context<Self>) -> Hsla {
|
||||
if self.selected() {
|
||||
let mut color = cx.theme().colors().icon_accent;
|
||||
color.fade_out(0.9);
|
||||
|
@ -246,14 +256,15 @@ pub trait RenderableCell: Render {
|
|||
cx.theme().colors().tab_bar_background
|
||||
}
|
||||
}
|
||||
fn control(&self, _cx: &ViewContext<Self>) -> Option<CellControl> {
|
||||
fn control(&self, _window: &mut Window, _cx: &mut Context<Self>) -> Option<CellControl> {
|
||||
None
|
||||
}
|
||||
|
||||
fn cell_position_spacer(
|
||||
&self,
|
||||
is_first: bool,
|
||||
cx: &ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<impl IntoElement> {
|
||||
let cell_position = self.cell_position();
|
||||
|
||||
|
@ -266,7 +277,7 @@ pub trait RenderableCell: Render {
|
|||
}
|
||||
}
|
||||
|
||||
fn gutter(&self, cx: &ViewContext<Self>) -> impl IntoElement {
|
||||
fn gutter(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let is_selected = self.selected();
|
||||
|
||||
div()
|
||||
|
@ -289,7 +300,7 @@ pub trait RenderableCell: Render {
|
|||
.when(!is_selected, |this| this.bg(cx.theme().colors().border)),
|
||||
),
|
||||
)
|
||||
.when_some(self.control(cx), |this, control| {
|
||||
.when_some(self.control(window, cx), |this, control| {
|
||||
this.child(
|
||||
div()
|
||||
.absolute()
|
||||
|
@ -314,7 +325,7 @@ pub trait RenderableCell: Render {
|
|||
pub trait RunnableCell: RenderableCell {
|
||||
fn execution_count(&self) -> Option<i32>;
|
||||
fn set_execution_count(&mut self, count: i32) -> &mut Self;
|
||||
fn run(&mut self, cx: &mut ViewContext<Self>) -> ();
|
||||
fn run(&mut self, window: &mut Window, cx: &mut Context<Self>) -> ();
|
||||
}
|
||||
|
||||
pub struct MarkdownCell {
|
||||
|
@ -356,7 +367,7 @@ impl RenderableCell for MarkdownCell {
|
|||
self
|
||||
}
|
||||
|
||||
fn control(&self, _: &ViewContext<Self>) -> Option<CellControl> {
|
||||
fn control(&self, _window: &mut Window, _: &mut Context<Self>) -> Option<CellControl> {
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -371,18 +382,18 @@ impl RenderableCell for MarkdownCell {
|
|||
}
|
||||
|
||||
impl Render for MarkdownCell {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let Some(parsed) = self.parsed_markdown.as_ref() else {
|
||||
return div();
|
||||
};
|
||||
|
||||
let mut markdown_render_context =
|
||||
markdown_preview::markdown_renderer::RenderContext::new(None, cx);
|
||||
markdown_preview::markdown_renderer::RenderContext::new(None, window, cx);
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
// TODO: Move base cell render into trait impl so we don't have to repeat this
|
||||
.children(self.cell_position_spacer(true, cx))
|
||||
.children(self.cell_position_spacer(true, window, cx))
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
|
@ -390,8 +401,8 @@ impl Render for MarkdownCell {
|
|||
.rounded_sm()
|
||||
.items_start()
|
||||
.gap(DynamicSpacing::Base08.rems(cx))
|
||||
.bg(self.selected_bg_color(cx))
|
||||
.child(self.gutter(cx))
|
||||
.bg(self.selected_bg_color(window, cx))
|
||||
.child(self.gutter(window, cx))
|
||||
.child(
|
||||
v_flex()
|
||||
.size_full()
|
||||
|
@ -408,7 +419,7 @@ impl Render for MarkdownCell {
|
|||
),
|
||||
)
|
||||
// TODO: Move base cell render into trait impl so we don't have to repeat this
|
||||
.children(self.cell_position_spacer(false, cx))
|
||||
.children(self.cell_position_spacer(false, window, cx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,7 +428,7 @@ pub struct CodeCell {
|
|||
metadata: CellMetadata,
|
||||
execution_count: Option<i32>,
|
||||
source: String,
|
||||
editor: View<editor::Editor>,
|
||||
editor: Entity<editor::Editor>,
|
||||
outputs: Vec<Output>,
|
||||
selected: bool,
|
||||
cell_position: Option<CellPosition>,
|
||||
|
@ -425,7 +436,7 @@ pub struct CodeCell {
|
|||
}
|
||||
|
||||
impl CodeCell {
|
||||
pub fn is_dirty(&self, cx: &AppContext) -> bool {
|
||||
pub fn is_dirty(&self, cx: &App) -> bool {
|
||||
self.editor.read(cx).buffer().read(cx).is_dirty(cx)
|
||||
}
|
||||
pub fn has_outputs(&self) -> bool {
|
||||
|
@ -444,7 +455,7 @@ impl CodeCell {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn gutter_output(&self, cx: &ViewContext<Self>) -> impl IntoElement {
|
||||
pub fn gutter_output(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let is_selected = self.selected();
|
||||
|
||||
div()
|
||||
|
@ -505,12 +516,12 @@ impl RenderableCell for CodeCell {
|
|||
&self.source
|
||||
}
|
||||
|
||||
fn control(&self, cx: &ViewContext<Self>) -> Option<CellControl> {
|
||||
fn control(&self, window: &mut Window, cx: &mut Context<Self>) -> Option<CellControl> {
|
||||
let cell_control = if self.has_outputs() {
|
||||
CellControl::new("rerun-cell", CellControlType::RerunCell)
|
||||
} else {
|
||||
CellControl::new("run-cell", CellControlType::RunCell)
|
||||
.on_click(cx.listener(move |this, _, cx| this.run(cx)))
|
||||
.on_click(cx.listener(move |this, _, window, cx| this.run(window, cx)))
|
||||
};
|
||||
|
||||
Some(cell_control)
|
||||
|
@ -536,7 +547,7 @@ impl RenderableCell for CodeCell {
|
|||
}
|
||||
|
||||
impl RunnableCell for CodeCell {
|
||||
fn run(&mut self, cx: &mut ViewContext<Self>) {
|
||||
fn run(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
println!("Running code cell: {}", self.id);
|
||||
}
|
||||
|
||||
|
@ -552,11 +563,11 @@ impl RunnableCell for CodeCell {
|
|||
}
|
||||
|
||||
impl Render for CodeCell {
|
||||
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()
|
||||
.size_full()
|
||||
// TODO: Move base cell render into trait impl so we don't have to repeat this
|
||||
.children(self.cell_position_spacer(true, cx))
|
||||
.children(self.cell_position_spacer(true, window, cx))
|
||||
// Editor portion
|
||||
.child(
|
||||
h_flex()
|
||||
|
@ -565,8 +576,8 @@ impl Render for CodeCell {
|
|||
.rounded_sm()
|
||||
.items_start()
|
||||
.gap(DynamicSpacing::Base08.rems(cx))
|
||||
.bg(self.selected_bg_color(cx))
|
||||
.child(self.gutter(cx))
|
||||
.bg(self.selected_bg_color(window, cx))
|
||||
.child(self.gutter(window, cx))
|
||||
.child(
|
||||
div().py_1p5().w_full().child(
|
||||
div()
|
||||
|
@ -591,8 +602,8 @@ impl Render for CodeCell {
|
|||
.rounded_sm()
|
||||
.items_start()
|
||||
.gap(DynamicSpacing::Base08.rems(cx))
|
||||
.bg(self.selected_bg_color(cx))
|
||||
.child(self.gutter_output(cx))
|
||||
.bg(self.selected_bg_color(window, cx))
|
||||
.child(self.gutter_output(window, cx))
|
||||
.child(
|
||||
div().py_1p5().w_full().child(
|
||||
div()
|
||||
|
@ -627,7 +638,7 @@ impl Render for CodeCell {
|
|||
Some(content.clone().into_any_element())
|
||||
}
|
||||
Output::ErrorOutput(error_view) => {
|
||||
error_view.render(cx)
|
||||
error_view.render(window, cx)
|
||||
}
|
||||
Output::ClearOutputWaitMarker => None,
|
||||
};
|
||||
|
@ -648,7 +659,7 @@ impl Render for CodeCell {
|
|||
),
|
||||
)
|
||||
// TODO: Move base cell render into trait impl so we don't have to repeat this
|
||||
.children(self.cell_position_spacer(false, cx))
|
||||
.children(self.cell_position_spacer(false, window, cx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,11 +710,11 @@ impl RenderableCell for RawCell {
|
|||
}
|
||||
|
||||
impl Render for RawCell {
|
||||
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()
|
||||
.size_full()
|
||||
// TODO: Move base cell render into trait impl so we don't have to repeat this
|
||||
.children(self.cell_position_spacer(true, cx))
|
||||
.children(self.cell_position_spacer(true, window, cx))
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
|
@ -711,8 +722,8 @@ impl Render for RawCell {
|
|||
.rounded_sm()
|
||||
.items_start()
|
||||
.gap(DynamicSpacing::Base08.rems(cx))
|
||||
.bg(self.selected_bg_color(cx))
|
||||
.child(self.gutter(cx))
|
||||
.bg(self.selected_bg_color(window, cx))
|
||||
.child(self.gutter(window, cx))
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
|
@ -725,6 +736,6 @@ impl Render for RawCell {
|
|||
),
|
||||
)
|
||||
// TODO: Move base cell render into trait impl so we don't have to repeat this
|
||||
.children(self.cell_position_spacer(false, cx))
|
||||
.children(self.cell_position_spacer(false, window, cx))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue