Pass a reference to TestAppContext in tests

This allows us to drop the context *after* we ran all futures to
completion and that's crucial otherwise we'll never drop entities
and/or flush effects.
This commit is contained in:
Antonio Scandurra 2022-03-01 12:01:02 +01:00
parent 8390f04e7d
commit 466db69780
20 changed files with 748 additions and 819 deletions

View File

@ -597,7 +597,7 @@ mod tests {
use surf::http::Response; use surf::http::Response;
#[gpui::test] #[gpui::test]
async fn test_channel_messages(mut cx: TestAppContext) { async fn test_channel_messages(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let user_id = 5; let user_id = 5;
@ -609,7 +609,7 @@ mod tests {
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let channel_list = cx.add_model(|cx| ChannelList::new(user_store, client.clone(), cx)); let channel_list = cx.add_model(|cx| ChannelList::new(user_store, client.clone(), cx));
channel_list.read_with(&cx, |list, _| assert_eq!(list.available_channels(), None)); channel_list.read_with(cx, |list, _| assert_eq!(list.available_channels(), None));
// Get the available channels. // Get the available channels.
let get_channels = server.receive::<proto::GetChannels>().await.unwrap(); let get_channels = server.receive::<proto::GetChannels>().await.unwrap();
@ -625,7 +625,7 @@ mod tests {
) )
.await; .await;
channel_list.next_notification(&cx).await; channel_list.next_notification(&cx).await;
channel_list.read_with(&cx, |list, _| { channel_list.read_with(cx, |list, _| {
assert_eq!( assert_eq!(
list.available_channels().unwrap(), list.available_channels().unwrap(),
&[ChannelDetails { &[ChannelDetails {
@ -652,12 +652,12 @@ mod tests {
// Join a channel and populate its existing messages. // Join a channel and populate its existing messages.
let channel = channel_list let channel = channel_list
.update(&mut cx, |list, cx| { .update(cx, |list, cx| {
let channel_id = list.available_channels().unwrap()[0].id; let channel_id = list.available_channels().unwrap()[0].id;
list.get_channel(channel_id, cx) list.get_channel(channel_id, cx)
}) })
.unwrap(); .unwrap();
channel.read_with(&cx, |channel, _| assert!(channel.messages().is_empty())); channel.read_with(cx, |channel, _| assert!(channel.messages().is_empty()));
let join_channel = server.receive::<proto::JoinChannel>().await.unwrap(); let join_channel = server.receive::<proto::JoinChannel>().await.unwrap();
server server
.respond( .respond(
@ -708,7 +708,7 @@ mod tests {
new_count: 2, new_count: 2,
} }
); );
channel.read_with(&cx, |channel, _| { channel.read_with(cx, |channel, _| {
assert_eq!( assert_eq!(
channel channel
.messages_in_range(0..2) .messages_in_range(0..2)
@ -723,7 +723,7 @@ mod tests {
// Receive a new message. // Receive a new message.
server.send(proto::ChannelMessageSent { server.send(proto::ChannelMessageSent {
channel_id: channel.read_with(&cx, |channel, _| channel.details.id), channel_id: channel.read_with(cx, |channel, _| channel.details.id),
message: Some(proto::ChannelMessage { message: Some(proto::ChannelMessage {
id: 12, id: 12,
body: "c".into(), body: "c".into(),
@ -756,7 +756,7 @@ mod tests {
new_count: 1, new_count: 1,
} }
); );
channel.read_with(&cx, |channel, _| { channel.read_with(cx, |channel, _| {
assert_eq!( assert_eq!(
channel channel
.messages_in_range(2..3) .messages_in_range(2..3)
@ -767,7 +767,7 @@ mod tests {
}); });
// Scroll up to view older messages. // Scroll up to view older messages.
channel.update(&mut cx, |channel, cx| { channel.update(cx, |channel, cx| {
assert!(channel.load_more_messages(cx)); assert!(channel.load_more_messages(cx));
}); });
let get_messages = server.receive::<proto::GetChannelMessages>().await.unwrap(); let get_messages = server.receive::<proto::GetChannelMessages>().await.unwrap();
@ -805,7 +805,7 @@ mod tests {
new_count: 2, new_count: 2,
} }
); );
channel.read_with(&cx, |channel, _| { channel.read_with(cx, |channel, _| {
assert_eq!( assert_eq!(
channel channel
.messages_in_range(0..2) .messages_in_range(0..2)

View File

@ -933,7 +933,7 @@ mod tests {
use gpui::TestAppContext; use gpui::TestAppContext;
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
async fn test_heartbeat(cx: TestAppContext) { async fn test_heartbeat(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let user_id = 5; let user_id = 5;
@ -953,7 +953,7 @@ mod tests {
} }
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
async fn test_reconnection(cx: TestAppContext) { async fn test_reconnection(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let user_id = 5; let user_id = 5;
@ -1001,7 +1001,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_subscribing_to_entity(mut cx: TestAppContext) { async fn test_subscribing_to_entity(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let user_id = 5; let user_id = 5;
@ -1033,14 +1033,11 @@ mod tests {
subscription: None, subscription: None,
}); });
let _subscription1 = let _subscription1 = model1.update(cx, |_, cx| client.add_model_for_remote_entity(1, cx));
model1.update(&mut cx, |_, cx| client.add_model_for_remote_entity(1, cx)); let _subscription2 = model2.update(cx, |_, cx| client.add_model_for_remote_entity(2, cx));
let _subscription2 =
model2.update(&mut cx, |_, cx| client.add_model_for_remote_entity(2, cx));
// Ensure dropping a subscription for the same entity type still allows receiving of // Ensure dropping a subscription for the same entity type still allows receiving of
// messages for other entity IDs of the same type. // messages for other entity IDs of the same type.
let subscription3 = let subscription3 = model3.update(cx, |_, cx| client.add_model_for_remote_entity(3, cx));
model3.update(&mut cx, |_, cx| client.add_model_for_remote_entity(3, cx));
drop(subscription3); drop(subscription3);
server.send(proto::UnshareProject { project_id: 1 }); server.send(proto::UnshareProject { project_id: 1 });
@ -1050,7 +1047,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_subscribing_after_dropping_subscription(mut cx: TestAppContext) { async fn test_subscribing_after_dropping_subscription(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let user_id = 5; let user_id = 5;
@ -1078,7 +1075,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_dropping_subscription_in_handler(mut cx: TestAppContext) { async fn test_dropping_subscription_in_handler(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let user_id = 5; let user_id = 5;
@ -1095,7 +1092,7 @@ mod tests {
async { Ok(()) } async { Ok(()) }
}, },
); );
model.update(&mut cx, |model, _| { model.update(cx, |model, _| {
model.subscription = Some(subscription); model.subscription = Some(subscription);
}); });
server.send(proto::Ping {}); server.send(proto::Ping {});

View File

@ -725,7 +725,7 @@ mod tests {
use workspace::WorkspaceParams; use workspace::WorkspaceParams;
#[gpui::test] #[gpui::test]
async fn test_diagnostics(mut cx: TestAppContext) { async fn test_diagnostics(cx: &mut TestAppContext) {
let params = cx.update(WorkspaceParams::test); let params = cx.update(WorkspaceParams::test);
let project = params.project.clone(); let project = params.project.clone();
let workspace = cx.add_view(0, |cx| Workspace::new(&params, cx)); let workspace = cx.add_view(0, |cx| Workspace::new(&params, cx));
@ -760,14 +760,14 @@ mod tests {
.await; .await;
project project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/test", false, cx) project.find_or_create_local_worktree("/test", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
// Create some diagnostics // Create some diagnostics
project.update(&mut cx, |project, cx| { project.update(cx, |project, cx| {
project project
.update_diagnostic_entries( .update_diagnostic_entries(
PathBuf::from("/test/main.rs"), PathBuf::from("/test/main.rs"),
@ -856,7 +856,7 @@ mod tests {
}); });
view.next_notification(&cx).await; view.next_notification(&cx).await;
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
let editor = view.editor.update(cx, |editor, cx| editor.snapshot(cx)); let editor = view.editor.update(cx, |editor, cx| editor.snapshot(cx));
assert_eq!( assert_eq!(
@ -920,7 +920,7 @@ mod tests {
}); });
// Diagnostics are added for another earlier path. // Diagnostics are added for another earlier path.
project.update(&mut cx, |project, cx| { project.update(cx, |project, cx| {
project.disk_based_diagnostics_started(cx); project.disk_based_diagnostics_started(cx);
project project
.update_diagnostic_entries( .update_diagnostic_entries(
@ -944,7 +944,7 @@ mod tests {
}); });
view.next_notification(&cx).await; view.next_notification(&cx).await;
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
let editor = view.editor.update(cx, |editor, cx| editor.snapshot(cx)); let editor = view.editor.update(cx, |editor, cx| editor.snapshot(cx));
assert_eq!( assert_eq!(
@ -1021,7 +1021,7 @@ mod tests {
}); });
// Diagnostics are added to the first path // Diagnostics are added to the first path
project.update(&mut cx, |project, cx| { project.update(cx, |project, cx| {
project.disk_based_diagnostics_started(cx); project.disk_based_diagnostics_started(cx);
project project
.update_diagnostic_entries( .update_diagnostic_entries(
@ -1059,7 +1059,7 @@ mod tests {
}); });
view.next_notification(&cx).await; view.next_notification(&cx).await;
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
let editor = view.editor.update(cx, |editor, cx| editor.snapshot(cx)); let editor = view.editor.update(cx, |editor, cx| editor.snapshot(cx));
assert_eq!( assert_eq!(

View File

@ -464,7 +464,7 @@ mod tests {
use Bias::*; use Bias::*;
#[gpui::test(iterations = 100)] #[gpui::test(iterations = 100)]
async fn test_random_display_map(mut cx: gpui::TestAppContext, mut rng: StdRng) { async fn test_random_display_map(cx: &mut gpui::TestAppContext, mut rng: StdRng) {
cx.foreground().set_block_on_ticks(0..=50); cx.foreground().set_block_on_ticks(0..=50);
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let operations = env::var("OPERATIONS") let operations = env::var("OPERATIONS")
@ -512,11 +512,11 @@ mod tests {
cx, cx,
) )
}); });
let mut notifications = observe(&map, &mut cx); let mut notifications = observe(&map, cx);
let mut fold_count = 0; let mut fold_count = 0;
let mut blocks = Vec::new(); let mut blocks = Vec::new();
let snapshot = map.update(&mut cx, |map, cx| map.snapshot(cx)); let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text()); log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text());
log::info!("fold text: {:?}", snapshot.folds_snapshot.text()); log::info!("fold text: {:?}", snapshot.folds_snapshot.text());
log::info!("tab text: {:?}", snapshot.tabs_snapshot.text()); log::info!("tab text: {:?}", snapshot.tabs_snapshot.text());
@ -533,10 +533,10 @@ mod tests {
Some(rng.gen_range(0.0..=max_wrap_width)) Some(rng.gen_range(0.0..=max_wrap_width))
}; };
log::info!("setting wrap width to {:?}", wrap_width); log::info!("setting wrap width to {:?}", wrap_width);
map.update(&mut cx, |map, cx| map.set_wrap_width(wrap_width, cx)); map.update(cx, |map, cx| map.set_wrap_width(wrap_width, cx));
} }
20..=44 => { 20..=44 => {
map.update(&mut cx, |map, cx| { map.update(cx, |map, cx| {
if rng.gen() || blocks.is_empty() { if rng.gen() || blocks.is_empty() {
let buffer = map.snapshot(cx).buffer_snapshot; let buffer = map.snapshot(cx).buffer_snapshot;
let block_properties = (0..rng.gen_range(1..=1)) let block_properties = (0..rng.gen_range(1..=1))
@ -582,7 +582,7 @@ mod tests {
45..=79 => { 45..=79 => {
let mut ranges = Vec::new(); let mut ranges = Vec::new();
for _ in 0..rng.gen_range(1..=3) { for _ in 0..rng.gen_range(1..=3) {
buffer.read_with(&cx, |buffer, cx| { buffer.read_with(cx, |buffer, cx| {
let buffer = buffer.read(cx); let buffer = buffer.read(cx);
let end = buffer.clip_offset(rng.gen_range(0..=buffer.len()), Right); let end = buffer.clip_offset(rng.gen_range(0..=buffer.len()), Right);
let start = buffer.clip_offset(rng.gen_range(0..=end), Left); let start = buffer.clip_offset(rng.gen_range(0..=end), Left);
@ -592,26 +592,26 @@ mod tests {
if rng.gen() && fold_count > 0 { if rng.gen() && fold_count > 0 {
log::info!("unfolding ranges: {:?}", ranges); log::info!("unfolding ranges: {:?}", ranges);
map.update(&mut cx, |map, cx| { map.update(cx, |map, cx| {
map.unfold(ranges, cx); map.unfold(ranges, cx);
}); });
} else { } else {
log::info!("folding ranges: {:?}", ranges); log::info!("folding ranges: {:?}", ranges);
map.update(&mut cx, |map, cx| { map.update(cx, |map, cx| {
map.fold(ranges, cx); map.fold(ranges, cx);
}); });
} }
} }
_ => { _ => {
buffer.update(&mut cx, |buffer, cx| buffer.randomly_edit(&mut rng, 5, cx)); buffer.update(cx, |buffer, cx| buffer.randomly_edit(&mut rng, 5, cx));
} }
} }
if map.read_with(&cx, |map, cx| map.is_rewrapping(cx)) { if map.read_with(cx, |map, cx| map.is_rewrapping(cx)) {
notifications.next().await.unwrap(); notifications.next().await.unwrap();
} }
let snapshot = map.update(&mut cx, |map, cx| map.snapshot(cx)); let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
fold_count = snapshot.fold_count(); fold_count = snapshot.fold_count();
log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text()); log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text());
log::info!("fold text: {:?}", snapshot.folds_snapshot.text()); log::info!("fold text: {:?}", snapshot.folds_snapshot.text());
@ -846,7 +846,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_chunks(mut cx: gpui::TestAppContext) { async fn test_chunks(cx: &mut gpui::TestAppContext) {
use unindent::Unindent as _; use unindent::Unindent as _;
let text = r#" let text = r#"
@ -914,7 +914,7 @@ mod tests {
] ]
); );
map.update(&mut cx, |map, cx| { map.update(cx, |map, cx| {
map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx) map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx)
}); });
assert_eq!( assert_eq!(
@ -931,7 +931,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_chunks_with_soft_wrapping(mut cx: gpui::TestAppContext) { async fn test_chunks_with_soft_wrapping(cx: &mut gpui::TestAppContext) {
use unindent::Unindent as _; use unindent::Unindent as _;
cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX); cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX);
@ -996,7 +996,7 @@ mod tests {
[("{}\n\n".to_string(), None)] [("{}\n\n".to_string(), None)]
); );
map.update(&mut cx, |map, cx| { map.update(cx, |map, cx| {
map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx) map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx)
}); });
assert_eq!( assert_eq!(

View File

@ -1010,7 +1010,7 @@ mod tests {
use text::Rope; use text::Rope;
#[gpui::test(iterations = 100)] #[gpui::test(iterations = 100)]
async fn test_random_wraps(mut cx: gpui::TestAppContext, mut rng: StdRng) { async fn test_random_wraps(cx: &mut gpui::TestAppContext, mut rng: StdRng) {
cx.foreground().set_block_on_ticks(0..=50); cx.foreground().set_block_on_ticks(0..=50);
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
let operations = env::var("OPERATIONS") let operations = env::var("OPERATIONS")
@ -1043,7 +1043,7 @@ mod tests {
MultiBuffer::build_simple(&text, cx) MultiBuffer::build_simple(&text, cx)
} }
}); });
let mut buffer_snapshot = buffer.read_with(&cx, |buffer, cx| buffer.snapshot(cx)); let mut buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx));
let (mut fold_map, folds_snapshot) = FoldMap::new(buffer_snapshot.clone()); let (mut fold_map, folds_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), tab_size); let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), tab_size);
log::info!("Unwrapped text (no folds): {:?}", buffer_snapshot.text()); log::info!("Unwrapped text (no folds): {:?}", buffer_snapshot.text());
@ -1059,13 +1059,13 @@ mod tests {
let (wrap_map, _) = let (wrap_map, _) =
cx.update(|cx| WrapMap::new(tabs_snapshot.clone(), font_id, font_size, wrap_width, cx)); cx.update(|cx| WrapMap::new(tabs_snapshot.clone(), font_id, font_size, wrap_width, cx));
let mut notifications = observe(&wrap_map, &mut cx); let mut notifications = observe(&wrap_map, cx);
if wrap_map.read_with(&cx, |map, _| map.is_rewrapping()) { if wrap_map.read_with(cx, |map, _| map.is_rewrapping()) {
notifications.next().await.unwrap(); notifications.next().await.unwrap();
} }
let (initial_snapshot, _) = wrap_map.update(&mut cx, |map, cx| { let (initial_snapshot, _) = wrap_map.update(cx, |map, cx| {
assert!(!map.is_rewrapping()); assert!(!map.is_rewrapping());
map.sync(tabs_snapshot.clone(), Vec::new(), cx) map.sync(tabs_snapshot.clone(), Vec::new(), cx)
}); });
@ -1091,20 +1091,20 @@ mod tests {
Some(rng.gen_range(0.0..=1000.0)) Some(rng.gen_range(0.0..=1000.0))
}; };
log::info!("Setting wrap width to {:?}", wrap_width); log::info!("Setting wrap width to {:?}", wrap_width);
wrap_map.update(&mut cx, |map, cx| map.set_wrap_width(wrap_width, cx)); wrap_map.update(cx, |map, cx| map.set_wrap_width(wrap_width, cx));
} }
20..=39 => { 20..=39 => {
for (folds_snapshot, fold_edits) in fold_map.randomly_mutate(&mut rng) { for (folds_snapshot, fold_edits) in fold_map.randomly_mutate(&mut rng) {
let (tabs_snapshot, tab_edits) = tab_map.sync(folds_snapshot, fold_edits); let (tabs_snapshot, tab_edits) = tab_map.sync(folds_snapshot, fold_edits);
let (mut snapshot, wrap_edits) = wrap_map let (mut snapshot, wrap_edits) =
.update(&mut cx, |map, cx| map.sync(tabs_snapshot, tab_edits, cx)); wrap_map.update(cx, |map, cx| map.sync(tabs_snapshot, tab_edits, cx));
snapshot.check_invariants(); snapshot.check_invariants();
snapshot.verify_chunks(&mut rng); snapshot.verify_chunks(&mut rng);
edits.push((snapshot, wrap_edits)); edits.push((snapshot, wrap_edits));
} }
} }
_ => { _ => {
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
let subscription = buffer.subscribe(); let subscription = buffer.subscribe();
let edit_count = rng.gen_range(1..=5); let edit_count = rng.gen_range(1..=5);
buffer.randomly_mutate(&mut rng, edit_count, cx); buffer.randomly_mutate(&mut rng, edit_count, cx);
@ -1125,24 +1125,23 @@ mod tests {
let unwrapped_text = tabs_snapshot.text(); let unwrapped_text = tabs_snapshot.text();
let expected_text = wrap_text(&unwrapped_text, wrap_width, &mut line_wrapper); let expected_text = wrap_text(&unwrapped_text, wrap_width, &mut line_wrapper);
let (mut snapshot, wrap_edits) = wrap_map.update(&mut cx, |map, cx| { let (mut snapshot, wrap_edits) =
map.sync(tabs_snapshot.clone(), tab_edits, cx) wrap_map.update(cx, |map, cx| map.sync(tabs_snapshot.clone(), tab_edits, cx));
});
snapshot.check_invariants(); snapshot.check_invariants();
snapshot.verify_chunks(&mut rng); snapshot.verify_chunks(&mut rng);
edits.push((snapshot, wrap_edits)); edits.push((snapshot, wrap_edits));
if wrap_map.read_with(&cx, |map, _| map.is_rewrapping()) && rng.gen_bool(0.4) { if wrap_map.read_with(cx, |map, _| map.is_rewrapping()) && rng.gen_bool(0.4) {
log::info!("Waiting for wrapping to finish"); log::info!("Waiting for wrapping to finish");
while wrap_map.read_with(&cx, |map, _| map.is_rewrapping()) { while wrap_map.read_with(cx, |map, _| map.is_rewrapping()) {
notifications.next().await.unwrap(); notifications.next().await.unwrap();
} }
wrap_map.read_with(&cx, |map, _| assert!(map.pending_edits.is_empty())); wrap_map.read_with(cx, |map, _| assert!(map.pending_edits.is_empty()));
} }
if !wrap_map.read_with(&cx, |map, _| map.is_rewrapping()) { if !wrap_map.read_with(cx, |map, _| map.is_rewrapping()) {
let (mut wrapped_snapshot, wrap_edits) = let (mut wrapped_snapshot, wrap_edits) =
wrap_map.update(&mut cx, |map, cx| map.sync(tabs_snapshot, Vec::new(), cx)); wrap_map.update(cx, |map, cx| map.sync(tabs_snapshot, Vec::new(), cx));
let actual_text = wrapped_snapshot.text(); let actual_text = wrapped_snapshot.text();
let actual_longest_row = wrapped_snapshot.longest_row(); let actual_longest_row = wrapped_snapshot.longest_row();
log::info!("Wrapping finished: {:?}", actual_text); log::info!("Wrapping finished: {:?}", actual_text);
@ -1220,13 +1219,13 @@ mod tests {
assert_eq!(initial_text.to_string(), snapshot_text.to_string()); assert_eq!(initial_text.to_string(), snapshot_text.to_string());
} }
if wrap_map.read_with(&cx, |map, _| map.is_rewrapping()) { if wrap_map.read_with(cx, |map, _| map.is_rewrapping()) {
log::info!("Waiting for wrapping to finish"); log::info!("Waiting for wrapping to finish");
while wrap_map.read_with(&cx, |map, _| map.is_rewrapping()) { while wrap_map.read_with(cx, |map, _| map.is_rewrapping()) {
notifications.next().await.unwrap(); notifications.next().await.unwrap();
} }
} }
wrap_map.read_with(&cx, |map, _| assert!(map.pending_edits.is_empty())); wrap_map.read_with(cx, |map, _| assert!(map.pending_edits.is_empty()));
} }
fn wrap_text( fn wrap_text(

View File

@ -7772,7 +7772,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_select_larger_smaller_syntax_node(mut cx: gpui::TestAppContext) { async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let language = Arc::new(Language::new( let language = Arc::new(Language::new(
LanguageConfig::default(), LanguageConfig::default(),
@ -7794,7 +7794,7 @@ mod tests {
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await; .await;
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_display_ranges( view.select_display_ranges(
&[ &[
DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25), DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25),
@ -7806,7 +7806,7 @@ mod tests {
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx); view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 23)..DisplayPoint::new(0, 27), DisplayPoint::new(0, 23)..DisplayPoint::new(0, 27),
DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7), DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7),
@ -7814,50 +7814,50 @@ mod tests {
] ]
); );
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx); view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28), DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28),
DisplayPoint::new(4, 1)..DisplayPoint::new(2, 0), DisplayPoint::new(4, 1)..DisplayPoint::new(2, 0),
] ]
); );
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx); view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[DisplayPoint::new(5, 0)..DisplayPoint::new(0, 0)] &[DisplayPoint::new(5, 0)..DisplayPoint::new(0, 0)]
); );
// Trying to expand the selected syntax node one more time has no effect. // Trying to expand the selected syntax node one more time has no effect.
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx); view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[DisplayPoint::new(5, 0)..DisplayPoint::new(0, 0)] &[DisplayPoint::new(5, 0)..DisplayPoint::new(0, 0)]
); );
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx); view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28), DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28),
DisplayPoint::new(4, 1)..DisplayPoint::new(2, 0), DisplayPoint::new(4, 1)..DisplayPoint::new(2, 0),
] ]
); );
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx); view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 23)..DisplayPoint::new(0, 27), DisplayPoint::new(0, 23)..DisplayPoint::new(0, 27),
DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7), DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7),
@ -7865,11 +7865,11 @@ mod tests {
] ]
); );
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx); view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25), DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25),
DisplayPoint::new(2, 24)..DisplayPoint::new(2, 12), DisplayPoint::new(2, 24)..DisplayPoint::new(2, 12),
@ -7878,11 +7878,11 @@ mod tests {
); );
// Trying to shrink the selected syntax node one more time has no effect. // Trying to shrink the selected syntax node one more time has no effect.
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx); view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25), DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25),
DisplayPoint::new(2, 24)..DisplayPoint::new(2, 12), DisplayPoint::new(2, 24)..DisplayPoint::new(2, 12),
@ -7892,7 +7892,7 @@ mod tests {
// Ensure that we keep expanding the selection if the larger selection starts or ends within // Ensure that we keep expanding the selection if the larger selection starts or ends within
// a fold. // a fold.
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.fold_ranges( view.fold_ranges(
vec![ vec![
Point::new(0, 21)..Point::new(0, 24), Point::new(0, 21)..Point::new(0, 24),
@ -7903,7 +7903,7 @@ mod tests {
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx); view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
}); });
assert_eq!( assert_eq!(
view.update(&mut cx, |view, cx| view.selected_display_ranges(cx)), view.update(cx, |view, cx| view.selected_display_ranges(cx)),
&[ &[
DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28), DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28),
DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7), DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7),
@ -7913,7 +7913,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_autoindent_selections(mut cx: gpui::TestAppContext) { async fn test_autoindent_selections(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let language = Arc::new( let language = Arc::new(
Language::new( Language::new(
@ -7954,7 +7954,7 @@ mod tests {
.condition(&cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx)) .condition(&cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx))
.await; .await;
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_ranges([5..5, 8..8, 9..9], None, cx); editor.select_ranges([5..5, 8..8, 9..9], None, cx);
editor.newline(&Newline, cx); editor.newline(&Newline, cx);
assert_eq!(editor.text(cx), "fn a(\n \n) {\n \n}\n"); assert_eq!(editor.text(cx), "fn a(\n \n) {\n \n}\n");
@ -7970,7 +7970,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_autoclose_pairs(mut cx: gpui::TestAppContext) { async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let language = Arc::new(Language::new( let language = Arc::new(Language::new(
LanguageConfig { LanguageConfig {
@ -8007,7 +8007,7 @@ mod tests {
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await; .await;
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_display_ranges( view.select_display_ranges(
&[ &[
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 1), DisplayPoint::new(0, 0)..DisplayPoint::new(0, 1),
@ -8081,7 +8081,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_snippets(mut cx: gpui::TestAppContext) { async fn test_snippets(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let text = " let text = "
@ -8093,7 +8093,7 @@ mod tests {
let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx)); let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));
let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx)); let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx));
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
let buffer = &editor.snapshot(cx).buffer_snapshot; let buffer = &editor.snapshot(cx).buffer_snapshot;
let snippet = Snippet::parse("f(${1:one}, ${2:two}, ${1:three})$0").unwrap(); let snippet = Snippet::parse("f(${1:one}, ${2:two}, ${1:three})$0").unwrap();
let insertion_ranges = [ let insertion_ranges = [
@ -8188,7 +8188,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_completion(mut cx: gpui::TestAppContext) { async fn test_completion(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let (language_server, mut fake) = cx.update(|cx| { let (language_server, mut fake) = cx.update(|cx| {
lsp::LanguageServer::fake_with_capabilities( lsp::LanguageServer::fake_with_capabilities(
@ -8213,23 +8213,23 @@ mod tests {
let fs = FakeFs::new(cx.background().clone()); let fs = FakeFs::new(cx.background().clone());
fs.insert_file("/file", text).await; fs.insert_file("/file", text).await;
let project = Project::test(fs, &mut cx); let project = Project::test(fs, cx);
let (worktree, relative_path) = project let (worktree, relative_path) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/file", false, cx) project.find_or_create_local_worktree("/file", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let project_path = ProjectPath { let project_path = ProjectPath {
worktree_id: worktree.read_with(&cx, |worktree, _| worktree.id()), worktree_id: worktree.read_with(cx, |worktree, _| worktree.id()),
path: relative_path.into(), path: relative_path.into(),
}; };
let buffer = project let buffer = project
.update(&mut cx, |project, cx| project.open_buffer(project_path, cx)) .update(cx, |project, cx| project.open_buffer(project_path, cx))
.await .await
.unwrap(); .unwrap();
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
buffer.set_language_server(Some(language_server), cx); buffer.set_language_server(Some(language_server), cx);
}); });
@ -8238,7 +8238,7 @@ mod tests {
let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx)); let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx));
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.project = Some(project); editor.project = Some(project);
editor.select_ranges([Point::new(0, 3)..Point::new(0, 3)], None, cx); editor.select_ranges([Point::new(0, 3)..Point::new(0, 3)], None, cx);
editor.handle_input(&Input(".".to_string()), cx); editor.handle_input(&Input(".".to_string()), cx);
@ -8258,7 +8258,7 @@ mod tests {
.condition(&cx, |editor, _| editor.context_menu_visible()) .condition(&cx, |editor, _| editor.context_menu_visible())
.await; .await;
let apply_additional_edits = editor.update(&mut cx, |editor, cx| { let apply_additional_edits = editor.update(cx, |editor, cx| {
editor.move_down(&MoveDown, cx); editor.move_down(&MoveDown, cx);
let apply_additional_edits = editor let apply_additional_edits = editor
.confirm_completion(&ConfirmCompletion(None), cx) .confirm_completion(&ConfirmCompletion(None), cx)
@ -8282,7 +8282,7 @@ mod tests {
.await; .await;
apply_additional_edits.await.unwrap(); apply_additional_edits.await.unwrap();
assert_eq!( assert_eq!(
editor.read_with(&cx, |editor, cx| editor.text(cx)), editor.read_with(cx, |editor, cx| editor.text(cx)),
" "
one.second_completion one.second_completion
two two
@ -8292,7 +8292,7 @@ mod tests {
.unindent() .unindent()
); );
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_ranges( editor.select_ranges(
[ [
Point::new(1, 3)..Point::new(1, 3), Point::new(1, 3)..Point::new(1, 3),
@ -8323,7 +8323,7 @@ mod tests {
.condition(&cx, |editor, _| editor.context_menu_visible()) .condition(&cx, |editor, _| editor.context_menu_visible())
.await; .await;
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.handle_input(&Input("i".to_string()), cx); editor.handle_input(&Input("i".to_string()), cx);
}); });
@ -8342,7 +8342,7 @@ mod tests {
.condition(&cx, |editor, _| editor.context_menu_visible()) .condition(&cx, |editor, _| editor.context_menu_visible())
.await; .await;
let apply_additional_edits = editor.update(&mut cx, |editor, cx| { let apply_additional_edits = editor.update(cx, |editor, cx| {
let apply_additional_edits = editor let apply_additional_edits = editor
.confirm_completion(&ConfirmCompletion(None), cx) .confirm_completion(&ConfirmCompletion(None), cx)
.unwrap(); .unwrap();
@ -8421,7 +8421,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_toggle_comment(mut cx: gpui::TestAppContext) { async fn test_toggle_comment(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let language = Arc::new(Language::new( let language = Arc::new(Language::new(
LanguageConfig { LanguageConfig {
@ -8444,7 +8444,7 @@ mod tests {
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx)); let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, view) = cx.add_window(|cx| build_editor(buffer, settings, cx)); let (_, view) = cx.add_window(|cx| build_editor(buffer, settings, cx));
view.update(&mut cx, |editor, cx| { view.update(cx, |editor, cx| {
// If multiple selections intersect a line, the line is only // If multiple selections intersect a line, the line is only
// toggled once. // toggled once.
editor.select_display_ranges( editor.select_display_ranges(
@ -8678,7 +8678,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_extra_newline_insertion(mut cx: gpui::TestAppContext) { async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {
let settings = cx.read(Settings::test); let settings = cx.read(Settings::test);
let language = Arc::new(Language::new( let language = Arc::new(Language::new(
LanguageConfig { LanguageConfig {
@ -8715,7 +8715,7 @@ mod tests {
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await; .await;
view.update(&mut cx, |view, cx| { view.update(cx, |view, cx| {
view.select_display_ranges( view.select_display_ranges(
&[ &[
DisplayPoint::new(0, 2)..DisplayPoint::new(0, 3), DisplayPoint::new(0, 2)..DisplayPoint::new(0, 3),

View File

@ -421,7 +421,7 @@ mod tests {
use workspace::{Workspace, WorkspaceParams}; use workspace::{Workspace, WorkspaceParams};
#[gpui::test] #[gpui::test]
async fn test_matching_paths(mut cx: gpui::TestAppContext) { async fn test_matching_paths(cx: &mut gpui::TestAppContext) {
let mut path_openers = Vec::new(); let mut path_openers = Vec::new();
cx.update(|cx| { cx.update(|cx| {
super::init(cx); super::init(cx);
@ -447,7 +447,7 @@ mod tests {
let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root", false, cx) project.find_or_create_local_worktree("/root", false, cx)
}) })
.await .await
@ -496,7 +496,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_matching_cancellation(mut cx: gpui::TestAppContext) { async fn test_matching_cancellation(cx: &mut gpui::TestAppContext) {
let params = cx.update(WorkspaceParams::test); let params = cx.update(WorkspaceParams::test);
let fs = params.fs.as_fake(); let fs = params.fs.as_fake();
fs.insert_tree( fs.insert_tree(
@ -516,7 +516,7 @@ mod tests {
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir", false, cx) project.find_or_create_local_worktree("/dir", false, cx)
}) })
.await .await
@ -533,12 +533,12 @@ mod tests {
let query = "hi".to_string(); let query = "hi".to_string();
finder finder
.update(&mut cx, |f, cx| f.spawn_search(query.clone(), cx)) .update(cx, |f, cx| f.spawn_search(query.clone(), cx))
.unwrap() .unwrap()
.await; .await;
finder.read_with(&cx, |f, _| assert_eq!(f.matches.len(), 5)); finder.read_with(cx, |f, _| assert_eq!(f.matches.len(), 5));
finder.update(&mut cx, |finder, cx| { finder.update(cx, |finder, cx| {
let matches = finder.matches.clone(); let matches = finder.matches.clone();
// Simulate a search being cancelled after the time limit, // Simulate a search being cancelled after the time limit,
@ -571,7 +571,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_single_file_worktrees(mut cx: gpui::TestAppContext) { async fn test_single_file_worktrees(cx: &mut gpui::TestAppContext) {
let params = cx.update(WorkspaceParams::test); let params = cx.update(WorkspaceParams::test);
params params
.fs .fs
@ -582,7 +582,7 @@ mod tests {
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root/the-parent-dir/the-file", false, cx) project.find_or_create_local_worktree("/root/the-parent-dir/the-file", false, cx)
}) })
.await .await
@ -600,7 +600,7 @@ mod tests {
// Even though there is only one worktree, that worktree's filename // Even though there is only one worktree, that worktree's filename
// is included in the matching, because the worktree is a single file. // is included in the matching, because the worktree is a single file.
finder finder
.update(&mut cx, |f, cx| f.spawn_search("thf".into(), cx)) .update(cx, |f, cx| f.spawn_search("thf".into(), cx))
.unwrap() .unwrap()
.await; .await;
cx.read(|cx| { cx.read(|cx| {
@ -618,14 +618,14 @@ mod tests {
// Since the worktree root is a file, searching for its name followed by a slash does // Since the worktree root is a file, searching for its name followed by a slash does
// not match anything. // not match anything.
finder finder
.update(&mut cx, |f, cx| f.spawn_search("thf/".into(), cx)) .update(cx, |f, cx| f.spawn_search("thf/".into(), cx))
.unwrap() .unwrap()
.await; .await;
finder.read_with(&cx, |f, _| assert_eq!(f.matches.len(), 0)); finder.read_with(cx, |f, _| assert_eq!(f.matches.len(), 0));
} }
#[gpui::test(retries = 5)] #[gpui::test(retries = 5)]
async fn test_multiple_matches_with_same_relative_path(mut cx: gpui::TestAppContext) { async fn test_multiple_matches_with_same_relative_path(cx: &mut gpui::TestAppContext) {
let params = cx.update(WorkspaceParams::test); let params = cx.update(WorkspaceParams::test);
params params
.fs .fs
@ -642,7 +642,7 @@ mod tests {
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
workspace workspace
.update(&mut cx, |workspace, cx| { .update(cx, |workspace, cx| {
workspace.open_paths( workspace.open_paths(
&[PathBuf::from("/root/dir1"), PathBuf::from("/root/dir2")], &[PathBuf::from("/root/dir1"), PathBuf::from("/root/dir2")],
cx, cx,
@ -662,12 +662,12 @@ mod tests {
// Run a search that matches two files with the same relative path. // Run a search that matches two files with the same relative path.
finder finder
.update(&mut cx, |f, cx| f.spawn_search("a.t".into(), cx)) .update(cx, |f, cx| f.spawn_search("a.t".into(), cx))
.unwrap() .unwrap()
.await; .await;
// Can switch between different matches with the same relative path. // Can switch between different matches with the same relative path.
finder.update(&mut cx, |f, cx| { finder.update(cx, |f, cx| {
assert_eq!(f.matches.len(), 2); assert_eq!(f.matches.len(), 2);
assert_eq!(f.selected_index(), 0); assert_eq!(f.selected_index(), 0);
f.select_next(&SelectNext, cx); f.select_next(&SelectNext, cx);

View File

@ -4726,7 +4726,7 @@ mod tests {
} }
#[crate::test(self)] #[crate::test(self)]
async fn test_model_condition(mut cx: TestAppContext) { async fn test_model_condition(cx: &mut TestAppContext) {
struct Counter(usize); struct Counter(usize);
impl super::Entity for Counter { impl super::Entity for Counter {
@ -4746,23 +4746,23 @@ mod tests {
let condition2 = model.condition(&cx, |model, _| model.0 == 3); let condition2 = model.condition(&cx, |model, _| model.0 == 3);
smol::pin!(condition1, condition2); smol::pin!(condition1, condition2);
model.update(&mut cx, |model, cx| model.inc(cx)); model.update(cx, |model, cx| model.inc(cx));
assert_eq!(poll_once(&mut condition1).await, None); assert_eq!(poll_once(&mut condition1).await, None);
assert_eq!(poll_once(&mut condition2).await, None); assert_eq!(poll_once(&mut condition2).await, None);
model.update(&mut cx, |model, cx| model.inc(cx)); model.update(cx, |model, cx| model.inc(cx));
assert_eq!(poll_once(&mut condition1).await, Some(())); assert_eq!(poll_once(&mut condition1).await, Some(()));
assert_eq!(poll_once(&mut condition2).await, None); assert_eq!(poll_once(&mut condition2).await, None);
model.update(&mut cx, |model, cx| model.inc(cx)); model.update(cx, |model, cx| model.inc(cx));
assert_eq!(poll_once(&mut condition2).await, Some(())); assert_eq!(poll_once(&mut condition2).await, Some(()));
model.update(&mut cx, |_, cx| cx.notify()); model.update(cx, |_, cx| cx.notify());
} }
#[crate::test(self)] #[crate::test(self)]
#[should_panic] #[should_panic]
async fn test_model_condition_timeout(mut cx: TestAppContext) { async fn test_model_condition_timeout(cx: &mut TestAppContext) {
struct Model; struct Model;
impl super::Entity for Model { impl super::Entity for Model {
@ -4775,7 +4775,7 @@ mod tests {
#[crate::test(self)] #[crate::test(self)]
#[should_panic(expected = "model dropped with pending condition")] #[should_panic(expected = "model dropped with pending condition")]
async fn test_model_condition_panic_on_drop(mut cx: TestAppContext) { async fn test_model_condition_panic_on_drop(cx: &mut TestAppContext) {
struct Model; struct Model;
impl super::Entity for Model { impl super::Entity for Model {
@ -4789,7 +4789,7 @@ mod tests {
} }
#[crate::test(self)] #[crate::test(self)]
async fn test_view_condition(mut cx: TestAppContext) { async fn test_view_condition(cx: &mut TestAppContext) {
struct Counter(usize); struct Counter(usize);
impl super::Entity for Counter { impl super::Entity for Counter {
@ -4819,22 +4819,22 @@ mod tests {
let condition2 = view.condition(&cx, |view, _| view.0 == 3); let condition2 = view.condition(&cx, |view, _| view.0 == 3);
smol::pin!(condition1, condition2); smol::pin!(condition1, condition2);
view.update(&mut cx, |view, cx| view.inc(cx)); view.update(cx, |view, cx| view.inc(cx));
assert_eq!(poll_once(&mut condition1).await, None); assert_eq!(poll_once(&mut condition1).await, None);
assert_eq!(poll_once(&mut condition2).await, None); assert_eq!(poll_once(&mut condition2).await, None);
view.update(&mut cx, |view, cx| view.inc(cx)); view.update(cx, |view, cx| view.inc(cx));
assert_eq!(poll_once(&mut condition1).await, Some(())); assert_eq!(poll_once(&mut condition1).await, Some(()));
assert_eq!(poll_once(&mut condition2).await, None); assert_eq!(poll_once(&mut condition2).await, None);
view.update(&mut cx, |view, cx| view.inc(cx)); view.update(cx, |view, cx| view.inc(cx));
assert_eq!(poll_once(&mut condition2).await, Some(())); assert_eq!(poll_once(&mut condition2).await, Some(()));
view.update(&mut cx, |_, cx| cx.notify()); view.update(cx, |_, cx| cx.notify());
} }
#[crate::test(self)] #[crate::test(self)]
#[should_panic] #[should_panic]
async fn test_view_condition_timeout(mut cx: TestAppContext) { async fn test_view_condition_timeout(cx: &mut TestAppContext) {
struct View; struct View;
impl super::Entity for View { impl super::Entity for View {
@ -4857,7 +4857,7 @@ mod tests {
#[crate::test(self)] #[crate::test(self)]
#[should_panic(expected = "view dropped with pending condition")] #[should_panic(expected = "view dropped with pending condition")]
async fn test_view_condition_panic_on_drop(mut cx: TestAppContext) { async fn test_view_condition_panic_on_drop(cx: &mut TestAppContext) {
struct View; struct View;
impl super::Entity for View { impl super::Entity for View {

View File

@ -65,26 +65,13 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
let mut outer_fn: ItemFn = if inner_fn.sig.asyncness.is_some() { let mut outer_fn: ItemFn = if inner_fn.sig.asyncness.is_some() {
// Pass to the test function the number of app contexts that it needs, // Pass to the test function the number of app contexts that it needs,
// based on its parameter list. // based on its parameter list.
let mut cx_vars = proc_macro2::TokenStream::new();
let mut inner_fn_args = proc_macro2::TokenStream::new(); let mut inner_fn_args = proc_macro2::TokenStream::new();
for (ix, arg) in inner_fn.sig.inputs.iter().enumerate() { for (ix, arg) in inner_fn.sig.inputs.iter().enumerate() {
if let FnArg::Typed(arg) = arg { if let FnArg::Typed(arg) = arg {
if let Type::Path(ty) = &*arg.ty { if let Type::Path(ty) = &*arg.ty {
let last_segment = ty.path.segments.last(); let last_segment = ty.path.segments.last();
match last_segment.map(|s| s.ident.to_string()).as_deref() { match last_segment.map(|s| s.ident.to_string()).as_deref() {
Some("TestAppContext") => {
let first_entity_id = ix * 100_000;
inner_fn_args.extend(quote!(
#namespace::TestAppContext::new(
foreground_platform.clone(),
cx.platform().clone(),
deterministic.build_foreground(#ix),
deterministic.build_background(),
cx.font_cache().clone(),
cx.leak_detector(),
#first_entity_id,
),
));
}
Some("StdRng") => { Some("StdRng") => {
inner_fn_args.extend(quote!(rand::SeedableRng::seed_from_u64(seed),)); inner_fn_args.extend(quote!(rand::SeedableRng::seed_from_u64(seed),));
} }
@ -98,6 +85,42 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
) )
} }
} }
} else if let Type::Reference(ty) = &*arg.ty {
match &*ty.elem {
Type::Path(ty) => {
let last_segment = ty.path.segments.last();
match last_segment.map(|s| s.ident.to_string()).as_deref() {
Some("TestAppContext") => {
let first_entity_id = ix * 100_000;
let cx_varname = format_ident!("cx_{}", ix);
cx_vars.extend(quote!(
let mut #cx_varname = #namespace::TestAppContext::new(
foreground_platform.clone(),
cx.platform().clone(),
deterministic.build_foreground(#ix),
deterministic.build_background(),
cx.font_cache().clone(),
cx.leak_detector(),
#first_entity_id,
);
));
inner_fn_args.extend(quote!(&mut #cx_varname,));
}
_ => {
return TokenStream::from(
syn::Error::new_spanned(arg, "invalid argument")
.into_compile_error(),
)
}
}
}
_ => {
return TokenStream::from(
syn::Error::new_spanned(arg, "invalid argument")
.into_compile_error(),
)
}
}
} else { } else {
return TokenStream::from( return TokenStream::from(
syn::Error::new_spanned(arg, "invalid argument").into_compile_error(), syn::Error::new_spanned(arg, "invalid argument").into_compile_error(),
@ -120,7 +143,9 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
#starting_seed as u64, #starting_seed as u64,
#max_retries, #max_retries,
&mut |cx, foreground_platform, deterministic, seed, is_last_iteration| { &mut |cx, foreground_platform, deterministic, seed, is_last_iteration| {
cx.foreground().run(#inner_fn_name(#inner_fn_args)) #cx_vars
cx.foreground().run(#inner_fn_name(#inner_fn_args));
cx.foreground().run_until_parked();
} }
); );
} }

View File

@ -125,23 +125,23 @@ fn test_edit_events(cx: &mut gpui::MutableAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_apply_diff(mut cx: gpui::TestAppContext) { async fn test_apply_diff(cx: &mut gpui::TestAppContext) {
let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n"; let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n";
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx)); let buffer = cx.add_model(|cx| Buffer::new(0, text, cx));
let text = "a\nccc\ndddd\nffffff\n"; let text = "a\nccc\ndddd\nffffff\n";
let diff = buffer.read_with(&cx, |b, cx| b.diff(text.into(), cx)).await; let diff = buffer.read_with(cx, |b, cx| b.diff(text.into(), cx)).await;
buffer.update(&mut cx, |b, cx| b.apply_diff(diff, cx)); buffer.update(cx, |b, cx| b.apply_diff(diff, cx));
cx.read(|cx| assert_eq!(buffer.read(cx).text(), text)); cx.read(|cx| assert_eq!(buffer.read(cx).text(), text));
let text = "a\n1\n\nccc\ndd2dd\nffffff\n"; let text = "a\n1\n\nccc\ndd2dd\nffffff\n";
let diff = buffer.read_with(&cx, |b, cx| b.diff(text.into(), cx)).await; let diff = buffer.read_with(cx, |b, cx| b.diff(text.into(), cx)).await;
buffer.update(&mut cx, |b, cx| b.apply_diff(diff, cx)); buffer.update(cx, |b, cx| b.apply_diff(diff, cx));
cx.read(|cx| assert_eq!(buffer.read(cx).text(), text)); cx.read(|cx| assert_eq!(buffer.read(cx).text(), text));
} }
#[gpui::test] #[gpui::test]
async fn test_reparse(mut cx: gpui::TestAppContext) { async fn test_reparse(cx: &mut gpui::TestAppContext) {
let text = "fn a() {}"; let text = "fn a() {}";
let buffer = let buffer =
cx.add_model(|cx| Buffer::new(0, text, cx).with_language(Arc::new(rust_lang()), cx)); cx.add_model(|cx| Buffer::new(0, text, cx).with_language(Arc::new(rust_lang()), cx));
@ -159,13 +159,13 @@ async fn test_reparse(mut cx: gpui::TestAppContext) {
) )
); );
buffer.update(&mut cx, |buffer, _| { buffer.update(cx, |buffer, _| {
buffer.set_sync_parse_timeout(Duration::ZERO) buffer.set_sync_parse_timeout(Duration::ZERO)
}); });
// Perform some edits (add parameter and variable reference) // Perform some edits (add parameter and variable reference)
// Parsing doesn't begin until the transaction is complete // Parsing doesn't begin until the transaction is complete
buffer.update(&mut cx, |buf, cx| { buffer.update(cx, |buf, cx| {
buf.start_transaction(); buf.start_transaction();
let offset = buf.text().find(")").unwrap(); let offset = buf.text().find(")").unwrap();
@ -196,19 +196,19 @@ async fn test_reparse(mut cx: gpui::TestAppContext) {
// * turn identifier into a field expression // * turn identifier into a field expression
// * turn field expression into a method call // * turn field expression into a method call
// * add a turbofish to the method call // * add a turbofish to the method call
buffer.update(&mut cx, |buf, cx| { buffer.update(cx, |buf, cx| {
let offset = buf.text().find(";").unwrap(); let offset = buf.text().find(";").unwrap();
buf.edit(vec![offset..offset], ".e", cx); buf.edit(vec![offset..offset], ".e", cx);
assert_eq!(buf.text(), "fn a(b: C) { d.e; }"); assert_eq!(buf.text(), "fn a(b: C) { d.e; }");
assert!(buf.is_parsing()); assert!(buf.is_parsing());
}); });
buffer.update(&mut cx, |buf, cx| { buffer.update(cx, |buf, cx| {
let offset = buf.text().find(";").unwrap(); let offset = buf.text().find(";").unwrap();
buf.edit(vec![offset..offset], "(f)", cx); buf.edit(vec![offset..offset], "(f)", cx);
assert_eq!(buf.text(), "fn a(b: C) { d.e(f); }"); assert_eq!(buf.text(), "fn a(b: C) { d.e(f); }");
assert!(buf.is_parsing()); assert!(buf.is_parsing());
}); });
buffer.update(&mut cx, |buf, cx| { buffer.update(cx, |buf, cx| {
let offset = buf.text().find("(f)").unwrap(); let offset = buf.text().find("(f)").unwrap();
buf.edit(vec![offset..offset], "::<G>", cx); buf.edit(vec![offset..offset], "::<G>", cx);
assert_eq!(buf.text(), "fn a(b: C) { d.e::<G>(f); }"); assert_eq!(buf.text(), "fn a(b: C) { d.e::<G>(f); }");
@ -230,7 +230,7 @@ async fn test_reparse(mut cx: gpui::TestAppContext) {
) )
); );
buffer.update(&mut cx, |buf, cx| { buffer.update(cx, |buf, cx| {
buf.undo(cx); buf.undo(cx);
assert_eq!(buf.text(), "fn a() {}"); assert_eq!(buf.text(), "fn a() {}");
assert!(buf.is_parsing()); assert!(buf.is_parsing());
@ -247,7 +247,7 @@ async fn test_reparse(mut cx: gpui::TestAppContext) {
) )
); );
buffer.update(&mut cx, |buf, cx| { buffer.update(cx, |buf, cx| {
buf.redo(cx); buf.redo(cx);
assert_eq!(buf.text(), "fn a(b: C) { d.e::<G>(f); }"); assert_eq!(buf.text(), "fn a(b: C) { d.e::<G>(f); }");
assert!(buf.is_parsing()); assert!(buf.is_parsing());
@ -276,7 +276,7 @@ async fn test_reparse(mut cx: gpui::TestAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_outline(mut cx: gpui::TestAppContext) { async fn test_outline(cx: &mut gpui::TestAppContext) {
let language = Arc::new( let language = Arc::new(
rust_lang() rust_lang()
.with_outline_query( .with_outline_query(
@ -336,7 +336,7 @@ async fn test_outline(mut cx: gpui::TestAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx)); let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let outline = buffer let outline = buffer
.read_with(&cx, |buffer, _| buffer.snapshot().outline(None)) .read_with(cx, |buffer, _| buffer.snapshot().outline(None))
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@ -553,7 +553,7 @@ fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut MutableAppConte
} }
#[gpui::test] #[gpui::test]
async fn test_diagnostics(mut cx: gpui::TestAppContext) { async fn test_diagnostics(cx: &mut gpui::TestAppContext) {
let (language_server, mut fake) = cx.update(lsp::LanguageServer::fake); let (language_server, mut fake) = cx.update(lsp::LanguageServer::fake);
let mut rust_lang = rust_lang(); let mut rust_lang = rust_lang();
rust_lang.config.language_server = Some(LanguageServerConfig { rust_lang.config.language_server = Some(LanguageServerConfig {
@ -579,13 +579,13 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) {
.await; .await;
// Edit the buffer, moving the content down // Edit the buffer, moving the content down
buffer.update(&mut cx, |buffer, cx| buffer.edit([0..0], "\n\n", cx)); buffer.update(cx, |buffer, cx| buffer.edit([0..0], "\n\n", cx));
let change_notification_1 = fake let change_notification_1 = fake
.receive_notification::<lsp::notification::DidChangeTextDocument>() .receive_notification::<lsp::notification::DidChangeTextDocument>()
.await; .await;
assert!(change_notification_1.text_document.version > open_notification.text_document.version); assert!(change_notification_1.text_document.version > open_notification.text_document.version);
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
// Receive diagnostics for an earlier version of the buffer. // Receive diagnostics for an earlier version of the buffer.
buffer buffer
.update_diagnostics( .update_diagnostics(
@ -760,7 +760,7 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) {
// Keep editing the buffer and ensure disk-based diagnostics get translated according to the // Keep editing the buffer and ensure disk-based diagnostics get translated according to the
// changes since the last save. // changes since the last save.
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
buffer.edit(Some(Point::new(2, 0)..Point::new(2, 0)), " ", cx); buffer.edit(Some(Point::new(2, 0)..Point::new(2, 0)), " ", cx);
buffer.edit(Some(Point::new(2, 8)..Point::new(2, 10)), "(x: usize)", cx); buffer.edit(Some(Point::new(2, 8)..Point::new(2, 10)), "(x: usize)", cx);
}); });
@ -771,7 +771,7 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) {
change_notification_2.text_document.version > change_notification_1.text_document.version change_notification_2.text_document.version > change_notification_1.text_document.version
); );
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
buffer buffer
.update_diagnostics( .update_diagnostics(
vec![ vec![
@ -836,7 +836,7 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_edits_from_lsp_with_past_version(mut cx: gpui::TestAppContext) { async fn test_edits_from_lsp_with_past_version(cx: &mut gpui::TestAppContext) {
let (language_server, mut fake) = cx.update(lsp::LanguageServer::fake); let (language_server, mut fake) = cx.update(lsp::LanguageServer::fake);
let text = " let text = "
@ -865,7 +865,7 @@ async fn test_edits_from_lsp_with_past_version(mut cx: gpui::TestAppContext) {
.version; .version;
// Simulate editing the buffer after the language server computes some edits. // Simulate editing the buffer after the language server computes some edits.
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
buffer.edit( buffer.edit(
[Point::new(0, 0)..Point::new(0, 0)], [Point::new(0, 0)..Point::new(0, 0)],
"// above first function\n", "// above first function\n",
@ -902,7 +902,7 @@ async fn test_edits_from_lsp_with_past_version(mut cx: gpui::TestAppContext) {
}); });
let edits = buffer let edits = buffer
.update(&mut cx, |buffer, cx| { .update(cx, |buffer, cx| {
buffer.edits_from_lsp( buffer.edits_from_lsp(
vec![ vec![
// replace body of first function // replace body of first function
@ -937,7 +937,7 @@ async fn test_edits_from_lsp_with_past_version(mut cx: gpui::TestAppContext) {
.await .await
.unwrap(); .unwrap();
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
for (range, new_text) in edits { for (range, new_text) in edits {
buffer.edit([range], new_text, cx); buffer.edit([range], new_text, cx);
} }
@ -962,7 +962,7 @@ async fn test_edits_from_lsp_with_past_version(mut cx: gpui::TestAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_edits_from_lsp_with_edits_on_adjacent_lines(mut cx: gpui::TestAppContext) { async fn test_edits_from_lsp_with_edits_on_adjacent_lines(cx: &mut gpui::TestAppContext) {
let text = " let text = "
use a::b; use a::b;
use a::c; use a::c;
@ -979,7 +979,7 @@ async fn test_edits_from_lsp_with_edits_on_adjacent_lines(mut cx: gpui::TestAppC
// Simulate the language server sending us a small edit in the form of a very large diff. // Simulate the language server sending us a small edit in the form of a very large diff.
// Rust-analyzer does this when performing a merge-imports code action. // Rust-analyzer does this when performing a merge-imports code action.
let edits = buffer let edits = buffer
.update(&mut cx, |buffer, cx| { .update(cx, |buffer, cx| {
buffer.edits_from_lsp( buffer.edits_from_lsp(
[ [
// Replace the first use statement without editing the semicolon. // Replace the first use statement without editing the semicolon.
@ -1015,7 +1015,7 @@ async fn test_edits_from_lsp_with_edits_on_adjacent_lines(mut cx: gpui::TestAppC
.await .await
.unwrap(); .unwrap();
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
let edits = edits let edits = edits
.into_iter() .into_iter()
.map(|(range, text)| { .map(|(range, text)| {
@ -1053,7 +1053,7 @@ async fn test_edits_from_lsp_with_edits_on_adjacent_lines(mut cx: gpui::TestAppC
} }
#[gpui::test] #[gpui::test]
async fn test_empty_diagnostic_ranges(mut cx: gpui::TestAppContext) { async fn test_empty_diagnostic_ranges(cx: &mut gpui::TestAppContext) {
cx.add_model(|cx| { cx.add_model(|cx| {
let text = concat!( let text = concat!(
"let one = ;\n", // "let one = ;\n", //

View File

@ -712,7 +712,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_fake(mut cx: TestAppContext) { async fn test_fake(cx: &mut TestAppContext) {
let (server, mut fake) = cx.update(LanguageServer::fake); let (server, mut fake) = cx.update(LanguageServer::fake);
let (message_tx, message_rx) = channel::unbounded(); let (message_tx, message_rx) = channel::unbounded();

View File

@ -3603,7 +3603,7 @@ mod tests {
use worktree::WorktreeHandle as _; use worktree::WorktreeHandle as _;
#[gpui::test] #[gpui::test]
async fn test_populate_and_search(mut cx: gpui::TestAppContext) { async fn test_populate_and_search(cx: &mut gpui::TestAppContext) {
let dir = temp_tree(json!({ let dir = temp_tree(json!({
"root": { "root": {
"apple": "", "apple": "",
@ -3627,10 +3627,10 @@ mod tests {
) )
.unwrap(); .unwrap();
let project = Project::test(Arc::new(RealFs), &mut cx); let project = Project::test(Arc::new(RealFs), cx);
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree(&root_link_path, false, cx) project.find_or_create_local_worktree(&root_link_path, false, cx)
}) })
.await .await
@ -3649,7 +3649,7 @@ mod tests {
let cancel_flag = Default::default(); let cancel_flag = Default::default();
let results = project let results = project
.read_with(&cx, |project, cx| { .read_with(cx, |project, cx| {
project.match_paths("bna", false, false, 10, &cancel_flag, cx) project.match_paths("bna", false, false, 10, &cancel_flag, cx)
}) })
.await; .await;
@ -3666,7 +3666,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_language_server_diagnostics(mut cx: gpui::TestAppContext) { async fn test_language_server_diagnostics(cx: &mut gpui::TestAppContext) {
let (language_server_config, mut fake_servers) = LanguageServerConfig::fake(); let (language_server_config, mut fake_servers) = LanguageServerConfig::fake();
let progress_token = language_server_config let progress_token = language_server_config
.disk_based_diagnostics_progress_token .disk_based_diagnostics_progress_token
@ -3693,31 +3693,31 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs, &mut cx); let project = Project::test(fs, cx);
project.update(&mut cx, |project, _| { project.update(cx, |project, _| {
Arc::get_mut(&mut project.languages).unwrap().add(language); Arc::get_mut(&mut project.languages).unwrap().add(language);
}); });
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir", false, cx) project.find_or_create_local_worktree("/dir", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = tree.read_with(&cx, |tree, _| tree.id()); let worktree_id = tree.read_with(cx, |tree, _| tree.id());
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
// Cause worktree to start the fake language server // Cause worktree to start the fake language server
let _buffer = project let _buffer = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.open_buffer((worktree_id, Path::new("b.rs")), cx) project.open_buffer((worktree_id, Path::new("b.rs")), cx)
}) })
.await .await
.unwrap(); .unwrap();
let mut events = subscribe(&project, &mut cx); let mut events = subscribe(&project, cx);
let mut fake_server = fake_servers.next().await.unwrap(); let mut fake_server = fake_servers.next().await.unwrap();
fake_server.start_progress(&progress_token).await; fake_server.start_progress(&progress_token).await;
@ -3759,11 +3759,11 @@ mod tests {
); );
let buffer = project let buffer = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx))
.await .await
.unwrap(); .unwrap();
buffer.read_with(&cx, |buffer, _| { buffer.read_with(cx, |buffer, _| {
let snapshot = buffer.snapshot(); let snapshot = buffer.snapshot();
let diagnostics = snapshot let diagnostics = snapshot
.diagnostics_in_range::<_, Point>(0..buffer.len()) .diagnostics_in_range::<_, Point>(0..buffer.len())
@ -3785,7 +3785,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_search_worktree_without_files(mut cx: gpui::TestAppContext) { async fn test_search_worktree_without_files(cx: &mut gpui::TestAppContext) {
let dir = temp_tree(json!({ let dir = temp_tree(json!({
"root": { "root": {
"dir1": {}, "dir1": {},
@ -3795,9 +3795,9 @@ mod tests {
} }
})); }));
let project = Project::test(Arc::new(RealFs), &mut cx); let project = Project::test(Arc::new(RealFs), cx);
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree(&dir.path(), false, cx) project.find_or_create_local_worktree(&dir.path(), false, cx)
}) })
.await .await
@ -3808,7 +3808,7 @@ mod tests {
let cancel_flag = Default::default(); let cancel_flag = Default::default();
let results = project let results = project
.read_with(&cx, |project, cx| { .read_with(cx, |project, cx| {
project.match_paths("dir", false, false, 10, &cancel_flag, cx) project.match_paths("dir", false, false, 10, &cancel_flag, cx)
}) })
.await; .await;
@ -3817,7 +3817,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_definition(mut cx: gpui::TestAppContext) { async fn test_definition(cx: &mut gpui::TestAppContext) {
let (language_server_config, mut fake_servers) = LanguageServerConfig::fake(); let (language_server_config, mut fake_servers) = LanguageServerConfig::fake();
let language = Arc::new(Language::new( let language = Arc::new(Language::new(
LanguageConfig { LanguageConfig {
@ -3839,23 +3839,23 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs, &mut cx); let project = Project::test(fs, cx);
project.update(&mut cx, |project, _| { project.update(cx, |project, _| {
Arc::get_mut(&mut project.languages).unwrap().add(language); Arc::get_mut(&mut project.languages).unwrap().add(language);
}); });
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir/b.rs", false, cx) project.find_or_create_local_worktree("/dir/b.rs", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = tree.read_with(&cx, |tree, _| tree.id()); let worktree_id = tree.read_with(cx, |tree, _| tree.id());
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
let buffer = project let buffer = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.open_buffer( project.open_buffer(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -3883,7 +3883,7 @@ mod tests {
}); });
let mut definitions = project let mut definitions = project
.update(&mut cx, |project, cx| project.definition(&buffer, 22, cx)) .update(cx, |project, cx| project.definition(&buffer, 22, cx))
.await .await
.unwrap(); .unwrap();
@ -3934,7 +3934,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_save_file(mut cx: gpui::TestAppContext) { async fn test_save_file(cx: &mut gpui::TestAppContext) {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
fs.insert_tree( fs.insert_tree(
"/dir", "/dir",
@ -3944,22 +3944,22 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
let worktree_id = project let worktree_id = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree("/dir", false, cx) p.find_or_create_local_worktree("/dir", false, cx)
}) })
.await .await
.unwrap() .unwrap()
.0 .0
.read_with(&cx, |tree, _| tree.id()); .read_with(cx, |tree, _| tree.id());
let buffer = project let buffer = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "file1"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await .await
.unwrap(); .unwrap();
buffer buffer
.update(&mut cx, |buffer, cx| { .update(cx, |buffer, cx| {
assert_eq!(buffer.text(), "the old contents"); assert_eq!(buffer.text(), "the old contents");
buffer.edit(Some(0..0), "a line of text.\n".repeat(10 * 1024), cx); buffer.edit(Some(0..0), "a line of text.\n".repeat(10 * 1024), cx);
buffer.save(cx) buffer.save(cx)
@ -3968,11 +3968,11 @@ mod tests {
.unwrap(); .unwrap();
let new_text = fs.load(Path::new("/dir/file1")).await.unwrap(); let new_text = fs.load(Path::new("/dir/file1")).await.unwrap();
assert_eq!(new_text, buffer.read_with(&cx, |buffer, _| buffer.text())); assert_eq!(new_text, buffer.read_with(cx, |buffer, _| buffer.text()));
} }
#[gpui::test] #[gpui::test]
async fn test_save_in_single_file_worktree(mut cx: gpui::TestAppContext) { async fn test_save_in_single_file_worktree(cx: &mut gpui::TestAppContext) {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
fs.insert_tree( fs.insert_tree(
"/dir", "/dir",
@ -3982,22 +3982,22 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
let worktree_id = project let worktree_id = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree("/dir/file1", false, cx) p.find_or_create_local_worktree("/dir/file1", false, cx)
}) })
.await .await
.unwrap() .unwrap()
.0 .0
.read_with(&cx, |tree, _| tree.id()); .read_with(cx, |tree, _| tree.id());
let buffer = project let buffer = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, ""), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, ""), cx))
.await .await
.unwrap(); .unwrap();
buffer buffer
.update(&mut cx, |buffer, cx| { .update(cx, |buffer, cx| {
buffer.edit(Some(0..0), "a line of text.\n".repeat(10 * 1024), cx); buffer.edit(Some(0..0), "a line of text.\n".repeat(10 * 1024), cx);
buffer.save(cx) buffer.save(cx)
}) })
@ -4005,11 +4005,11 @@ mod tests {
.unwrap(); .unwrap();
let new_text = fs.load(Path::new("/dir/file1")).await.unwrap(); let new_text = fs.load(Path::new("/dir/file1")).await.unwrap();
assert_eq!(new_text, buffer.read_with(&cx, |buffer, _| buffer.text())); assert_eq!(new_text, buffer.read_with(cx, |buffer, _| buffer.text()));
} }
#[gpui::test(retries = 5)] #[gpui::test(retries = 5)]
async fn test_rescan_and_remote_updates(mut cx: gpui::TestAppContext) { async fn test_rescan_and_remote_updates(cx: &mut gpui::TestAppContext) {
let dir = temp_tree(json!({ let dir = temp_tree(json!({
"a": { "a": {
"file1": "", "file1": "",
@ -4024,16 +4024,16 @@ mod tests {
} }
})); }));
let project = Project::test(Arc::new(RealFs), &mut cx); let project = Project::test(Arc::new(RealFs), cx);
let rpc = project.read_with(&cx, |p, _| p.client.clone()); let rpc = project.read_with(cx, |p, _| p.client.clone());
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree(dir.path(), false, cx) p.find_or_create_local_worktree(dir.path(), false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = tree.read_with(&cx, |tree, _| tree.id()); let worktree_id = tree.read_with(cx, |tree, _| tree.id());
let buffer_for_path = |path: &'static str, cx: &mut gpui::TestAppContext| { let buffer_for_path = |path: &'static str, cx: &mut gpui::TestAppContext| {
let buffer = project.update(cx, |p, cx| p.open_buffer((worktree_id, path), cx)); let buffer = project.update(cx, |p, cx| p.open_buffer((worktree_id, path), cx));
@ -4047,10 +4047,10 @@ mod tests {
}) })
}; };
let buffer2 = buffer_for_path("a/file2", &mut cx).await; let buffer2 = buffer_for_path("a/file2", cx).await;
let buffer3 = buffer_for_path("a/file3", &mut cx).await; let buffer3 = buffer_for_path("a/file3", cx).await;
let buffer4 = buffer_for_path("b/c/file4", &mut cx).await; let buffer4 = buffer_for_path("b/c/file4", cx).await;
let buffer5 = buffer_for_path("b/c/file5", &mut cx).await; let buffer5 = buffer_for_path("b/c/file5", cx).await;
let file2_id = id_for_path("a/file2", &cx); let file2_id = id_for_path("a/file2", &cx);
let file3_id = id_for_path("a/file3", &cx); let file3_id = id_for_path("a/file3", &cx);
@ -4061,7 +4061,7 @@ mod tests {
.await; .await;
// Create a remote copy of this worktree. // Create a remote copy of this worktree.
let initial_snapshot = tree.read_with(&cx, |tree, _| tree.as_local().unwrap().snapshot()); let initial_snapshot = tree.read_with(cx, |tree, _| tree.as_local().unwrap().snapshot());
let (remote, load_task) = cx.update(|cx| { let (remote, load_task) = cx.update(|cx| {
Worktree::remote( Worktree::remote(
1, 1,
@ -4136,7 +4136,7 @@ mod tests {
// Update the remote worktree. Check that it becomes consistent with the // Update the remote worktree. Check that it becomes consistent with the
// local worktree. // local worktree.
remote.update(&mut cx, |remote, cx| { remote.update(cx, |remote, cx| {
let update_message = tree.read(cx).as_local().unwrap().snapshot().build_update( let update_message = tree.read(cx).as_local().unwrap().snapshot().build_update(
&initial_snapshot, &initial_snapshot,
1, 1,
@ -4161,7 +4161,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_buffer_deduping(mut cx: gpui::TestAppContext) { async fn test_buffer_deduping(cx: &mut gpui::TestAppContext) {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
fs.insert_tree( fs.insert_tree(
"/the-dir", "/the-dir",
@ -4172,18 +4172,18 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
let worktree_id = project let worktree_id = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree("/the-dir", false, cx) p.find_or_create_local_worktree("/the-dir", false, cx)
}) })
.await .await
.unwrap() .unwrap()
.0 .0
.read_with(&cx, |tree, _| tree.id()); .read_with(cx, |tree, _| tree.id());
// Spawn multiple tasks to open paths, repeating some paths. // Spawn multiple tasks to open paths, repeating some paths.
let (buffer_a_1, buffer_b, buffer_a_2) = project.update(&mut cx, |p, cx| { let (buffer_a_1, buffer_b, buffer_a_2) = project.update(cx, |p, cx| {
( (
p.open_buffer((worktree_id, "a.txt"), cx), p.open_buffer((worktree_id, "a.txt"), cx),
p.open_buffer((worktree_id, "b.txt"), cx), p.open_buffer((worktree_id, "b.txt"), cx),
@ -4194,8 +4194,8 @@ mod tests {
let buffer_a_1 = buffer_a_1.await.unwrap(); let buffer_a_1 = buffer_a_1.await.unwrap();
let buffer_a_2 = buffer_a_2.await.unwrap(); let buffer_a_2 = buffer_a_2.await.unwrap();
let buffer_b = buffer_b.await.unwrap(); let buffer_b = buffer_b.await.unwrap();
assert_eq!(buffer_a_1.read_with(&cx, |b, _| b.text()), "a-contents"); assert_eq!(buffer_a_1.read_with(cx, |b, _| b.text()), "a-contents");
assert_eq!(buffer_b.read_with(&cx, |b, _| b.text()), "b-contents"); assert_eq!(buffer_b.read_with(cx, |b, _| b.text()), "b-contents");
// There is only one buffer per path. // There is only one buffer per path.
let buffer_a_id = buffer_a_1.id(); let buffer_a_id = buffer_a_1.id();
@ -4204,7 +4204,7 @@ mod tests {
// Open the same path again while it is still open. // Open the same path again while it is still open.
drop(buffer_a_1); drop(buffer_a_1);
let buffer_a_3 = project let buffer_a_3 = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await .await
.unwrap(); .unwrap();
@ -4213,7 +4213,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_buffer_is_dirty(mut cx: gpui::TestAppContext) { async fn test_buffer_is_dirty(cx: &mut gpui::TestAppContext) {
use std::fs; use std::fs;
let dir = temp_tree(json!({ let dir = temp_tree(json!({
@ -4222,28 +4222,28 @@ mod tests {
"file3": "ghi", "file3": "ghi",
})); }));
let project = Project::test(Arc::new(RealFs), &mut cx); let project = Project::test(Arc::new(RealFs), cx);
let (worktree, _) = project let (worktree, _) = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree(dir.path(), false, cx) p.find_or_create_local_worktree(dir.path(), false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = worktree.read_with(&cx, |worktree, _| worktree.id()); let worktree_id = worktree.read_with(cx, |worktree, _| worktree.id());
worktree.flush_fs_events(&cx).await; worktree.flush_fs_events(&cx).await;
worktree worktree
.read_with(&cx, |t, _| t.as_local().unwrap().scan_complete()) .read_with(cx, |t, _| t.as_local().unwrap().scan_complete())
.await; .await;
let buffer1 = project let buffer1 = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "file1"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await .await
.unwrap(); .unwrap();
let events = Rc::new(RefCell::new(Vec::new())); let events = Rc::new(RefCell::new(Vec::new()));
// initially, the buffer isn't dirty. // initially, the buffer isn't dirty.
buffer1.update(&mut cx, |buffer, cx| { buffer1.update(cx, |buffer, cx| {
cx.subscribe(&buffer1, { cx.subscribe(&buffer1, {
let events = events.clone(); let events = events.clone();
move |_, _, event, _| events.borrow_mut().push(event.clone()) move |_, _, event, _| events.borrow_mut().push(event.clone())
@ -4257,7 +4257,7 @@ mod tests {
}); });
// after the first edit, the buffer is dirty, and emits a dirtied event. // after the first edit, the buffer is dirty, and emits a dirtied event.
buffer1.update(&mut cx, |buffer, cx| { buffer1.update(cx, |buffer, cx| {
assert!(buffer.text() == "ac"); assert!(buffer.text() == "ac");
assert!(buffer.is_dirty()); assert!(buffer.is_dirty());
assert_eq!( assert_eq!(
@ -4269,7 +4269,7 @@ mod tests {
}); });
// after saving, the buffer is not dirty, and emits a saved event. // after saving, the buffer is not dirty, and emits a saved event.
buffer1.update(&mut cx, |buffer, cx| { buffer1.update(cx, |buffer, cx| {
assert!(!buffer.is_dirty()); assert!(!buffer.is_dirty());
assert_eq!(*events.borrow(), &[language::Event::Saved]); assert_eq!(*events.borrow(), &[language::Event::Saved]);
events.borrow_mut().clear(); events.borrow_mut().clear();
@ -4279,7 +4279,7 @@ mod tests {
}); });
// after editing again, the buffer is dirty, and emits another dirty event. // after editing again, the buffer is dirty, and emits another dirty event.
buffer1.update(&mut cx, |buffer, cx| { buffer1.update(cx, |buffer, cx| {
assert!(buffer.text() == "aBDc"); assert!(buffer.text() == "aBDc");
assert!(buffer.is_dirty()); assert!(buffer.is_dirty());
assert_eq!( assert_eq!(
@ -4304,10 +4304,10 @@ mod tests {
// When a file is deleted, the buffer is considered dirty. // When a file is deleted, the buffer is considered dirty.
let events = Rc::new(RefCell::new(Vec::new())); let events = Rc::new(RefCell::new(Vec::new()));
let buffer2 = project let buffer2 = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "file2"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "file2"), cx))
.await .await
.unwrap(); .unwrap();
buffer2.update(&mut cx, |_, cx| { buffer2.update(cx, |_, cx| {
cx.subscribe(&buffer2, { cx.subscribe(&buffer2, {
let events = events.clone(); let events = events.clone();
move |_, _, event, _| events.borrow_mut().push(event.clone()) move |_, _, event, _| events.borrow_mut().push(event.clone())
@ -4325,10 +4325,10 @@ mod tests {
// When a file is already dirty when deleted, we don't emit a Dirtied event. // When a file is already dirty when deleted, we don't emit a Dirtied event.
let events = Rc::new(RefCell::new(Vec::new())); let events = Rc::new(RefCell::new(Vec::new()));
let buffer3 = project let buffer3 = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "file3"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "file3"), cx))
.await .await
.unwrap(); .unwrap();
buffer3.update(&mut cx, |_, cx| { buffer3.update(cx, |_, cx| {
cx.subscribe(&buffer3, { cx.subscribe(&buffer3, {
let events = events.clone(); let events = events.clone();
move |_, _, event, _| events.borrow_mut().push(event.clone()) move |_, _, event, _| events.borrow_mut().push(event.clone())
@ -4337,7 +4337,7 @@ mod tests {
}); });
worktree.flush_fs_events(&cx).await; worktree.flush_fs_events(&cx).await;
buffer3.update(&mut cx, |buffer, cx| { buffer3.update(cx, |buffer, cx| {
buffer.edit(Some(0..0), "x", cx); buffer.edit(Some(0..0), "x", cx);
}); });
events.borrow_mut().clear(); events.borrow_mut().clear();
@ -4350,30 +4350,28 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_buffer_file_changes_on_disk(mut cx: gpui::TestAppContext) { async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) {
use std::fs; use std::fs;
let initial_contents = "aaa\nbbbbb\nc\n"; let initial_contents = "aaa\nbbbbb\nc\n";
let dir = temp_tree(json!({ "the-file": initial_contents })); let dir = temp_tree(json!({ "the-file": initial_contents }));
let project = Project::test(Arc::new(RealFs), &mut cx); let project = Project::test(Arc::new(RealFs), cx);
let (worktree, _) = project let (worktree, _) = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree(dir.path(), false, cx) p.find_or_create_local_worktree(dir.path(), false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = worktree.read_with(&cx, |tree, _| tree.id()); let worktree_id = worktree.read_with(cx, |tree, _| tree.id());
worktree worktree
.read_with(&cx, |t, _| t.as_local().unwrap().scan_complete()) .read_with(cx, |t, _| t.as_local().unwrap().scan_complete())
.await; .await;
let abs_path = dir.path().join("the-file"); let abs_path = dir.path().join("the-file");
let buffer = project let buffer = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| p.open_buffer((worktree_id, "the-file"), cx))
p.open_buffer((worktree_id, "the-file"), cx)
})
.await .await
.unwrap(); .unwrap();
@ -4397,7 +4395,7 @@ mod tests {
// Change the file on disk, adding two new lines of text, and removing // Change the file on disk, adding two new lines of text, and removing
// one line. // one line.
buffer.read_with(&cx, |buffer, _| { buffer.read_with(cx, |buffer, _| {
assert!(!buffer.is_dirty()); assert!(!buffer.is_dirty());
assert!(!buffer.has_conflict()); assert!(!buffer.has_conflict());
}); });
@ -4411,7 +4409,7 @@ mod tests {
.condition(&cx, |buffer, _| buffer.text() == new_contents) .condition(&cx, |buffer, _| buffer.text() == new_contents)
.await; .await;
buffer.update(&mut cx, |buffer, _| { buffer.update(cx, |buffer, _| {
assert_eq!(buffer.text(), new_contents); assert_eq!(buffer.text(), new_contents);
assert!(!buffer.is_dirty()); assert!(!buffer.is_dirty());
assert!(!buffer.has_conflict()); assert!(!buffer.has_conflict());
@ -4433,7 +4431,7 @@ mod tests {
}); });
// Modify the buffer // Modify the buffer
buffer.update(&mut cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
buffer.edit(vec![0..0], " ", cx); buffer.edit(vec![0..0], " ", cx);
assert!(buffer.is_dirty()); assert!(buffer.is_dirty());
assert!(!buffer.has_conflict()); assert!(!buffer.has_conflict());
@ -4450,7 +4448,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_grouped_diagnostics(mut cx: gpui::TestAppContext) { async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
fs.insert_tree( fs.insert_tree(
"/the-dir", "/the-dir",
@ -4467,17 +4465,17 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
let (worktree, _) = project let (worktree, _) = project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.find_or_create_local_worktree("/the-dir", false, cx) p.find_or_create_local_worktree("/the-dir", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = worktree.read_with(&cx, |tree, _| tree.id()); let worktree_id = worktree.read_with(cx, |tree, _| tree.id());
let buffer = project let buffer = project
.update(&mut cx, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)) .update(cx, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx))
.await .await
.unwrap(); .unwrap();
@ -4582,11 +4580,11 @@ mod tests {
}; };
project project
.update(&mut cx, |p, cx| { .update(cx, |p, cx| {
p.update_diagnostics(message, &Default::default(), cx) p.update_diagnostics(message, &Default::default(), cx)
}) })
.unwrap(); .unwrap();
let buffer = buffer.read_with(&cx, |buffer, _| buffer.snapshot()); let buffer = buffer.read_with(cx, |buffer, _| buffer.snapshot());
assert_eq!( assert_eq!(
buffer buffer
@ -4709,7 +4707,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_rename(mut cx: gpui::TestAppContext) { async fn test_rename(cx: &mut gpui::TestAppContext) {
let (language_server_config, mut fake_servers) = LanguageServerConfig::fake(); let (language_server_config, mut fake_servers) = LanguageServerConfig::fake();
let language = Arc::new(Language::new( let language = Arc::new(Language::new(
LanguageConfig { LanguageConfig {
@ -4731,23 +4729,23 @@ mod tests {
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
project.update(&mut cx, |project, _| { project.update(cx, |project, _| {
Arc::get_mut(&mut project.languages).unwrap().add(language); Arc::get_mut(&mut project.languages).unwrap().add(language);
}); });
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir", false, cx) project.find_or_create_local_worktree("/dir", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = tree.read_with(&cx, |tree, _| tree.id()); let worktree_id = tree.read_with(cx, |tree, _| tree.id());
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
let buffer = project let buffer = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.open_buffer((worktree_id, Path::new("one.rs")), cx) project.open_buffer((worktree_id, Path::new("one.rs")), cx)
}) })
.await .await
@ -4755,7 +4753,7 @@ mod tests {
let mut fake_server = fake_servers.next().await.unwrap(); let mut fake_server = fake_servers.next().await.unwrap();
let response = project.update(&mut cx, |project, cx| { let response = project.update(cx, |project, cx| {
project.prepare_rename(buffer.clone(), 7, cx) project.prepare_rename(buffer.clone(), 7, cx)
}); });
fake_server fake_server
@ -4771,10 +4769,10 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let range = response.await.unwrap().unwrap(); let range = response.await.unwrap().unwrap();
let range = buffer.read_with(&cx, |buffer, _| range.to_offset(buffer)); let range = buffer.read_with(cx, |buffer, _| range.to_offset(buffer));
assert_eq!(range, 6..9); assert_eq!(range, 6..9);
let response = project.update(&mut cx, |project, cx| { let response = project.update(cx, |project, cx| {
project.perform_rename(buffer.clone(), 7, "THREE".to_string(), true, cx) project.perform_rename(buffer.clone(), 7, "THREE".to_string(), true, cx)
}); });
fake_server fake_server
@ -4837,7 +4835,7 @@ mod tests {
.remove_entry(&buffer) .remove_entry(&buffer)
.unwrap() .unwrap()
.0 .0
.read_with(&cx, |buffer, _| buffer.text()), .read_with(cx, |buffer, _| buffer.text()),
"const THREE: usize = 1;" "const THREE: usize = 1;"
); );
assert_eq!( assert_eq!(
@ -4845,13 +4843,13 @@ mod tests {
.into_keys() .into_keys()
.next() .next()
.unwrap() .unwrap()
.read_with(&cx, |buffer, _| buffer.text()), .read_with(cx, |buffer, _| buffer.text()),
"const TWO: usize = one::THREE + one::THREE;" "const TWO: usize = one::THREE + one::THREE;"
); );
} }
#[gpui::test] #[gpui::test]
async fn test_search(mut cx: gpui::TestAppContext) { async fn test_search(cx: &mut gpui::TestAppContext) {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
fs.insert_tree( fs.insert_tree(
"/dir", "/dir",
@ -4863,19 +4861,19 @@ mod tests {
}), }),
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir", false, cx) project.find_or_create_local_worktree("/dir", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = tree.read_with(&cx, |tree, _| tree.id()); let worktree_id = tree.read_with(cx, |tree, _| tree.id());
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
assert_eq!( assert_eq!(
search(&project, SearchQuery::text("TWO", false, true), &mut cx) search(&project, SearchQuery::text("TWO", false, true), cx)
.await .await
.unwrap(), .unwrap(),
HashMap::from_iter([ HashMap::from_iter([
@ -4885,17 +4883,17 @@ mod tests {
); );
let buffer_4 = project let buffer_4 = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.open_buffer((worktree_id, "four.rs"), cx) project.open_buffer((worktree_id, "four.rs"), cx)
}) })
.await .await
.unwrap(); .unwrap();
buffer_4.update(&mut cx, |buffer, cx| { buffer_4.update(cx, |buffer, cx| {
buffer.edit([20..28, 31..43], "two::TWO", cx); buffer.edit([20..28, 31..43], "two::TWO", cx);
}); });
assert_eq!( assert_eq!(
search(&project, SearchQuery::text("TWO", false, true), &mut cx) search(&project, SearchQuery::text("TWO", false, true), cx)
.await .await
.unwrap(), .unwrap(),
HashMap::from_iter([ HashMap::from_iter([

View File

@ -2441,7 +2441,7 @@ mod tests {
use util::test::temp_tree; use util::test::temp_tree;
#[gpui::test] #[gpui::test]
async fn test_traversal(cx: gpui::TestAppContext) { async fn test_traversal(cx: &mut gpui::TestAppContext) {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
fs.insert_tree( fs.insert_tree(
"/root", "/root",
@ -2470,7 +2470,7 @@ mod tests {
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
tree.read_with(&cx, |tree, _| { tree.read_with(cx, |tree, _| {
assert_eq!( assert_eq!(
tree.entries(false) tree.entries(false)
.map(|entry| entry.path.as_ref()) .map(|entry| entry.path.as_ref())
@ -2486,7 +2486,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_rescan_with_gitignore(cx: gpui::TestAppContext) { async fn test_rescan_with_gitignore(cx: &mut gpui::TestAppContext) {
let dir = temp_tree(json!({ let dir = temp_tree(json!({
".git": {}, ".git": {},
".gitignore": "ignored-dir\n", ".gitignore": "ignored-dir\n",

View File

@ -589,7 +589,7 @@ mod tests {
use workspace::WorkspaceParams; use workspace::WorkspaceParams;
#[gpui::test] #[gpui::test]
async fn test_visible_list(mut cx: gpui::TestAppContext) { async fn test_visible_list(cx: &mut gpui::TestAppContext) {
let params = cx.update(WorkspaceParams::test); let params = cx.update(WorkspaceParams::test);
let settings = params.settings.clone(); let settings = params.settings.clone();
let fs = params.fs.as_fake(); let fs = params.fs.as_fake();
@ -639,28 +639,28 @@ mod tests {
) )
}); });
let (root1, _) = project let (root1, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root1", false, cx) project.find_or_create_local_worktree("/root1", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
root1 root1
.read_with(&cx, |t, _| t.as_local().unwrap().scan_complete()) .read_with(cx, |t, _| t.as_local().unwrap().scan_complete())
.await; .await;
let (root2, _) = project let (root2, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root2", false, cx) project.find_or_create_local_worktree("/root2", false, cx)
}) })
.await .await
.unwrap(); .unwrap();
root2 root2
.read_with(&cx, |t, _| t.as_local().unwrap().scan_complete()) .read_with(cx, |t, _| t.as_local().unwrap().scan_complete())
.await; .await;
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
let panel = workspace.update(&mut cx, |_, cx| ProjectPanel::new(project, settings, cx)); let panel = workspace.update(cx, |_, cx| ProjectPanel::new(project, settings, cx));
assert_eq!( assert_eq!(
visible_entry_details(&panel, 0..50, &mut cx), visible_entry_details(&panel, 0..50, cx),
&[ &[
EntryDetails { EntryDetails {
filename: "root1".to_string(), filename: "root1".to_string(),
@ -721,9 +721,9 @@ mod tests {
], ],
); );
toggle_expand_dir(&panel, "root1/b", &mut cx); toggle_expand_dir(&panel, "root1/b", cx);
assert_eq!( assert_eq!(
visible_entry_details(&panel, 0..50, &mut cx), visible_entry_details(&panel, 0..50, cx),
&[ &[
EntryDetails { EntryDetails {
filename: "root1".to_string(), filename: "root1".to_string(),
@ -799,7 +799,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
visible_entry_details(&panel, 5..8, &mut cx), visible_entry_details(&panel, 5..8, cx),
[ [
EntryDetails { EntryDetails {
filename: "4".to_string(), filename: "4".to_string(),

View File

@ -347,7 +347,7 @@ mod tests {
use gpui::TestAppContext; use gpui::TestAppContext;
#[gpui::test(iterations = 50)] #[gpui::test(iterations = 50)]
async fn test_request_response(cx: TestAppContext) { async fn test_request_response(cx: &mut TestAppContext) {
let executor = cx.foreground(); let executor = cx.foreground();
// create 2 clients connected to 1 server // create 2 clients connected to 1 server
@ -441,7 +441,7 @@ mod tests {
} }
#[gpui::test(iterations = 50)] #[gpui::test(iterations = 50)]
async fn test_order_of_response_and_incoming(cx: TestAppContext) { async fn test_order_of_response_and_incoming(cx: &mut TestAppContext) {
let executor = cx.foreground(); let executor = cx.foreground();
let server = Peer::new(); let server = Peer::new();
let client = Peer::new(); let client = Peer::new();
@ -539,7 +539,7 @@ mod tests {
} }
#[gpui::test(iterations = 50)] #[gpui::test(iterations = 50)]
async fn test_dropping_request_before_completion(cx: TestAppContext) { async fn test_dropping_request_before_completion(cx: &mut TestAppContext) {
let executor = cx.foreground(); let executor = cx.foreground();
let server = Peer::new(); let server = Peer::new();
let client = Peer::new(); let client = Peer::new();
@ -651,7 +651,7 @@ mod tests {
} }
#[gpui::test(iterations = 50)] #[gpui::test(iterations = 50)]
async fn test_disconnect(cx: TestAppContext) { async fn test_disconnect(cx: &mut TestAppContext) {
let executor = cx.foreground(); let executor = cx.foreground();
let (client_conn, mut server_conn, _) = Connection::in_memory(cx.background()); let (client_conn, mut server_conn, _) = Connection::in_memory(cx.background());
@ -686,7 +686,7 @@ mod tests {
} }
#[gpui::test(iterations = 50)] #[gpui::test(iterations = 50)]
async fn test_io_error(cx: TestAppContext) { async fn test_io_error(cx: &mut TestAppContext) {
let executor = cx.foreground(); let executor = cx.foreground();
let (client_conn, mut server_conn, _) = Connection::in_memory(cx.background()); let (client_conn, mut server_conn, _) = Connection::in_memory(cx.background());

View File

@ -520,7 +520,7 @@ mod tests {
use unindent::Unindent as _; use unindent::Unindent as _;
#[gpui::test] #[gpui::test]
async fn test_search_simple(mut cx: TestAppContext) { async fn test_search_simple(cx: &mut TestAppContext) {
let fonts = cx.font_cache(); let fonts = cx.font_cache();
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default()); let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
theme.search.match_background = Color::red(); theme.search.match_background = Color::red();
@ -551,11 +551,11 @@ mod tests {
// Search for a string that appears with different casing. // Search for a string that appears with different casing.
// By default, search is case-insensitive. // By default, search is case-insensitive.
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.set_query("us", cx); search_bar.set_query("us", cx);
}); });
editor.next_notification(&cx).await; editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert_eq!( assert_eq!(
editor.all_highlighted_ranges(cx), editor.all_highlighted_ranges(cx),
&[ &[
@ -572,11 +572,11 @@ mod tests {
}); });
// Switch to a case sensitive search. // Switch to a case sensitive search.
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::CaseSensitive), cx); search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::CaseSensitive), cx);
}); });
editor.next_notification(&cx).await; editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert_eq!( assert_eq!(
editor.all_highlighted_ranges(cx), editor.all_highlighted_ranges(cx),
&[( &[(
@ -588,11 +588,11 @@ mod tests {
// Search for a string that appears both as a whole word and // Search for a string that appears both as a whole word and
// within other words. By default, all results are found. // within other words. By default, all results are found.
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.set_query("or", cx); search_bar.set_query("or", cx);
}); });
editor.next_notification(&cx).await; editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert_eq!( assert_eq!(
editor.all_highlighted_ranges(cx), editor.all_highlighted_ranges(cx),
&[ &[
@ -629,11 +629,11 @@ mod tests {
}); });
// Switch to a whole word search. // Switch to a whole word search.
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::WholeWord), cx); search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::WholeWord), cx);
}); });
editor.next_notification(&cx).await; editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert_eq!( assert_eq!(
editor.all_highlighted_ranges(cx), editor.all_highlighted_ranges(cx),
&[ &[
@ -653,10 +653,10 @@ mod tests {
); );
}); });
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)], cx); editor.select_display_ranges(&[DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)], cx);
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
search_bar.select_match(&SelectMatch(Direction::Next), cx); search_bar.select_match(&SelectMatch(Direction::Next), cx);
assert_eq!( assert_eq!(
@ -664,82 +664,82 @@ mod tests {
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)] [DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.select_match(&SelectMatch(Direction::Next), cx); search_bar.select_match(&SelectMatch(Direction::Next), cx);
assert_eq!( assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)), editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)] [DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(1)); assert_eq!(search_bar.active_match_index, Some(1));
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.select_match(&SelectMatch(Direction::Next), cx); search_bar.select_match(&SelectMatch(Direction::Next), cx);
assert_eq!( assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)), editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)] [DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2)); assert_eq!(search_bar.active_match_index, Some(2));
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.select_match(&SelectMatch(Direction::Next), cx); search_bar.select_match(&SelectMatch(Direction::Next), cx);
assert_eq!( assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)), editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)] [DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.select_match(&SelectMatch(Direction::Prev), cx); search_bar.select_match(&SelectMatch(Direction::Prev), cx);
assert_eq!( assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)), editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)] [DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2)); assert_eq!(search_bar.active_match_index, Some(2));
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.select_match(&SelectMatch(Direction::Prev), cx); search_bar.select_match(&SelectMatch(Direction::Prev), cx);
assert_eq!( assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)), editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)] [DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(1)); assert_eq!(search_bar.active_match_index, Some(1));
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
search_bar.select_match(&SelectMatch(Direction::Prev), cx); search_bar.select_match(&SelectMatch(Direction::Prev), cx);
assert_eq!( assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)), editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)] [DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
}); });
// Park the cursor in between matches and ensure that going to the previous match selects // Park the cursor in between matches and ensure that going to the previous match selects
// the closest match to the left. // the closest match to the left.
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx); editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx);
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(1)); assert_eq!(search_bar.active_match_index, Some(1));
search_bar.select_match(&SelectMatch(Direction::Prev), cx); search_bar.select_match(&SelectMatch(Direction::Prev), cx);
assert_eq!( assert_eq!(
@ -747,16 +747,16 @@ mod tests {
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)] [DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
}); });
// Park the cursor in between matches and ensure that going to the next match selects the // Park the cursor in between matches and ensure that going to the next match selects the
// closest match to the right. // closest match to the right.
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx); editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx);
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(1)); assert_eq!(search_bar.active_match_index, Some(1));
search_bar.select_match(&SelectMatch(Direction::Next), cx); search_bar.select_match(&SelectMatch(Direction::Next), cx);
assert_eq!( assert_eq!(
@ -764,16 +764,16 @@ mod tests {
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)] [DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(1)); assert_eq!(search_bar.active_match_index, Some(1));
}); });
// Park the cursor after the last match and ensure that going to the previous match selects // Park the cursor after the last match and ensure that going to the previous match selects
// the last match. // the last match.
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)], cx); editor.select_display_ranges(&[DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)], cx);
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(2)); assert_eq!(search_bar.active_match_index, Some(2));
search_bar.select_match(&SelectMatch(Direction::Prev), cx); search_bar.select_match(&SelectMatch(Direction::Prev), cx);
assert_eq!( assert_eq!(
@ -781,16 +781,16 @@ mod tests {
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)] [DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2)); assert_eq!(search_bar.active_match_index, Some(2));
}); });
// Park the cursor after the last match and ensure that going to the next match selects the // Park the cursor after the last match and ensure that going to the next match selects the
// first match. // first match.
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)], cx); editor.select_display_ranges(&[DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)], cx);
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(2)); assert_eq!(search_bar.active_match_index, Some(2));
search_bar.select_match(&SelectMatch(Direction::Next), cx); search_bar.select_match(&SelectMatch(Direction::Next), cx);
assert_eq!( assert_eq!(
@ -798,16 +798,16 @@ mod tests {
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)] [DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
}); });
// Park the cursor before the first match and ensure that going to the previous match // Park the cursor before the first match and ensure that going to the previous match
// selects the last match. // selects the last match.
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)], cx); editor.select_display_ranges(&[DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)], cx);
}); });
search_bar.update(&mut cx, |search_bar, cx| { search_bar.update(cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(0)); assert_eq!(search_bar.active_match_index, Some(0));
search_bar.select_match(&SelectMatch(Direction::Prev), cx); search_bar.select_match(&SelectMatch(Direction::Prev), cx);
assert_eq!( assert_eq!(
@ -815,7 +815,7 @@ mod tests {
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)] [DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
); );
}); });
search_bar.read_with(&cx, |search_bar, _| { search_bar.read_with(cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2)); assert_eq!(search_bar.active_match_index, Some(2));
}); });
} }

View File

@ -714,7 +714,7 @@ mod tests {
use std::sync::Arc; use std::sync::Arc;
#[gpui::test] #[gpui::test]
async fn test_project_search(mut cx: TestAppContext) { async fn test_project_search(cx: &mut TestAppContext) {
let fonts = cx.font_cache(); let fonts = cx.font_cache();
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default()); let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
theme.search.match_background = Color::red(); theme.search.match_background = Color::red();
@ -732,9 +732,9 @@ mod tests {
}), }),
) )
.await; .await;
let project = Project::test(fs.clone(), &mut cx); let project = Project::test(fs.clone(), cx);
let (tree, _) = project let (tree, _) = project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir", false, cx) project.find_or_create_local_worktree("/dir", false, cx)
}) })
.await .await
@ -747,14 +747,14 @@ mod tests {
ProjectSearchView::new(search.clone(), None, settings, cx) ProjectSearchView::new(search.clone(), None, settings, cx)
}); });
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
search_view search_view
.query_editor .query_editor
.update(cx, |query_editor, cx| query_editor.set_text("TWO", cx)); .update(cx, |query_editor, cx| query_editor.set_text("TWO", cx));
search_view.search(&Search, cx); search_view.search(&Search, cx);
}); });
search_view.next_notification(&cx).await; search_view.next_notification(&cx).await;
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
assert_eq!( assert_eq!(
search_view search_view
.results_editor .results_editor
@ -791,7 +791,7 @@ mod tests {
search_view.select_match(&SelectMatch(Direction::Next), cx); search_view.select_match(&SelectMatch(Direction::Next), cx);
}); });
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(1)); assert_eq!(search_view.active_match_index, Some(1));
assert_eq!( assert_eq!(
search_view search_view
@ -802,7 +802,7 @@ mod tests {
search_view.select_match(&SelectMatch(Direction::Next), cx); search_view.select_match(&SelectMatch(Direction::Next), cx);
}); });
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(2)); assert_eq!(search_view.active_match_index, Some(2));
assert_eq!( assert_eq!(
search_view search_view
@ -813,7 +813,7 @@ mod tests {
search_view.select_match(&SelectMatch(Direction::Next), cx); search_view.select_match(&SelectMatch(Direction::Next), cx);
}); });
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(0)); assert_eq!(search_view.active_match_index, Some(0));
assert_eq!( assert_eq!(
search_view search_view
@ -824,7 +824,7 @@ mod tests {
search_view.select_match(&SelectMatch(Direction::Prev), cx); search_view.select_match(&SelectMatch(Direction::Prev), cx);
}); });
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(2)); assert_eq!(search_view.active_match_index, Some(2));
assert_eq!( assert_eq!(
search_view search_view
@ -835,7 +835,7 @@ mod tests {
search_view.select_match(&SelectMatch(Direction::Prev), cx); search_view.select_match(&SelectMatch(Direction::Prev), cx);
}); });
search_view.update(&mut cx, |search_view, cx| { search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(1)); assert_eq!(search_view.active_match_index, Some(1));
assert_eq!( assert_eq!(
search_view search_view

View File

@ -627,7 +627,7 @@ pub mod tests {
use util::post_inc; use util::post_inc;
#[gpui::test] #[gpui::test]
async fn test_get_users_by_ids(cx: TestAppContext) { async fn test_get_users_by_ids(cx: &mut TestAppContext) {
for test_db in [TestDb::postgres(), TestDb::fake(cx.background())] { for test_db in [TestDb::postgres(), TestDb::fake(cx.background())] {
let db = test_db.db(); let db = test_db.db();
@ -667,7 +667,7 @@ pub mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_recent_channel_messages(cx: TestAppContext) { async fn test_recent_channel_messages(cx: &mut TestAppContext) {
for test_db in [TestDb::postgres(), TestDb::fake(cx.background())] { for test_db in [TestDb::postgres(), TestDb::fake(cx.background())] {
let db = test_db.db(); let db = test_db.db();
let user = db.create_user("user", false).await.unwrap(); let user = db.create_user("user", false).await.unwrap();
@ -703,7 +703,7 @@ pub mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_channel_message_nonces(cx: TestAppContext) { async fn test_channel_message_nonces(cx: &mut TestAppContext) {
for test_db in [TestDb::postgres(), TestDb::fake(cx.background())] { for test_db in [TestDb::postgres(), TestDb::fake(cx.background())] {
let db = test_db.db(); let db = test_db.db();
let user = db.create_user("user", false).await.unwrap(); let user = db.create_user("user", false).await.unwrap();

File diff suppressed because it is too large Load Diff

View File

@ -152,7 +152,7 @@ mod tests {
}; };
#[gpui::test] #[gpui::test]
async fn test_open_paths_action(mut cx: TestAppContext) { async fn test_open_paths_action(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
let dir = temp_tree(json!({ let dir = temp_tree(json!({
"a": { "a": {
@ -186,7 +186,7 @@ mod tests {
.await; .await;
assert_eq!(cx.window_ids().len(), 1); assert_eq!(cx.window_ids().len(), 1);
let workspace_1 = cx.root_view::<Workspace>(cx.window_ids()[0]).unwrap(); let workspace_1 = cx.root_view::<Workspace>(cx.window_ids()[0]).unwrap();
workspace_1.read_with(&cx, |workspace, cx| { workspace_1.read_with(cx, |workspace, cx| {
assert_eq!(workspace.worktrees(cx).count(), 2) assert_eq!(workspace.worktrees(cx).count(), 2)
}); });
@ -205,7 +205,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_new_empty_workspace(mut cx: TestAppContext) { async fn test_new_empty_workspace(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
cx.update(|cx| { cx.update(|cx| {
workspace::init(cx); workspace::init(cx);
@ -213,7 +213,7 @@ mod tests {
cx.dispatch_global_action(workspace::OpenNew(app_state.clone())); cx.dispatch_global_action(workspace::OpenNew(app_state.clone()));
let window_id = *cx.window_ids().first().unwrap(); let window_id = *cx.window_ids().first().unwrap();
let workspace = cx.root_view::<Workspace>(window_id).unwrap(); let workspace = cx.root_view::<Workspace>(window_id).unwrap();
let editor = workspace.update(&mut cx, |workspace, cx| { let editor = workspace.update(cx, |workspace, cx| {
workspace workspace
.active_item(cx) .active_item(cx)
.unwrap() .unwrap()
@ -221,22 +221,22 @@ mod tests {
.unwrap() .unwrap()
}); });
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert!(editor.text(cx).is_empty()); assert!(editor.text(cx).is_empty());
}); });
let save_task = workspace.update(&mut cx, |workspace, cx| workspace.save_active_item(cx)); let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(cx));
app_state.fs.as_fake().insert_dir("/root").await; app_state.fs.as_fake().insert_dir("/root").await;
cx.simulate_new_path_selection(|_| Some(PathBuf::from("/root/the-new-name"))); cx.simulate_new_path_selection(|_| Some(PathBuf::from("/root/the-new-name")));
save_task.await.unwrap(); save_task.await.unwrap();
editor.read_with(&cx, |editor, cx| { editor.read_with(cx, |editor, cx| {
assert!(!editor.is_dirty(cx)); assert!(!editor.is_dirty(cx));
assert_eq!(editor.title(cx), "the-new-name"); assert_eq!(editor.title(cx), "the-new-name");
}); });
} }
#[gpui::test] #[gpui::test]
async fn test_open_entry(mut cx: TestAppContext) { async fn test_open_entry(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
app_state app_state
.fs .fs
@ -256,7 +256,7 @@ mod tests {
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root", false, cx) project.find_or_create_local_worktree("/root", false, cx)
}) })
.await .await
@ -271,7 +271,7 @@ mod tests {
// Open the first entry // Open the first entry
let entry_1 = workspace let entry_1 = workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx)) .update(cx, |w, cx| w.open_path(file1.clone(), cx))
.await .await
.unwrap(); .unwrap();
cx.read(|cx| { cx.read(|cx| {
@ -285,7 +285,7 @@ mod tests {
// Open the second entry // Open the second entry
workspace workspace
.update(&mut cx, |w, cx| w.open_path(file2.clone(), cx)) .update(cx, |w, cx| w.open_path(file2.clone(), cx))
.await .await
.unwrap(); .unwrap();
cx.read(|cx| { cx.read(|cx| {
@ -299,7 +299,7 @@ mod tests {
// Open the first entry again. The existing pane item is activated. // Open the first entry again. The existing pane item is activated.
let entry_1b = workspace let entry_1b = workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx)) .update(cx, |w, cx| w.open_path(file1.clone(), cx))
.await .await
.unwrap(); .unwrap();
assert_eq!(entry_1.id(), entry_1b.id()); assert_eq!(entry_1.id(), entry_1b.id());
@ -315,14 +315,14 @@ mod tests {
// Split the pane with the first entry, then open the second entry again. // Split the pane with the first entry, then open the second entry again.
workspace workspace
.update(&mut cx, |w, cx| { .update(cx, |w, cx| {
w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx); w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx);
w.open_path(file2.clone(), cx) w.open_path(file2.clone(), cx)
}) })
.await .await
.unwrap(); .unwrap();
workspace.read_with(&cx, |w, cx| { workspace.read_with(cx, |w, cx| {
assert_eq!( assert_eq!(
w.active_pane() w.active_pane()
.read(cx) .read(cx)
@ -334,7 +334,7 @@ mod tests {
}); });
// Open the third entry twice concurrently. Only one pane item is added. // Open the third entry twice concurrently. Only one pane item is added.
let (t1, t2) = workspace.update(&mut cx, |w, cx| { let (t1, t2) = workspace.update(cx, |w, cx| {
( (
w.open_path(file3.clone(), cx), w.open_path(file3.clone(), cx),
w.open_path(file3.clone(), cx), w.open_path(file3.clone(), cx),
@ -357,7 +357,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_open_paths(mut cx: TestAppContext) { async fn test_open_paths(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
let fs = app_state.fs.as_fake(); let fs = app_state.fs.as_fake();
fs.insert_dir("/dir1").await; fs.insert_dir("/dir1").await;
@ -369,7 +369,7 @@ mod tests {
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/dir1", false, cx) project.find_or_create_local_worktree("/dir1", false, cx)
}) })
.await .await
@ -435,7 +435,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_save_conflicting_item(mut cx: TestAppContext) { async fn test_save_conflicting_item(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
let fs = app_state.fs.as_fake(); let fs = app_state.fs.as_fake();
fs.insert_tree("/root", json!({ "a.txt": "" })).await; fs.insert_tree("/root", json!({ "a.txt": "" })).await;
@ -444,7 +444,7 @@ mod tests {
let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root", false, cx) project.find_or_create_local_worktree("/root", false, cx)
}) })
.await .await
@ -474,24 +474,24 @@ mod tests {
.await; .await;
cx.read(|cx| assert!(editor.is_dirty(cx))); cx.read(|cx| assert!(editor.is_dirty(cx)));
let save_task = workspace.update(&mut cx, |workspace, cx| workspace.save_active_item(cx)); let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(cx));
cx.simulate_prompt_answer(window_id, 0); cx.simulate_prompt_answer(window_id, 0);
save_task.await.unwrap(); save_task.await.unwrap();
editor.read_with(&cx, |editor, cx| { editor.read_with(cx, |editor, cx| {
assert!(!editor.is_dirty(cx)); assert!(!editor.is_dirty(cx));
assert!(!editor.has_conflict(cx)); assert!(!editor.has_conflict(cx));
}); });
} }
#[gpui::test] #[gpui::test]
async fn test_open_and_save_new_file(mut cx: TestAppContext) { async fn test_open_and_save_new_file(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
app_state.fs.as_fake().insert_dir("/root").await; app_state.fs.as_fake().insert_dir("/root").await;
let params = cx.update(|cx| WorkspaceParams::local(&app_state, cx)); let params = cx.update(|cx| WorkspaceParams::local(&app_state, cx));
let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root", false, cx) project.find_or_create_local_worktree("/root", false, cx)
}) })
.await .await
@ -500,7 +500,7 @@ mod tests {
// Create a new untitled buffer // Create a new untitled buffer
cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone()));
let editor = workspace.read_with(&cx, |workspace, cx| { let editor = workspace.read_with(cx, |workspace, cx| {
workspace workspace
.active_item(cx) .active_item(cx)
.unwrap() .unwrap()
@ -508,7 +508,7 @@ mod tests {
.unwrap() .unwrap()
}); });
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert!(!editor.is_dirty(cx)); assert!(!editor.is_dirty(cx));
assert_eq!(editor.title(cx), "untitled"); assert_eq!(editor.title(cx), "untitled");
assert!(Arc::ptr_eq( assert!(Arc::ptr_eq(
@ -520,7 +520,7 @@ mod tests {
}); });
// Save the buffer. This prompts for a filename. // Save the buffer. This prompts for a filename.
let save_task = workspace.update(&mut cx, |workspace, cx| workspace.save_active_item(cx)); let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(cx));
cx.simulate_new_path_selection(|parent_dir| { cx.simulate_new_path_selection(|parent_dir| {
assert_eq!(parent_dir, Path::new("/root")); assert_eq!(parent_dir, Path::new("/root"));
Some(parent_dir.join("the-new-name.rs")) Some(parent_dir.join("the-new-name.rs"))
@ -533,21 +533,21 @@ mod tests {
// When the save completes, the buffer's title is updated and the language is assigned based // When the save completes, the buffer's title is updated and the language is assigned based
// on the path. // on the path.
save_task.await.unwrap(); save_task.await.unwrap();
editor.read_with(&cx, |editor, cx| { editor.read_with(cx, |editor, cx| {
assert!(!editor.is_dirty(cx)); assert!(!editor.is_dirty(cx));
assert_eq!(editor.title(cx), "the-new-name.rs"); assert_eq!(editor.title(cx), "the-new-name.rs");
assert_eq!(editor.language(cx).unwrap().name().as_ref(), "Rust"); assert_eq!(editor.language(cx).unwrap().name().as_ref(), "Rust");
}); });
// Edit the file and save it again. This time, there is no filename prompt. // Edit the file and save it again. This time, there is no filename prompt.
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.handle_input(&editor::Input(" there".into()), cx); editor.handle_input(&editor::Input(" there".into()), cx);
assert_eq!(editor.is_dirty(cx.as_ref()), true); assert_eq!(editor.is_dirty(cx.as_ref()), true);
}); });
let save_task = workspace.update(&mut cx, |workspace, cx| workspace.save_active_item(cx)); let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(cx));
save_task.await.unwrap(); save_task.await.unwrap();
assert!(!cx.did_prompt_for_new_path()); assert!(!cx.did_prompt_for_new_path());
editor.read_with(&cx, |editor, cx| { editor.read_with(cx, |editor, cx| {
assert!(!editor.is_dirty(cx)); assert!(!editor.is_dirty(cx));
assert_eq!(editor.title(cx), "the-new-name.rs") assert_eq!(editor.title(cx), "the-new-name.rs")
}); });
@ -556,7 +556,7 @@ mod tests {
// the same buffer. // the same buffer.
cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone()));
workspace workspace
.update(&mut cx, |workspace, cx| { .update(cx, |workspace, cx| {
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
workspace.open_path( workspace.open_path(
ProjectPath { ProjectPath {
@ -568,7 +568,7 @@ mod tests {
}) })
.await .await
.unwrap(); .unwrap();
let editor2 = workspace.update(&mut cx, |workspace, cx| { let editor2 = workspace.update(cx, |workspace, cx| {
workspace workspace
.active_item(cx) .active_item(cx)
.unwrap() .unwrap()
@ -584,7 +584,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_setting_language_when_saving_as_single_file_worktree(mut cx: TestAppContext) { async fn test_setting_language_when_saving_as_single_file_worktree(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
app_state.fs.as_fake().insert_dir("/root").await; app_state.fs.as_fake().insert_dir("/root").await;
let params = cx.update(|cx| WorkspaceParams::local(&app_state, cx)); let params = cx.update(|cx| WorkspaceParams::local(&app_state, cx));
@ -592,7 +592,7 @@ mod tests {
// Create a new untitled buffer // Create a new untitled buffer
cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone()));
let editor = workspace.read_with(&cx, |workspace, cx| { let editor = workspace.read_with(cx, |workspace, cx| {
workspace workspace
.active_item(cx) .active_item(cx)
.unwrap() .unwrap()
@ -600,7 +600,7 @@ mod tests {
.unwrap() .unwrap()
}); });
editor.update(&mut cx, |editor, cx| { editor.update(cx, |editor, cx| {
assert!(Arc::ptr_eq( assert!(Arc::ptr_eq(
editor.language(cx).unwrap(), editor.language(cx).unwrap(),
&language::PLAIN_TEXT &language::PLAIN_TEXT
@ -610,18 +610,18 @@ mod tests {
}); });
// Save the buffer. This prompts for a filename. // Save the buffer. This prompts for a filename.
let save_task = workspace.update(&mut cx, |workspace, cx| workspace.save_active_item(cx)); let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(cx));
cx.simulate_new_path_selection(|_| Some(PathBuf::from("/root/the-new-name.rs"))); cx.simulate_new_path_selection(|_| Some(PathBuf::from("/root/the-new-name.rs")));
save_task.await.unwrap(); save_task.await.unwrap();
// The buffer is not dirty anymore and the language is assigned based on the path. // The buffer is not dirty anymore and the language is assigned based on the path.
editor.read_with(&cx, |editor, cx| { editor.read_with(cx, |editor, cx| {
assert!(!editor.is_dirty(cx)); assert!(!editor.is_dirty(cx));
assert_eq!(editor.language(cx).unwrap().name().as_ref(), "Rust") assert_eq!(editor.language(cx).unwrap().name().as_ref(), "Rust")
}); });
} }
#[gpui::test] #[gpui::test]
async fn test_pane_actions(mut cx: TestAppContext) { async fn test_pane_actions(cx: &mut TestAppContext) {
cx.update(|cx| pane::init(cx)); cx.update(|cx| pane::init(cx));
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
app_state app_state
@ -643,7 +643,7 @@ mod tests {
let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root", false, cx) project.find_or_create_local_worktree("/root", false, cx)
}) })
.await .await
@ -656,7 +656,7 @@ mod tests {
let pane_1 = cx.read(|cx| workspace.read(cx).active_pane().clone()); let pane_1 = cx.read(|cx| workspace.read(cx).active_pane().clone());
workspace workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx)) .update(cx, |w, cx| w.open_path(file1.clone(), cx))
.await .await
.unwrap(); .unwrap();
cx.read(|cx| { cx.read(|cx| {
@ -686,7 +686,7 @@ mod tests {
} }
#[gpui::test] #[gpui::test]
async fn test_navigation(mut cx: TestAppContext) { async fn test_navigation(cx: &mut TestAppContext) {
let app_state = cx.update(test_app_state); let app_state = cx.update(test_app_state);
app_state app_state
.fs .fs
@ -706,7 +706,7 @@ mod tests {
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx)); let (_, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
params params
.project .project
.update(&mut cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree("/root", false, cx) project.find_or_create_local_worktree("/root", false, cx)
}) })
.await .await
@ -719,110 +719,94 @@ mod tests {
let file3 = entries[2].clone(); let file3 = entries[2].clone();
let editor1 = workspace let editor1 = workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx)) .update(cx, |w, cx| w.open_path(file1.clone(), cx))
.await .await
.unwrap() .unwrap()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap(); .unwrap();
editor1.update(&mut cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(10, 0)..DisplayPoint::new(10, 0)], cx); editor.select_display_ranges(&[DisplayPoint::new(10, 0)..DisplayPoint::new(10, 0)], cx);
}); });
let editor2 = workspace let editor2 = workspace
.update(&mut cx, |w, cx| w.open_path(file2.clone(), cx)) .update(cx, |w, cx| w.open_path(file2.clone(), cx))
.await .await
.unwrap() .unwrap()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap(); .unwrap();
let editor3 = workspace let editor3 = workspace
.update(&mut cx, |w, cx| w.open_path(file3.clone(), cx)) .update(cx, |w, cx| w.open_path(file3.clone(), cx))
.await .await
.unwrap() .unwrap()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap(); .unwrap();
editor3.update(&mut cx, |editor, cx| { editor3.update(cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(15, 0)..DisplayPoint::new(15, 0)], cx); editor.select_display_ranges(&[DisplayPoint::new(15, 0)..DisplayPoint::new(15, 0)], cx);
}); });
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file3.clone(), DisplayPoint::new(15, 0)) (file3.clone(), DisplayPoint::new(15, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_back(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_back(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file3.clone(), DisplayPoint::new(0, 0)) (file3.clone(), DisplayPoint::new(0, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_back(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_back(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file2.clone(), DisplayPoint::new(0, 0)) (file2.clone(), DisplayPoint::new(0, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_back(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_back(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file1.clone(), DisplayPoint::new(10, 0)) (file1.clone(), DisplayPoint::new(10, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_back(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_back(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file1.clone(), DisplayPoint::new(0, 0)) (file1.clone(), DisplayPoint::new(0, 0))
); );
// Go back one more time and ensure we don't navigate past the first item in the history. // Go back one more time and ensure we don't navigate past the first item in the history.
workspace workspace.update(cx, |w, cx| Pane::go_back(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_back(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file1.clone(), DisplayPoint::new(0, 0)) (file1.clone(), DisplayPoint::new(0, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_forward(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_forward(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file1.clone(), DisplayPoint::new(10, 0)) (file1.clone(), DisplayPoint::new(10, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_forward(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_forward(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file2.clone(), DisplayPoint::new(0, 0)) (file2.clone(), DisplayPoint::new(0, 0))
); );
// Go forward to an item that has been closed, ensuring it gets re-opened at the same // Go forward to an item that has been closed, ensuring it gets re-opened at the same
// location. // location.
workspace.update(&mut cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
workspace workspace
.active_pane() .active_pane()
.update(cx, |pane, cx| pane.close_item(editor3.id(), cx)); .update(cx, |pane, cx| pane.close_item(editor3.id(), cx));
drop(editor3); drop(editor3);
}); });
workspace workspace.update(cx, |w, cx| Pane::go_forward(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_forward(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file3.clone(), DisplayPoint::new(0, 0)) (file3.clone(), DisplayPoint::new(0, 0))
); );
// Go back to an item that has been closed and removed from disk, ensuring it gets skipped. // Go back to an item that has been closed and removed from disk, ensuring it gets skipped.
workspace workspace
.update(&mut cx, |workspace, cx| { .update(cx, |workspace, cx| {
workspace workspace
.active_pane() .active_pane()
.update(cx, |pane, cx| pane.close_item(editor2.id(), cx)); .update(cx, |pane, cx| pane.close_item(editor2.id(), cx));
@ -834,18 +818,14 @@ mod tests {
}) })
.await .await
.unwrap(); .unwrap();
workspace workspace.update(cx, |w, cx| Pane::go_back(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_back(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file1.clone(), DisplayPoint::new(10, 0)) (file1.clone(), DisplayPoint::new(10, 0))
); );
workspace workspace.update(cx, |w, cx| Pane::go_forward(w, cx)).await;
.update(&mut cx, |w, cx| Pane::go_forward(w, cx))
.await;
assert_eq!( assert_eq!(
active_location(&workspace, &mut cx), active_location(&workspace, cx),
(file3.clone(), DisplayPoint::new(0, 0)) (file3.clone(), DisplayPoint::new(0, 0))
); );