History

sum_tree: Replace rayon with futures (#41586)

Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored by: Kate <kate@zed.dev>

Lukas Wirth committed 1 year ago

Commit f2ce06c1 parent 7c29c6d67 files · +1271 −640Browse files

Showing the changes to crates/multi_buffer/src (1 of 67 files). Show all

Unified · Split

crates/multi_buffer/src/multi_buffer_tests.rs+19−14
@@ -1,6 +1,6 @@
1use super::*;1use super::*;
2use buffer_diff::{DiffHunkStatus, DiffHunkStatusKind};2use buffer_diff::{DiffHunkStatus, DiffHunkStatusKind};
3use gpui::{App, TestAppContext};3use gpui::{App, BackgroundExecutor, TestAppContext};
4use indoc::indoc;4use indoc::indoc;
5use language::{Buffer, Rope};5use language::{Buffer, Rope};
6use parking_lot::RwLock;6use parking_lot::RwLock;
@@ -79,9 +79,14 @@ fn test_remote(cx: &mut App) { · 72 unmodified lines
79 let ops = cx79 let ops = cx
80 .background_executor()80 .background_executor()
81 .block(host_buffer.read(cx).serialize_ops(None, cx));81 .block(host_buffer.read(cx).serialize_ops(None, cx));
82 let mut buffer =82 let mut buffer = Buffer::from_proto(
83 Buffer::from_proto(ReplicaId::REMOTE_SERVER, Capability::ReadWrite, state, None)83 ReplicaId::REMOTE_SERVER,
84 .unwrap();84 Capability::ReadWrite,
85 state,
86 None,
87 cx.background_executor(),
88 )
89 .unwrap();
85 buffer.apply_ops(90 buffer.apply_ops(
86 ops.into_iter()91 ops.into_iter()
87 .map(|op| language::proto::deserialize_operation(op).unwrap()),92 .map(|op| language::proto::deserialize_operation(op).unwrap()),
@@ -1224,7 +1229,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 1136 unmodified lines
1224 assert_chunks_in_ranges(&snapshot);1229 assert_chunks_in_ranges(&snapshot);
1225 assert_consistent_line_numbers(&snapshot);1230 assert_consistent_line_numbers(&snapshot);
1226 assert_position_translation(&snapshot);1231 assert_position_translation(&snapshot);
1227 assert_line_indents(&snapshot);1232 assert_line_indents(&snapshot, cx.background_executor());
1228 1233
1229 multibuffer.update(cx, |multibuffer, cx| {1234 multibuffer.update(cx, |multibuffer, cx| {
1230 multibuffer.collapse_diff_hunks(vec![Anchor::min()..Anchor::max()], cx)1235 multibuffer.collapse_diff_hunks(vec![Anchor::min()..Anchor::max()], cx)
@@ -1248,7 +1253,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 17 unmodified lines
1248 assert_chunks_in_ranges(&snapshot);1253 assert_chunks_in_ranges(&snapshot);
1249 assert_consistent_line_numbers(&snapshot);1254 assert_consistent_line_numbers(&snapshot);
1250 assert_position_translation(&snapshot);1255 assert_position_translation(&snapshot);
1251 assert_line_indents(&snapshot);1256 assert_line_indents(&snapshot, cx.background_executor());
1252 1257
1253 // Expand the first diff hunk1258 // Expand the first diff hunk
1254 multibuffer.update(cx, |multibuffer, cx| {1259 multibuffer.update(cx, |multibuffer, cx| {
@@ -1300,7 +1305,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 45 unmodified lines
1300 assert_chunks_in_ranges(&snapshot);1305 assert_chunks_in_ranges(&snapshot);
1301 assert_consistent_line_numbers(&snapshot);1306 assert_consistent_line_numbers(&snapshot);
1302 assert_position_translation(&snapshot);1307 assert_position_translation(&snapshot);
1303 assert_line_indents(&snapshot);1308 assert_line_indents(&snapshot, cx.background_executor());
1304 1309
1305 // Edit the buffer before the first hunk1310 // Edit the buffer before the first hunk
1306 buffer.update(cx, |buffer, cx| {1311 buffer.update(cx, |buffer, cx| {
@@ -1342,7 +1347,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 35 unmodified lines
1342 assert_chunks_in_ranges(&snapshot);1347 assert_chunks_in_ranges(&snapshot);
1343 assert_consistent_line_numbers(&snapshot);1348 assert_consistent_line_numbers(&snapshot);
1344 assert_position_translation(&snapshot);1349 assert_position_translation(&snapshot);
1345 assert_line_indents(&snapshot);1350 assert_line_indents(&snapshot, cx.background_executor());
1346 1351
1347 // Recalculate the diff, changing the first diff hunk.1352 // Recalculate the diff, changing the first diff hunk.
1348 diff.update(cx, |diff, cx| {1353 diff.update(cx, |diff, cx| {
@@ -2067,7 +2072,7 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) { · 718 unmodified lines
2067 }2072 }
2068 2073
2069 assert_position_translation(&snapshot);2074 assert_position_translation(&snapshot);
2070 assert_line_indents(&snapshot);2075 assert_line_indents(&snapshot, cx.background_executor());
2071 2076
2072 assert_eq!(2077 assert_eq!(
2073 snapshot2078 snapshot
@@ -2118,7 +2123,7 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) { · 44 unmodified lines
2118 ),2123 ),
2119 );2124 );
2120 2125
2121 assert_line_indents(&snapshot);2126 assert_line_indents(&snapshot, cx.background_executor());
2122}2127}
2123 2128
2124/// A naive implementation of a multi-buffer that does not maintain2129/// A naive implementation of a multi-buffer that does not maintain
@@ -2888,7 +2893,7 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) { · 763 unmodified lines
2888 );2893 );
2889 }2894 }
2890 2895
2891 let text_rope = Rope::from(expected_text.as_str());2896 let text_rope = Rope::from_str(expected_text.as_str(), cx.background_executor());
2892 for _ in 0..10 {2897 for _ in 0..10 {
2893 let end_ix = text_rope.clip_offset(rng.random_range(0..=text_rope.len()), Bias::Right);2898 let end_ix = text_rope.clip_offset(rng.random_range(0..=text_rope.len()), Bias::Right);
2894 let start_ix = text_rope.clip_offset(rng.random_range(0..=end_ix), Bias::Left);2899 let start_ix = text_rope.clip_offset(rng.random_range(0..=end_ix), Bias::Left);
@@ -3512,7 +3517,7 @@ fn assert_consistent_line_numbers(snapshot: &MultiBufferSnapshot) { · 617 unmodified lines
3512 3517
3513#[track_caller]3518#[track_caller]
3514fn assert_position_translation(snapshot: &MultiBufferSnapshot) {3519fn assert_position_translation(snapshot: &MultiBufferSnapshot) {
3515 let text = Rope::from(snapshot.text());3520 let text = Rope::from_str_small(&snapshot.text());
3516 3521
3517 let mut left_anchors = Vec::new();3522 let mut left_anchors = Vec::new();
3518 let mut right_anchors = Vec::new();3523 let mut right_anchors = Vec::new();
@@ -3636,10 +3641,10 @@ fn assert_position_translation(snapshot: &MultiBufferSnapshot) { · 117 unmodified lines
3636 }3641 }
3637}3642}
3638 3643
3639fn assert_line_indents(snapshot: &MultiBufferSnapshot) {3644fn assert_line_indents(snapshot: &MultiBufferSnapshot, executor: &BackgroundExecutor) {
3640 let max_row = snapshot.max_point().row;3645 let max_row = snapshot.max_point().row;
3641 let buffer_id = snapshot.excerpts().next().unwrap().1.remote_id();3646 let buffer_id = snapshot.excerpts().next().unwrap().1.remote_id();
3642 let text = text::Buffer::new(ReplicaId::LOCAL, buffer_id, snapshot.text());3647 let text = text::Buffer::new(ReplicaId::LOCAL, buffer_id, snapshot.text(), executor);
3643 let mut line_indents = text3648 let mut line_indents = text
3644 .line_indents_in_row_range(0..max_row + 1)3649 .line_indents_in_row_range(0..max_row + 1)
3645 .collect::<Vec<_>>();3650 .collect::<Vec<_>>();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t