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:
Nathan Sobo 2025-01-25 20:02:45 -07:00 committed by GitHub
parent 21b4a0d50e
commit 6fca1d2b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
648 changed files with 36248 additions and 28208 deletions

View file

@ -6,8 +6,8 @@ use crate::Buffer;
use clock::ReplicaId;
use collections::BTreeMap;
use futures::FutureExt as _;
use gpui::{AppContext, BorrowAppContext, Model};
use gpui::{Context, TestAppContext};
use gpui::TestAppContext;
use gpui::{App, AppContext as _, BorrowAppContext, Entity};
use indoc::indoc;
use proto::deserialize_operation;
use rand::prelude::*;
@ -42,10 +42,10 @@ fn init_logger() {
}
#[gpui::test]
fn test_line_endings(cx: &mut gpui::AppContext) {
fn test_line_endings(cx: &mut gpui::App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer =
Buffer::local("one\r\ntwo\rthree", cx).with_language(Arc::new(rust_lang()), cx);
assert_eq!(buffer.text(), "one\ntwo\nthree");
@ -67,7 +67,7 @@ fn test_line_endings(cx: &mut gpui::AppContext) {
}
#[gpui::test]
fn test_select_language(cx: &mut AppContext) {
fn test_select_language(cx: &mut App) {
init_settings(cx, |_| {});
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
@ -256,13 +256,13 @@ fn file(path: &str) -> Arc<dyn File> {
}
#[gpui::test]
fn test_edit_events(cx: &mut gpui::AppContext) {
fn test_edit_events(cx: &mut gpui::App) {
let mut now = Instant::now();
let buffer_1_events = Arc::new(Mutex::new(Vec::new()));
let buffer_2_events = Arc::new(Mutex::new(Vec::new()));
let buffer1 = cx.new_model(|cx| Buffer::local("abcdef", cx));
let buffer2 = cx.new_model(|cx| {
let buffer1 = cx.new(|cx| Buffer::local("abcdef", cx));
let buffer2 = cx.new(|cx| {
Buffer::remote(
BufferId::from(cx.entity_id().as_non_zero_u64()),
1,
@ -354,7 +354,7 @@ fn test_edit_events(cx: &mut gpui::AppContext) {
#[gpui::test]
async fn test_apply_diff(cx: &mut TestAppContext) {
let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n";
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
let buffer = cx.new(|cx| Buffer::local(text, cx));
let anchor = buffer.update(cx, |buffer, _| buffer.anchor_before(Point::new(3, 3)));
let text = "a\nccc\ndddd\nffffff\n";
@ -386,7 +386,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
]
.join("\n");
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
let buffer = cx.new(|cx| Buffer::local(text, cx));
// Spawn a task to format the buffer's whitespace.
// Pause so that the formatting task starts running.
@ -450,8 +450,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_reparse(cx: &mut gpui::TestAppContext) {
let text = "fn a() {}";
let buffer =
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
// Wait for the initial text to parse
cx.executor().run_until_parked();
@ -577,7 +576,7 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_resetting_language(cx: &mut gpui::TestAppContext) {
let buffer = cx.new_model(|cx| {
let buffer = cx.new(|cx| {
let mut buffer = Buffer::local("{}", cx).with_language(Arc::new(rust_lang()), cx);
buffer.set_sync_parse_timeout(Duration::ZERO);
buffer
@ -626,8 +625,7 @@ async fn test_outline(cx: &mut gpui::TestAppContext) {
"#
.unindent();
let buffer =
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let outline = buffer
.update(cx, |buffer, _| buffer.snapshot().outline(None))
.unwrap();
@ -711,8 +709,7 @@ async fn test_outline_nodes_with_newlines(cx: &mut gpui::TestAppContext) {
"#
.unindent();
let buffer =
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let outline = buffer
.update(cx, |buffer, _| buffer.snapshot().outline(None))
.unwrap();
@ -748,7 +745,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
"#
.unindent();
let buffer = cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(language), cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(language), cx));
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
// extra context nodes are included in the outline.
@ -774,7 +771,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
}
#[gpui::test]
fn test_outline_annotations(cx: &mut AppContext) {
fn test_outline_annotations(cx: &mut App) {
// Add this new test case
let text = r#"
/// This is a doc comment
@ -794,8 +791,7 @@ fn test_outline_annotations(cx: &mut AppContext) {
"#
.unindent();
let buffer =
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let outline = buffer
.update(cx, |buffer, _| buffer.snapshot().outline(None))
.unwrap();
@ -845,8 +841,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
"#
.unindent();
let buffer =
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
// point is at the start of an item
@ -916,7 +911,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
}
#[gpui::test]
fn test_text_objects(cx: &mut AppContext) {
fn test_text_objects(cx: &mut App) {
let (text, ranges) = marked_text_ranges(
indoc! {r#"
impl Hello {
@ -927,7 +922,7 @@ fn test_text_objects(cx: &mut AppContext) {
);
let buffer =
cx.new_model(|cx| Buffer::local(text.clone(), cx).with_language(Arc::new(rust_lang()), cx));
cx.new(|cx| Buffer::local(text.clone(), cx).with_language(Arc::new(rust_lang()), cx));
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
let matches = snapshot
@ -949,7 +944,7 @@ fn test_text_objects(cx: &mut AppContext) {
}
#[gpui::test]
fn test_enclosing_bracket_ranges(cx: &mut AppContext) {
fn test_enclosing_bracket_ranges(cx: &mut App) {
let mut assert = |selection_text, range_markers| {
assert_bracket_pairs(selection_text, range_markers, rust_lang(), cx)
};
@ -1065,7 +1060,7 @@ fn test_enclosing_bracket_ranges(cx: &mut AppContext) {
}
#[gpui::test]
fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &mut AppContext) {
fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &mut App) {
let mut assert = |selection_text, bracket_pair_texts| {
assert_bracket_pairs(selection_text, bracket_pair_texts, javascript_lang(), cx)
};
@ -1097,8 +1092,8 @@ fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &
}
#[gpui::test]
fn test_range_for_syntax_ancestor(cx: &mut AppContext) {
cx.new_model(|cx| {
fn test_range_for_syntax_ancestor(cx: &mut App) {
cx.new(|cx| {
let text = "fn a() { b(|c| {}) }";
let buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
let snapshot = buffer.snapshot();
@ -1147,10 +1142,10 @@ fn test_range_for_syntax_ancestor(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_with_soft_tabs(cx: &mut AppContext) {
fn test_autoindent_with_soft_tabs(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = "fn a() {}";
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
@ -1187,12 +1182,12 @@ fn test_autoindent_with_soft_tabs(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_with_hard_tabs(cx: &mut AppContext) {
fn test_autoindent_with_hard_tabs(cx: &mut App) {
init_settings(cx, |settings| {
settings.defaults.hard_tabs = Some(true);
});
cx.new_model(|cx| {
cx.new(|cx| {
let text = "fn a() {}";
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
@ -1229,10 +1224,10 @@ fn test_autoindent_with_hard_tabs(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppContext) {
fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local(
"
fn a() {
@ -1371,7 +1366,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC
buffer
});
cx.new_model(|cx| {
cx.new(|cx| {
eprintln!("second buffer: {:?}", cx.entity_id());
let mut buffer = Buffer::local(
@ -1434,10 +1429,10 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC
}
#[gpui::test]
fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut AppContext) {
fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local(
"
fn a() {
@ -1495,10 +1490,10 @@ fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut Ap
}
#[gpui::test]
fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) {
fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local(
"
fn a() {}
@ -1551,10 +1546,10 @@ fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) {
fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = "a\nb";
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
buffer.edit(
@ -1568,10 +1563,10 @@ fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_multi_line_insertion(cx: &mut AppContext) {
fn test_autoindent_multi_line_insertion(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = "
const a: usize = 1;
fn b() {
@ -1609,10 +1604,10 @@ fn test_autoindent_multi_line_insertion(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_block_mode(cx: &mut AppContext) {
fn test_autoindent_block_mode(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = r#"
fn a() {
b();
@ -1692,10 +1687,10 @@ fn test_autoindent_block_mode(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContext) {
fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = r#"
fn a() {
if b() {
@ -1771,10 +1766,10 @@ fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContex
}
#[gpui::test]
fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut AppContext) {
fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let (text, ranges_to_replace) = marked_text_ranges(
&"
mod numbers {
@ -1834,10 +1829,10 @@ fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_language_without_indents_query(cx: &mut AppContext) {
fn test_autoindent_language_without_indents_query(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = "
* one
- a
@ -1878,7 +1873,7 @@ fn test_autoindent_language_without_indents_query(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
fn test_autoindent_with_injected_languages(cx: &mut App) {
init_settings(cx, |settings| {
settings.languages.extend([
(
@ -1906,7 +1901,7 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
language_registry.add(html_language.clone());
language_registry.add(javascript_language.clone());
cx.new_model(|cx| {
cx.new(|cx| {
let (text, ranges) = marked_text_ranges(
&"
<div>ˇ
@ -1952,12 +1947,12 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
}
#[gpui::test]
fn test_autoindent_query_with_outdent_captures(cx: &mut AppContext) {
fn test_autoindent_query_with_outdent_captures(cx: &mut App) {
init_settings(cx, |settings| {
settings.defaults.tab_size = Some(2.try_into().unwrap());
});
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("", cx).with_language(Arc::new(ruby_lang()), cx);
let text = r#"
@ -2001,7 +1996,7 @@ async fn test_async_autoindents_preserve_preview(cx: &mut TestAppContext) {
// First we insert some newlines to request an auto-indent (asynchronously).
// Then we request that a preview tab be preserved for the new version, even though it's edited.
let buffer = cx.new_model(|cx| {
let buffer = cx.new(|cx| {
let text = "fn a() {}";
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
@ -2053,11 +2048,11 @@ async fn test_async_autoindents_preserve_preview(cx: &mut TestAppContext) {
}
#[gpui::test]
fn test_insert_empty_line(cx: &mut AppContext) {
fn test_insert_empty_line(cx: &mut App) {
init_settings(cx, |_| {});
// Insert empty line at the beginning, requesting an empty line above
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
let point = buffer.insert_empty_line(Point::new(0, 0), true, false, cx);
assert_eq!(buffer.text(), "\nabc\ndef\nghi");
@ -2066,7 +2061,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line at the beginning, requesting an empty line above and below
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
let point = buffer.insert_empty_line(Point::new(0, 0), true, true, cx);
assert_eq!(buffer.text(), "\n\nabc\ndef\nghi");
@ -2075,7 +2070,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line at the start of a line, requesting empty lines above and below
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
let point = buffer.insert_empty_line(Point::new(2, 0), true, true, cx);
assert_eq!(buffer.text(), "abc\ndef\n\n\n\nghi");
@ -2084,7 +2079,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line in the middle of a line, requesting empty lines above and below
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndefghi\njkl", cx);
let point = buffer.insert_empty_line(Point::new(1, 3), true, true, cx);
assert_eq!(buffer.text(), "abc\ndef\n\n\n\nghi\njkl");
@ -2093,7 +2088,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line in the middle of a line, requesting empty line above only
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndefghi\njkl", cx);
let point = buffer.insert_empty_line(Point::new(1, 3), true, false, cx);
assert_eq!(buffer.text(), "abc\ndef\n\n\nghi\njkl");
@ -2102,7 +2097,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line in the middle of a line, requesting empty line below only
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndefghi\njkl", cx);
let point = buffer.insert_empty_line(Point::new(1, 3), false, true, cx);
assert_eq!(buffer.text(), "abc\ndef\n\n\nghi\njkl");
@ -2111,7 +2106,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line at the end, requesting empty lines above and below
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
let point = buffer.insert_empty_line(Point::new(2, 3), true, true, cx);
assert_eq!(buffer.text(), "abc\ndef\nghi\n\n\n");
@ -2120,7 +2115,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line at the end, requesting empty line above only
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
let point = buffer.insert_empty_line(Point::new(2, 3), true, false, cx);
assert_eq!(buffer.text(), "abc\ndef\nghi\n\n");
@ -2129,7 +2124,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
});
// Insert empty line at the end, requesting empty line below only
cx.new_model(|cx| {
cx.new(|cx| {
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
let point = buffer.insert_empty_line(Point::new(2, 3), false, true, cx);
assert_eq!(buffer.text(), "abc\ndef\nghi\n\n");
@ -2139,10 +2134,10 @@ fn test_insert_empty_line(cx: &mut AppContext) {
}
#[gpui::test]
fn test_language_scope_at_with_javascript(cx: &mut AppContext) {
fn test_language_scope_at_with_javascript(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let language = Language::new(
LanguageConfig {
name: "JavaScript".into(),
@ -2281,10 +2276,10 @@ fn test_language_scope_at_with_javascript(cx: &mut AppContext) {
}
#[gpui::test]
fn test_language_scope_at_with_rust(cx: &mut AppContext) {
fn test_language_scope_at_with_rust(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let language = Language::new(
LanguageConfig {
name: "Rust".into(),
@ -2350,10 +2345,10 @@ fn test_language_scope_at_with_rust(cx: &mut AppContext) {
}
#[gpui::test]
fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) {
fn test_language_scope_at_with_combined_injections(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = r#"
<ol>
<% people.each do |person| %>
@ -2398,10 +2393,10 @@ fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) {
}
#[gpui::test]
fn test_language_at_with_hidden_languages(cx: &mut AppContext) {
fn test_language_at_with_hidden_languages(cx: &mut App) {
init_settings(cx, |_| {});
cx.new_model(|cx| {
cx.new(|cx| {
let text = r#"
this is an *emphasized* word.
"#
@ -2437,10 +2432,10 @@ fn test_language_at_with_hidden_languages(cx: &mut AppContext) {
}
#[gpui::test]
fn test_serialization(cx: &mut gpui::AppContext) {
fn test_serialization(cx: &mut gpui::App) {
let mut now = Instant::now();
let buffer1 = cx.new_model(|cx| {
let buffer1 = cx.new(|cx| {
let mut buffer = Buffer::local("abc", cx);
buffer.edit([(3..3, "D")], None, cx);
@ -2463,7 +2458,7 @@ fn test_serialization(cx: &mut gpui::AppContext) {
let ops = cx
.background_executor()
.block(buffer1.read(cx).serialize_ops(None, cx));
let buffer2 = cx.new_model(|cx| {
let buffer2 = cx.new(|cx| {
let mut buffer = Buffer::from_proto(1, Capability::ReadWrite, state, None).unwrap();
buffer.apply_ops(
ops.into_iter()
@ -2479,10 +2474,10 @@ fn test_serialization(cx: &mut gpui::AppContext) {
fn test_branch_and_merge(cx: &mut TestAppContext) {
cx.update(|cx| init_settings(cx, |_| {}));
let base = cx.new_model(|cx| Buffer::local("one\ntwo\nthree\n", cx));
let base = cx.new(|cx| Buffer::local("one\ntwo\nthree\n", cx));
// Create a remote replica of the base buffer.
let base_replica = cx.new_model(|cx| {
let base_replica = cx.new(|cx| {
Buffer::from_proto(1, Capability::ReadWrite, base.read(cx).to_proto(cx), None).unwrap()
});
base.update(cx, |_buffer, cx| {
@ -2566,7 +2561,7 @@ fn test_branch_and_merge(cx: &mut TestAppContext) {
fn test_merge_into_base(cx: &mut TestAppContext) {
cx.update(|cx| init_settings(cx, |_| {}));
let base = cx.new_model(|cx| Buffer::local("abcdefghijk", cx));
let base = cx.new(|cx| Buffer::local("abcdefghijk", cx));
let branch = base.update(cx, |buffer, cx| buffer.branch(cx));
// Make 3 edits, merge one into the base.
@ -2606,7 +2601,7 @@ fn test_merge_into_base(cx: &mut TestAppContext) {
fn test_undo_after_merge_into_base(cx: &mut TestAppContext) {
cx.update(|cx| init_settings(cx, |_| {}));
let base = cx.new_model(|cx| Buffer::local("abcdefghijk", cx));
let base = cx.new(|cx| Buffer::local("abcdefghijk", cx));
let branch = base.update(cx, |buffer, cx| buffer.branch(cx));
// Make 2 edits, merge one into the base.
@ -2655,7 +2650,7 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
LanguageConfig::default(),
Some(tree_sitter_rust::LANGUAGE.into()),
));
let buffer = cx.new_model(|cx| Buffer::local(text, cx).with_language(language, cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(language, cx));
let highlighted_edits = preview_edits(
&buffer,
cx,
@ -2672,7 +2667,7 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
);
async fn preview_edits(
buffer: &Model<Buffer>,
buffer: &Entity<Buffer>,
cx: &mut TestAppContext,
edits: impl IntoIterator<Item = (Range<Point>, &'static str)>,
) -> HighlightedEdits {
@ -2714,7 +2709,7 @@ async fn test_preview_edits_interpolate(cx: &mut TestAppContext) {
LanguageConfig::default(),
Some(tree_sitter_rust::LANGUAGE.into()),
));
let buffer = cx.new_model(|cx| Buffer::local(text, cx).with_language(language, cx));
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(language, cx));
let edits = construct_edits(&buffer, [(Point::new(1, 4)..Point::new(1, 4), "first")], cx);
let edit_preview = buffer
@ -2754,7 +2749,7 @@ async fn test_preview_edits_interpolate(cx: &mut TestAppContext) {
);
fn construct_edits(
buffer: &Model<Buffer>,
buffer: &Entity<Buffer>,
edits: impl IntoIterator<Item = (Range<Point>, &'static str)>,
cx: &mut TestAppContext,
) -> Arc<[(Range<Anchor>, String)]> {
@ -2775,7 +2770,7 @@ async fn test_preview_edits_interpolate(cx: &mut TestAppContext) {
}
#[gpui::test(iterations = 100)]
fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
fn test_random_collaboration(cx: &mut App, mut rng: StdRng) {
let min_peers = env::var("MIN_PEERS")
.map(|i| i.parse().expect("invalid `MIN_PEERS` variable"))
.unwrap_or(1);
@ -2793,10 +2788,10 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
let mut replica_ids = Vec::new();
let mut buffers = Vec::new();
let network = Arc::new(Mutex::new(Network::new(rng.clone())));
let base_buffer = cx.new_model(|cx| Buffer::local(base_text.as_str(), cx));
let base_buffer = cx.new(|cx| Buffer::local(base_text.as_str(), cx));
for i in 0..rng.gen_range(min_peers..=max_peers) {
let buffer = cx.new_model(|cx| {
let buffer = cx.new(|cx| {
let state = base_buffer.read(cx).to_proto(cx);
let ops = cx
.background_executor()
@ -2810,7 +2805,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
);
buffer.set_group_interval(Duration::from_millis(rng.gen_range(0..=200)));
let network = network.clone();
cx.subscribe(&cx.handle(), move |buffer, _, event, _| {
cx.subscribe(&cx.model(), move |buffer, _, event, _| {
if let BufferEvent::Operation {
operation,
is_local: true,
@ -2920,7 +2915,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
new_replica_id,
replica_id
);
new_buffer = Some(cx.new_model(|cx| {
new_buffer = Some(cx.new(|cx| {
let mut new_buffer = Buffer::from_proto(
new_replica_id,
Capability::ReadWrite,
@ -2941,7 +2936,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
);
new_buffer.set_group_interval(Duration::from_millis(rng.gen_range(0..=200)));
let network = network.clone();
cx.subscribe(&cx.handle(), move |buffer, _, event, _| {
cx.subscribe(&cx.model(), move |buffer, _, event, _| {
if let BufferEvent::Operation {
operation,
is_local: true,
@ -3357,7 +3352,7 @@ pub fn markdown_inline_lang() -> Language {
.unwrap()
}
fn get_tree_sexp(buffer: &Model<Buffer>, cx: &mut gpui::TestAppContext) -> String {
fn get_tree_sexp(buffer: &Entity<Buffer>, cx: &mut gpui::TestAppContext) -> String {
buffer.update(cx, |buffer, _| {
let snapshot = buffer.snapshot();
let layers = snapshot.syntax.layers(buffer.as_text_snapshot());
@ -3370,12 +3365,11 @@ fn assert_bracket_pairs(
selection_text: &'static str,
bracket_pair_texts: Vec<&'static str>,
language: Language,
cx: &mut AppContext,
cx: &mut App,
) {
let (expected_text, selection_ranges) = marked_text_ranges(selection_text, false);
let buffer = cx.new_model(|cx| {
Buffer::local(expected_text.clone(), cx).with_language(Arc::new(language), cx)
});
let buffer =
cx.new(|cx| Buffer::local(expected_text.clone(), cx).with_language(Arc::new(language), cx));
let buffer = buffer.update(cx, |buffer, _cx| buffer.snapshot());
let selection_range = selection_ranges[0].clone();
@ -3395,7 +3389,7 @@ fn assert_bracket_pairs(
);
}
fn init_settings(cx: &mut AppContext, f: fn(&mut AllLanguageSettingsContent)) {
fn init_settings(cx: &mut App, f: fn(&mut AllLanguageSettingsContent)) {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
crate::init(cx);