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
|
@ -61,7 +61,7 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
|
|||
let language_server_id = LanguageServerId(0);
|
||||
let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store());
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*window, cx);
|
||||
let workspace = window.root(cx).unwrap();
|
||||
|
||||
|
@ -150,18 +150,20 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
|
|||
});
|
||||
|
||||
// Open the project diagnostics view while there are already diagnostics.
|
||||
let view = window.build_view(cx, |cx| {
|
||||
let diagnostics = window.build_model(cx, |window, cx| {
|
||||
ProjectDiagnosticsEditor::new_with_context(
|
||||
1,
|
||||
true,
|
||||
project.clone(),
|
||||
workspace.downgrade(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
let editor = view.update(cx, |view, _| view.editor.clone());
|
||||
let editor = diagnostics.update(cx, |diagnostics, _| diagnostics.editor.clone());
|
||||
|
||||
view.next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)
|
||||
diagnostics
|
||||
.next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)
|
||||
.await;
|
||||
assert_eq!(
|
||||
editor_blocks(&editor, cx),
|
||||
|
@ -251,7 +253,8 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
|
|||
lsp_store.disk_based_diagnostics_finished(language_server_id, cx);
|
||||
});
|
||||
|
||||
view.next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)
|
||||
diagnostics
|
||||
.next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)
|
||||
.await;
|
||||
assert_eq!(
|
||||
editor_blocks(&editor, cx),
|
||||
|
@ -370,7 +373,8 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
|
|||
lsp_store.disk_based_diagnostics_finished(language_server_id, cx);
|
||||
});
|
||||
|
||||
view.next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)
|
||||
diagnostics
|
||||
.next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)
|
||||
.await;
|
||||
assert_eq!(
|
||||
editor_blocks(&editor, cx),
|
||||
|
@ -477,20 +481,21 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
|
|||
let server_id_2 = LanguageServerId(101);
|
||||
let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store());
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*window, cx);
|
||||
let workspace = window.root(cx).unwrap();
|
||||
|
||||
let view = window.build_view(cx, |cx| {
|
||||
let diagnostics = window.build_model(cx, |window, cx| {
|
||||
ProjectDiagnosticsEditor::new_with_context(
|
||||
1,
|
||||
true,
|
||||
project.clone(),
|
||||
workspace.downgrade(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
let editor = view.update(cx, |view, _| view.editor.clone());
|
||||
let editor = diagnostics.update(cx, |diagnostics, _| diagnostics.editor.clone());
|
||||
|
||||
// Two language servers start updating diagnostics
|
||||
lsp_store.update(cx, |lsp_store, cx| {
|
||||
|
@ -754,25 +759,26 @@ async fn test_random_diagnostics(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
|
||||
let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store());
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*window, cx);
|
||||
let workspace = window.root(cx).unwrap();
|
||||
|
||||
let mutated_view = window.build_view(cx, |cx| {
|
||||
let mutated_diagnostics = window.build_model(cx, |window, cx| {
|
||||
ProjectDiagnosticsEditor::new_with_context(
|
||||
1,
|
||||
true,
|
||||
project.clone(),
|
||||
workspace.downgrade(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.add_item_to_center(Box::new(mutated_view.clone()), cx);
|
||||
workspace.update_in(cx, |workspace, window, cx| {
|
||||
workspace.add_item_to_center(Box::new(mutated_diagnostics.clone()), window, cx);
|
||||
});
|
||||
mutated_view.update(cx, |view, cx| {
|
||||
assert!(view.focus_handle.is_focused(cx));
|
||||
mutated_diagnostics.update_in(cx, |diagnostics, window, _cx| {
|
||||
assert!(diagnostics.focus_handle.is_focused(window));
|
||||
});
|
||||
|
||||
let mut next_group_id = 0;
|
||||
|
@ -858,16 +864,19 @@ async fn test_random_diagnostics(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
}
|
||||
|
||||
log::info!("updating mutated diagnostics view");
|
||||
mutated_view.update(cx, |view, cx| view.update_stale_excerpts(cx));
|
||||
mutated_diagnostics.update_in(cx, |diagnostics, window, cx| {
|
||||
diagnostics.update_stale_excerpts(window, cx)
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
log::info!("constructing reference diagnostics view");
|
||||
let reference_view = window.build_view(cx, |cx| {
|
||||
let reference_diagnostics = window.build_model(cx, |window, cx| {
|
||||
ProjectDiagnosticsEditor::new_with_context(
|
||||
1,
|
||||
true,
|
||||
project.clone(),
|
||||
workspace.downgrade(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
@ -875,8 +884,8 @@ async fn test_random_diagnostics(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
.advance_clock(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10));
|
||||
cx.run_until_parked();
|
||||
|
||||
let mutated_excerpts = get_diagnostics_excerpts(&mutated_view, cx);
|
||||
let reference_excerpts = get_diagnostics_excerpts(&reference_view, cx);
|
||||
let mutated_excerpts = get_diagnostics_excerpts(&mutated_diagnostics, cx);
|
||||
let reference_excerpts = get_diagnostics_excerpts(&reference_diagnostics, cx);
|
||||
|
||||
for ((path, language_server_id), diagnostics) in current_diagnostics {
|
||||
for diagnostic in diagnostics {
|
||||
|
@ -917,13 +926,13 @@ struct ExcerptInfo {
|
|||
}
|
||||
|
||||
fn get_diagnostics_excerpts(
|
||||
view: &View<ProjectDiagnosticsEditor>,
|
||||
diagnostics: &Entity<ProjectDiagnosticsEditor>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> Vec<ExcerptInfo> {
|
||||
view.update(cx, |view, cx| {
|
||||
diagnostics.update(cx, |diagnostics, cx| {
|
||||
let mut result = vec![];
|
||||
let mut excerpt_indices_by_id = HashMap::default();
|
||||
view.excerpts.update(cx, |multibuffer, cx| {
|
||||
diagnostics.excerpts.update(cx, |multibuffer, cx| {
|
||||
let snapshot = multibuffer.snapshot(cx);
|
||||
for (id, buffer, range) in snapshot.excerpts() {
|
||||
excerpt_indices_by_id.insert(id, result.len());
|
||||
|
@ -940,7 +949,7 @@ fn get_diagnostics_excerpts(
|
|||
}
|
||||
});
|
||||
|
||||
for state in &view.path_states {
|
||||
for state in &diagnostics.path_states {
|
||||
for group in &state.diagnostic_groups {
|
||||
for (ix, excerpt_id) in group.excerpts.iter().enumerate() {
|
||||
let excerpt_ix = excerpt_indices_by_id[excerpt_id];
|
||||
|
@ -1043,58 +1052,63 @@ const FILE_HEADER: &str = "file header";
|
|||
const EXCERPT_HEADER: &str = "excerpt header";
|
||||
|
||||
fn editor_blocks(
|
||||
editor: &View<Editor>,
|
||||
editor: &Entity<Editor>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> Vec<(DisplayRow, SharedString)> {
|
||||
let mut blocks = Vec::new();
|
||||
cx.draw(gpui::Point::default(), AvailableSpace::min_size(), |cx| {
|
||||
editor.update(cx, |editor, cx| {
|
||||
let snapshot = editor.snapshot(cx);
|
||||
blocks.extend(
|
||||
snapshot
|
||||
.blocks_in_range(DisplayRow(0)..snapshot.max_point().row())
|
||||
.filter_map(|(row, block)| {
|
||||
let block_id = block.id();
|
||||
let name: SharedString = match block {
|
||||
Block::Custom(block) => {
|
||||
let mut element = block.render(&mut BlockContext {
|
||||
context: cx,
|
||||
anchor_x: px(0.),
|
||||
gutter_dimensions: &GutterDimensions::default(),
|
||||
line_height: px(0.),
|
||||
em_width: px(0.),
|
||||
max_width: px(0.),
|
||||
block_id,
|
||||
selected: false,
|
||||
editor_style: &editor::EditorStyle::default(),
|
||||
});
|
||||
let element = element.downcast_mut::<Stateful<Div>>().unwrap();
|
||||
element
|
||||
.interactivity()
|
||||
.element_id
|
||||
.clone()?
|
||||
.try_into()
|
||||
.ok()?
|
||||
}
|
||||
|
||||
Block::FoldedBuffer { .. } => FILE_HEADER.into(),
|
||||
Block::ExcerptBoundary {
|
||||
starts_new_buffer, ..
|
||||
} => {
|
||||
if *starts_new_buffer {
|
||||
FILE_HEADER.into()
|
||||
} else {
|
||||
EXCERPT_HEADER.into()
|
||||
cx.draw(
|
||||
gpui::Point::default(),
|
||||
AvailableSpace::min_size(),
|
||||
|window, cx| {
|
||||
editor.update(cx, |editor, cx| {
|
||||
let snapshot = editor.snapshot(window, cx);
|
||||
blocks.extend(
|
||||
snapshot
|
||||
.blocks_in_range(DisplayRow(0)..snapshot.max_point().row())
|
||||
.filter_map(|(row, block)| {
|
||||
let block_id = block.id();
|
||||
let name: SharedString = match block {
|
||||
Block::Custom(block) => {
|
||||
let mut element = block.render(&mut BlockContext {
|
||||
app: cx,
|
||||
window,
|
||||
anchor_x: px(0.),
|
||||
gutter_dimensions: &GutterDimensions::default(),
|
||||
line_height: px(0.),
|
||||
em_width: px(0.),
|
||||
max_width: px(0.),
|
||||
block_id,
|
||||
selected: false,
|
||||
editor_style: &editor::EditorStyle::default(),
|
||||
});
|
||||
let element = element.downcast_mut::<Stateful<Div>>().unwrap();
|
||||
element
|
||||
.interactivity()
|
||||
.element_id
|
||||
.clone()?
|
||||
.try_into()
|
||||
.ok()?
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Some((row, name))
|
||||
}),
|
||||
)
|
||||
});
|
||||
Block::FoldedBuffer { .. } => FILE_HEADER.into(),
|
||||
Block::ExcerptBoundary {
|
||||
starts_new_buffer, ..
|
||||
} => {
|
||||
if *starts_new_buffer {
|
||||
FILE_HEADER.into()
|
||||
} else {
|
||||
EXCERPT_HEADER.into()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
div().into_any()
|
||||
});
|
||||
Some((row, name))
|
||||
}),
|
||||
)
|
||||
});
|
||||
|
||||
div().into_any()
|
||||
},
|
||||
);
|
||||
blocks
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue