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,6 +1,6 @@
|
|||
use super::*;
|
||||
use git::diff::DiffHunkStatus;
|
||||
use gpui::{AppContext, Context, TestAppContext};
|
||||
use gpui::{App, TestAppContext};
|
||||
use indoc::indoc;
|
||||
use language::{Buffer, Rope};
|
||||
use parking_lot::RwLock;
|
||||
|
@ -17,9 +17,9 @@ fn init_logger() {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_empty_singleton(cx: &mut AppContext) {
|
||||
let buffer = cx.new_model(|cx| Buffer::local("", cx));
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
fn test_empty_singleton(cx: &mut App) {
|
||||
let buffer = cx.new(|cx| Buffer::local("", cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
assert_eq!(snapshot.text(), "");
|
||||
assert_eq!(
|
||||
|
@ -33,9 +33,9 @@ fn test_empty_singleton(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_singleton(cx: &mut AppContext) {
|
||||
let buffer = cx.new_model(|cx| Buffer::local(sample_text(6, 6, 'a'), cx));
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
fn test_singleton(cx: &mut App) {
|
||||
let buffer = cx.new(|cx| Buffer::local(sample_text(6, 6, 'a'), cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
|
||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
assert_eq!(snapshot.text(), buffer.read(cx).text());
|
||||
|
@ -68,9 +68,9 @@ fn test_singleton(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_remote(cx: &mut AppContext) {
|
||||
let host_buffer = cx.new_model(|cx| Buffer::local("a", cx));
|
||||
let guest_buffer = cx.new_model(|cx| {
|
||||
fn test_remote(cx: &mut App) {
|
||||
let host_buffer = cx.new(|cx| Buffer::local("a", cx));
|
||||
let guest_buffer = cx.new(|cx| {
|
||||
let state = host_buffer.read(cx).to_proto(cx);
|
||||
let ops = cx
|
||||
.background_executor()
|
||||
|
@ -83,7 +83,7 @@ fn test_remote(cx: &mut AppContext) {
|
|||
);
|
||||
buffer
|
||||
});
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(guest_buffer.clone(), cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(guest_buffer.clone(), cx));
|
||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
assert_eq!(snapshot.text(), "a");
|
||||
|
||||
|
@ -97,10 +97,10 @@ fn test_remote(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_excerpt_boundaries_and_clipping(cx: &mut AppContext) {
|
||||
let buffer_1 = cx.new_model(|cx| Buffer::local(sample_text(6, 6, 'a'), cx));
|
||||
let buffer_2 = cx.new_model(|cx| Buffer::local(sample_text(6, 6, 'g'), cx));
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
fn test_excerpt_boundaries_and_clipping(cx: &mut App) {
|
||||
let buffer_1 = cx.new(|cx| Buffer::local(sample_text(6, 6, 'a'), cx));
|
||||
let buffer_2 = cx.new(|cx| Buffer::local(sample_text(6, 6, 'g'), cx));
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
|
||||
let events = Arc::new(RwLock::new(Vec::<Event>::new()));
|
||||
multibuffer.update(cx, |_, cx| {
|
||||
|
@ -354,17 +354,17 @@ fn test_excerpt_boundaries_and_clipping(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_diff_boundary_anchors(cx: &mut AppContext) {
|
||||
fn test_diff_boundary_anchors(cx: &mut App) {
|
||||
let base_text = "one\ntwo\nthree\n";
|
||||
let text = "one\nthree\n";
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
let change_set = cx.new_model(|cx| {
|
||||
let change_set = cx.new(|cx| {
|
||||
let mut change_set = BufferChangeSet::new(&buffer, cx);
|
||||
change_set.recalculate_diff_sync(base_text.into(), snapshot.text, true, cx);
|
||||
change_set
|
||||
});
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
multibuffer.update(cx, |multibuffer, cx| {
|
||||
multibuffer.add_change_set(change_set, cx)
|
||||
});
|
||||
|
@ -406,14 +406,14 @@ fn test_diff_boundary_anchors(cx: &mut AppContext) {
|
|||
fn test_diff_hunks_in_range(cx: &mut TestAppContext) {
|
||||
let base_text = "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\n";
|
||||
let text = "one\nfour\nseven\n";
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let change_set = cx.new_model(|cx| {
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
let change_set = cx.new(|cx| {
|
||||
let mut change_set = BufferChangeSet::new(&buffer, cx);
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
change_set.recalculate_diff_sync(base_text.into(), snapshot.text, true, cx);
|
||||
change_set
|
||||
});
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (mut snapshot, mut subscription) = multibuffer.update(cx, |multibuffer, cx| {
|
||||
(multibuffer.snapshot(cx), multibuffer.subscribe())
|
||||
});
|
||||
|
@ -504,14 +504,14 @@ fn test_diff_hunks_in_range(cx: &mut TestAppContext) {
|
|||
fn test_editing_text_in_diff_hunks(cx: &mut TestAppContext) {
|
||||
let base_text = "one\ntwo\nfour\nfive\nsix\nseven\n";
|
||||
let text = "one\ntwo\nTHREE\nfour\nfive\nseven\n";
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let change_set = cx.new_model(|cx| {
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
let change_set = cx.new(|cx| {
|
||||
let mut change_set = BufferChangeSet::new(&buffer, cx);
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
change_set.recalculate_diff_sync(base_text.into(), snapshot.text, true, cx);
|
||||
change_set
|
||||
});
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
|
||||
let (mut snapshot, mut subscription) = multibuffer.update(cx, |multibuffer, cx| {
|
||||
multibuffer.add_change_set(change_set.clone(), cx);
|
||||
|
@ -660,12 +660,12 @@ fn test_editing_text_in_diff_hunks(cx: &mut TestAppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_excerpt_events(cx: &mut AppContext) {
|
||||
let buffer_1 = cx.new_model(|cx| Buffer::local(sample_text(10, 3, 'a'), cx));
|
||||
let buffer_2 = cx.new_model(|cx| Buffer::local(sample_text(10, 3, 'm'), cx));
|
||||
fn test_excerpt_events(cx: &mut App) {
|
||||
let buffer_1 = cx.new(|cx| Buffer::local(sample_text(10, 3, 'a'), cx));
|
||||
let buffer_2 = cx.new(|cx| Buffer::local(sample_text(10, 3, 'm'), cx));
|
||||
|
||||
let leader_multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let follower_multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let leader_multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let follower_multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let follower_edit_event_count = Arc::new(RwLock::new(0));
|
||||
|
||||
follower_multibuffer.update(cx, |_, cx| {
|
||||
|
@ -766,9 +766,9 @@ fn test_excerpt_events(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_expand_excerpts(cx: &mut AppContext) {
|
||||
let buffer = cx.new_model(|cx| Buffer::local(sample_text(20, 3, 'a'), cx));
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
fn test_expand_excerpts(cx: &mut App) {
|
||||
let buffer = cx.new(|cx| Buffer::local(sample_text(20, 3, 'a'), cx));
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
|
||||
multibuffer.update(cx, |multibuffer, cx| {
|
||||
multibuffer.push_excerpts_with_context_lines(
|
||||
|
@ -842,9 +842,9 @@ fn test_expand_excerpts(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_push_excerpts_with_context_lines(cx: &mut AppContext) {
|
||||
let buffer = cx.new_model(|cx| Buffer::local(sample_text(20, 3, 'a'), cx));
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
fn test_push_excerpts_with_context_lines(cx: &mut App) {
|
||||
let buffer = cx.new(|cx| Buffer::local(sample_text(20, 3, 'a'), cx));
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| {
|
||||
multibuffer.push_excerpts_with_context_lines(
|
||||
buffer.clone(),
|
||||
|
@ -896,8 +896,8 @@ fn test_push_excerpts_with_context_lines(cx: &mut AppContext) {
|
|||
|
||||
#[gpui::test(iterations = 100)]
|
||||
async fn test_push_multiple_excerpts_with_context_lines(cx: &mut TestAppContext) {
|
||||
let buffer_1 = cx.new_model(|cx| Buffer::local(sample_text(20, 3, 'a'), cx));
|
||||
let buffer_2 = cx.new_model(|cx| Buffer::local(sample_text(15, 4, 'a'), cx));
|
||||
let buffer_1 = cx.new(|cx| Buffer::local(sample_text(20, 3, 'a'), cx));
|
||||
let buffer_2 = cx.new(|cx| Buffer::local(sample_text(15, 4, 'a'), cx));
|
||||
let snapshot_1 = buffer_1.update(cx, |buffer, _| buffer.snapshot());
|
||||
let snapshot_2 = buffer_2.update(cx, |buffer, _| buffer.snapshot());
|
||||
let ranges_1 = vec![
|
||||
|
@ -910,7 +910,7 @@ async fn test_push_multiple_excerpts_with_context_lines(cx: &mut TestAppContext)
|
|||
snapshot_2.anchor_before(Point::new(10, 0))..snapshot_2.anchor_before(Point::new(10, 2)),
|
||||
];
|
||||
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let anchor_ranges = multibuffer
|
||||
.update(cx, |multibuffer, cx| {
|
||||
multibuffer.push_multiple_excerpts_with_context_lines(
|
||||
|
@ -972,8 +972,8 @@ async fn test_push_multiple_excerpts_with_context_lines(cx: &mut TestAppContext)
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_empty_multibuffer(cx: &mut AppContext) {
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
fn test_empty_multibuffer(cx: &mut App) {
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
|
||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
assert_eq!(snapshot.text(), "");
|
||||
|
@ -994,9 +994,9 @@ fn test_empty_multibuffer(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_singleton_multibuffer_anchors(cx: &mut AppContext) {
|
||||
let buffer = cx.new_model(|cx| Buffer::local("abcd", cx));
|
||||
let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
fn test_singleton_multibuffer_anchors(cx: &mut App) {
|
||||
let buffer = cx.new(|cx| Buffer::local("abcd", cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer.clone(), cx));
|
||||
let old_snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit([(0..0, "X")], None, cx);
|
||||
|
@ -1014,10 +1014,10 @@ fn test_singleton_multibuffer_anchors(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_multibuffer_anchors(cx: &mut AppContext) {
|
||||
let buffer_1 = cx.new_model(|cx| Buffer::local("abcd", cx));
|
||||
let buffer_2 = cx.new_model(|cx| Buffer::local("efghi", cx));
|
||||
let multibuffer = cx.new_model(|cx| {
|
||||
fn test_multibuffer_anchors(cx: &mut App) {
|
||||
let buffer_1 = cx.new(|cx| Buffer::local("abcd", cx));
|
||||
let buffer_2 = cx.new(|cx| Buffer::local("efghi", cx));
|
||||
let multibuffer = cx.new(|cx| {
|
||||
let mut multibuffer = MultiBuffer::new(Capability::ReadWrite);
|
||||
multibuffer.push_excerpts(
|
||||
buffer_1.clone(),
|
||||
|
@ -1072,10 +1072,10 @@ fn test_multibuffer_anchors(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_resolving_anchors_after_replacing_their_excerpts(cx: &mut AppContext) {
|
||||
let buffer_1 = cx.new_model(|cx| Buffer::local("abcd", cx));
|
||||
let buffer_2 = cx.new_model(|cx| Buffer::local("ABCDEFGHIJKLMNOP", cx));
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
fn test_resolving_anchors_after_replacing_their_excerpts(cx: &mut App) {
|
||||
let buffer_1 = cx.new(|cx| Buffer::local("abcd", cx));
|
||||
let buffer_2 = cx.new(|cx| Buffer::local("ABCDEFGHIJKLMNOP", cx));
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
|
||||
// Create an insertion id in buffer 1 that doesn't exist in buffer 2.
|
||||
// Add an excerpt from buffer 1 that spans this new insertion.
|
||||
|
@ -1224,12 +1224,12 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) {
|
|||
"
|
||||
);
|
||||
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
let change_set =
|
||||
cx.new_model(|cx| BufferChangeSet::new_with_base_text(base_text.to_string(), &buffer, cx));
|
||||
cx.new(|cx| BufferChangeSet::new_with_base_text(base_text.to_string(), &buffer, cx));
|
||||
cx.run_until_parked();
|
||||
|
||||
let multibuffer = cx.new_model(|cx| {
|
||||
let multibuffer = cx.new(|cx| {
|
||||
let mut multibuffer = MultiBuffer::singleton(buffer.clone(), cx);
|
||||
multibuffer.add_change_set(change_set.clone(), cx);
|
||||
multibuffer
|
||||
|
@ -1468,12 +1468,12 @@ fn test_repeatedly_expand_a_diff_hunk(cx: &mut TestAppContext) {
|
|||
"
|
||||
);
|
||||
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
let change_set =
|
||||
cx.new_model(|cx| BufferChangeSet::new_with_base_text(base_text.to_string(), &buffer, cx));
|
||||
cx.new(|cx| BufferChangeSet::new_with_base_text(base_text.to_string(), &buffer, cx));
|
||||
cx.run_until_parked();
|
||||
|
||||
let multibuffer = cx.new_model(|cx| {
|
||||
let multibuffer = cx.new(|cx| {
|
||||
let mut multibuffer = MultiBuffer::singleton(buffer.clone(), cx);
|
||||
multibuffer.add_change_set(change_set.clone(), cx);
|
||||
multibuffer
|
||||
|
@ -1573,17 +1573,15 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) {
|
|||
"
|
||||
);
|
||||
|
||||
let buffer_1 = cx.new_model(|cx| Buffer::local(text_1, cx));
|
||||
let buffer_2 = cx.new_model(|cx| Buffer::local(text_2, cx));
|
||||
let change_set_1 = cx.new_model(|cx| {
|
||||
BufferChangeSet::new_with_base_text(base_text_1.to_string(), &buffer_1, cx)
|
||||
});
|
||||
let change_set_2 = cx.new_model(|cx| {
|
||||
BufferChangeSet::new_with_base_text(base_text_2.to_string(), &buffer_2, cx)
|
||||
});
|
||||
let buffer_1 = cx.new(|cx| Buffer::local(text_1, cx));
|
||||
let buffer_2 = cx.new(|cx| Buffer::local(text_2, cx));
|
||||
let change_set_1 =
|
||||
cx.new(|cx| BufferChangeSet::new_with_base_text(base_text_1.to_string(), &buffer_1, cx));
|
||||
let change_set_2 =
|
||||
cx.new(|cx| BufferChangeSet::new_with_base_text(base_text_2.to_string(), &buffer_2, cx));
|
||||
cx.run_until_parked();
|
||||
|
||||
let multibuffer = cx.new_model(|cx| {
|
||||
let multibuffer = cx.new(|cx| {
|
||||
let mut multibuffer = MultiBuffer::new(Capability::ReadWrite);
|
||||
multibuffer.push_excerpts(
|
||||
buffer_1.clone(),
|
||||
|
@ -1762,12 +1760,12 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) {
|
|||
#[derive(Default)]
|
||||
struct ReferenceMultibuffer {
|
||||
excerpts: Vec<ReferenceExcerpt>,
|
||||
change_sets: HashMap<BufferId, Model<BufferChangeSet>>,
|
||||
change_sets: HashMap<BufferId, Entity<BufferChangeSet>>,
|
||||
}
|
||||
|
||||
struct ReferenceExcerpt {
|
||||
id: ExcerptId,
|
||||
buffer: Model<Buffer>,
|
||||
buffer: Entity<Buffer>,
|
||||
range: Range<text::Anchor>,
|
||||
expanded_diff_hunks: Vec<text::Anchor>,
|
||||
}
|
||||
|
@ -1780,7 +1778,7 @@ struct ReferenceRegion {
|
|||
}
|
||||
|
||||
impl ReferenceMultibuffer {
|
||||
fn expand_excerpts(&mut self, excerpts: &HashSet<ExcerptId>, line_count: u32, cx: &AppContext) {
|
||||
fn expand_excerpts(&mut self, excerpts: &HashSet<ExcerptId>, line_count: u32, cx: &App) {
|
||||
if line_count == 0 {
|
||||
return;
|
||||
}
|
||||
|
@ -1798,7 +1796,7 @@ impl ReferenceMultibuffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_excerpt(&mut self, id: ExcerptId, cx: &AppContext) {
|
||||
fn remove_excerpt(&mut self, id: ExcerptId, cx: &App) {
|
||||
let ix = self
|
||||
.excerpts
|
||||
.iter()
|
||||
|
@ -1819,7 +1817,7 @@ impl ReferenceMultibuffer {
|
|||
&mut self,
|
||||
prev_id: ExcerptId,
|
||||
new_excerpt_id: ExcerptId,
|
||||
(buffer_handle, anchor_range): (Model<Buffer>, Range<text::Anchor>),
|
||||
(buffer_handle, anchor_range): (Entity<Buffer>, Range<text::Anchor>),
|
||||
) {
|
||||
let excerpt_ix = if prev_id == ExcerptId::max() {
|
||||
self.excerpts.len()
|
||||
|
@ -1841,12 +1839,7 @@ impl ReferenceMultibuffer {
|
|||
);
|
||||
}
|
||||
|
||||
fn expand_diff_hunks(
|
||||
&mut self,
|
||||
excerpt_id: ExcerptId,
|
||||
range: Range<text::Anchor>,
|
||||
cx: &AppContext,
|
||||
) {
|
||||
fn expand_diff_hunks(&mut self, excerpt_id: ExcerptId, range: Range<text::Anchor>, cx: &App) {
|
||||
let excerpt = self
|
||||
.excerpts
|
||||
.iter_mut()
|
||||
|
@ -1894,7 +1887,7 @@ impl ReferenceMultibuffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn expected_content(&self, cx: &AppContext) -> (String, Vec<RowInfo>, HashSet<MultiBufferRow>) {
|
||||
fn expected_content(&self, cx: &App) -> (String, Vec<RowInfo>, HashSet<MultiBufferRow>) {
|
||||
let mut text = String::new();
|
||||
let mut regions = Vec::<ReferenceRegion>::new();
|
||||
let mut excerpt_boundary_rows = HashSet::default();
|
||||
|
@ -2030,7 +2023,7 @@ impl ReferenceMultibuffer {
|
|||
(text, row_infos, excerpt_boundary_rows)
|
||||
}
|
||||
|
||||
fn diffs_updated(&mut self, cx: &AppContext) {
|
||||
fn diffs_updated(&mut self, cx: &App) {
|
||||
for excerpt in &mut self.excerpts {
|
||||
let buffer = excerpt.buffer.read(cx).snapshot();
|
||||
let excerpt_range = excerpt.range.to_offset(&buffer);
|
||||
|
@ -2064,20 +2057,20 @@ impl ReferenceMultibuffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_change_set(&mut self, change_set: Model<BufferChangeSet>, cx: &mut AppContext) {
|
||||
fn add_change_set(&mut self, change_set: Entity<BufferChangeSet>, cx: &mut App) {
|
||||
let buffer_id = change_set.read(cx).buffer_id;
|
||||
self.change_sets.insert(buffer_id, change_set);
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test(iterations = 100)]
|
||||
fn test_random_multibuffer(cx: &mut AppContext, mut rng: StdRng) {
|
||||
fn test_random_multibuffer(cx: &mut App, mut rng: StdRng) {
|
||||
let operations = env::var("OPERATIONS")
|
||||
.map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
|
||||
.unwrap_or(10);
|
||||
|
||||
let mut buffers: Vec<Model<Buffer>> = Vec::new();
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let mut buffers: Vec<Entity<Buffer>> = Vec::new();
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let mut reference = ReferenceMultibuffer::default();
|
||||
let mut anchors = Vec::new();
|
||||
let mut old_versions = Vec::new();
|
||||
|
@ -2214,9 +2207,9 @@ fn test_random_multibuffer(cx: &mut AppContext, mut rng: StdRng) {
|
|||
.take(256)
|
||||
.collect::<String>();
|
||||
|
||||
let buffer = cx.new_model(|cx| Buffer::local(base_text.clone(), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(base_text.clone(), cx));
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
let change_set = cx.new_model(|cx| {
|
||||
let change_set = cx.new(|cx| {
|
||||
let mut change_set = BufferChangeSet::new(&buffer, cx);
|
||||
change_set.recalculate_diff_sync(base_text, snapshot.text, true, cx);
|
||||
change_set
|
||||
|
@ -2431,21 +2424,21 @@ fn test_random_multibuffer(cx: &mut AppContext, mut rng: StdRng) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_history(cx: &mut AppContext) {
|
||||
fn test_history(cx: &mut App) {
|
||||
let test_settings = SettingsStore::test(cx);
|
||||
cx.set_global(test_settings);
|
||||
let group_interval: Duration = Duration::from_millis(1);
|
||||
let buffer_1 = cx.new_model(|cx| {
|
||||
let buffer_1 = cx.new(|cx| {
|
||||
let mut buf = Buffer::local("1234", cx);
|
||||
buf.set_group_interval(group_interval);
|
||||
buf
|
||||
});
|
||||
let buffer_2 = cx.new_model(|cx| {
|
||||
let buffer_2 = cx.new(|cx| {
|
||||
let mut buf = Buffer::local("5678", cx);
|
||||
buf.set_group_interval(group_interval);
|
||||
buf
|
||||
});
|
||||
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
multibuffer.update(cx, |this, _| {
|
||||
this.history.group_interval = group_interval;
|
||||
});
|
||||
|
@ -2710,7 +2703,7 @@ fn format_diff(
|
|||
|
||||
#[track_caller]
|
||||
fn assert_new_snapshot(
|
||||
multibuffer: &Model<MultiBuffer>,
|
||||
multibuffer: &Entity<MultiBuffer>,
|
||||
snapshot: &mut MultiBufferSnapshot,
|
||||
subscription: &mut Subscription,
|
||||
cx: &mut TestAppContext,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue