Add remove channel method

Move test client fields into appstate and fix tests

Co-authored-by: max <max@zed.dev>
This commit is contained in:
Mikayla Maki 2023-08-01 16:06:21 -07:00
parent 56d4d5d1a8
commit 74437b3988
No known key found for this signature in database
15 changed files with 534 additions and 256 deletions

View file

@ -19,14 +19,14 @@ async fn test_basic_channels(
let client_b = server.create_client(cx_b, "user_b").await;
let channel_a_id = client_a
.channel_store
.channel_store()
.update(cx_a, |channel_store, _| {
channel_store.create_channel("channel-a", None)
})
.await
.unwrap();
client_a.channel_store.read_with(cx_a, |channels, _| {
client_a.channel_store().read_with(cx_a, |channels, _| {
assert_eq!(
channels.channels(),
&[Arc::new(Channel {
@ -39,12 +39,12 @@ async fn test_basic_channels(
});
client_b
.channel_store
.channel_store()
.read_with(cx_b, |channels, _| assert_eq!(channels.channels(), &[]));
// Invite client B to channel A as client A.
client_a
.channel_store
.channel_store()
.update(cx_a, |channel_store, _| {
channel_store.invite_member(channel_a_id, client_b.user_id().unwrap(), false)
})
@ -54,7 +54,7 @@ async fn test_basic_channels(
// Wait for client b to see the invitation
deterministic.run_until_parked();
client_b.channel_store.read_with(cx_b, |channels, _| {
client_b.channel_store().read_with(cx_b, |channels, _| {
assert_eq!(
channels.channel_invitations(),
&[Arc::new(Channel {
@ -68,13 +68,13 @@ async fn test_basic_channels(
// Client B now sees that they are in channel A.
client_b
.channel_store
.channel_store()
.update(cx_b, |channels, _| {
channels.respond_to_channel_invite(channel_a_id, true)
})
.await
.unwrap();
client_b.channel_store.read_with(cx_b, |channels, _| {
client_b.channel_store().read_with(cx_b, |channels, _| {
assert_eq!(channels.channel_invitations(), &[]);
assert_eq!(
channels.channels(),
@ -86,6 +86,23 @@ async fn test_basic_channels(
})]
)
});
// Client A deletes the channel
client_a
.channel_store()
.update(cx_a, |channel_store, _| {
channel_store.remove_channel(channel_a_id)
})
.await
.unwrap();
deterministic.run_until_parked();
client_a
.channel_store()
.read_with(cx_a, |channels, _| assert_eq!(channels.channels(), &[]));
client_b
.channel_store()
.read_with(cx_b, |channels, _| assert_eq!(channels.channels(), &[]));
}
#[gpui::test]

View file

@ -749,7 +749,7 @@ async fn test_server_restarts(
let mut server = TestServer::start(&deterministic).await;
let client_a = server.create_client(cx_a, "user_a").await;
client_a
.fs
.fs()
.insert_tree("/a", json!({ "a.txt": "a-contents" }))
.await;
@ -1221,7 +1221,7 @@ async fn test_share_project(
let active_call_c = cx_c.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -1388,7 +1388,7 @@ async fn test_unshare_project(
let active_call_b = cx_b.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -1477,7 +1477,7 @@ async fn test_host_disconnect(
cx_b.update(editor::init);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -1500,7 +1500,7 @@ async fn test_host_disconnect(
assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
let (window_id_b, workspace_b) =
cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));
cx_b.add_window(|cx| Workspace::new(0, project_b.clone(), client_b.app_state.clone(), cx));
let editor_b = workspace_b
.update(cx_b, |workspace, cx| {
workspace.open_path((worktree_id, "b.txt"), None, true, cx)
@ -1584,7 +1584,7 @@ async fn test_project_reconnect(
cx_b.update(editor::init);
client_a
.fs
.fs()
.insert_tree(
"/root-1",
json!({
@ -1612,7 +1612,7 @@ async fn test_project_reconnect(
)
.await;
client_a
.fs
.fs()
.insert_tree(
"/root-2",
json!({
@ -1621,7 +1621,7 @@ async fn test_project_reconnect(
)
.await;
client_a
.fs
.fs()
.insert_tree(
"/root-3",
json!({
@ -1701,7 +1701,7 @@ async fn test_project_reconnect(
// While client A is disconnected, add and remove files from client A's project.
client_a
.fs
.fs()
.insert_tree(
"/root-1/dir1/subdir2",
json!({
@ -1713,7 +1713,7 @@ async fn test_project_reconnect(
)
.await;
client_a
.fs
.fs()
.remove_dir(
"/root-1/dir1/subdir1".as_ref(),
RemoveOptions {
@ -1835,11 +1835,11 @@ async fn test_project_reconnect(
// While client B is disconnected, add and remove files from client A's project
client_a
.fs
.fs()
.insert_file("/root-1/dir1/subdir2/j.txt", "j-contents".into())
.await;
client_a
.fs
.fs()
.remove_file("/root-1/dir1/subdir2/i.txt".as_ref(), Default::default())
.await
.unwrap();
@ -1925,8 +1925,8 @@ async fn test_active_call_events(
let mut server = TestServer::start(&deterministic).await;
let client_a = server.create_client(cx_a, "user_a").await;
let client_b = server.create_client(cx_b, "user_b").await;
client_a.fs.insert_tree("/a", json!({})).await;
client_b.fs.insert_tree("/b", json!({})).await;
client_a.fs().insert_tree("/a", json!({})).await;
client_b.fs().insert_tree("/b", json!({})).await;
let (project_a, _) = client_a.build_local_project("/a", cx_a).await;
let (project_b, _) = client_b.build_local_project("/b", cx_b).await;
@ -2014,8 +2014,8 @@ async fn test_room_location(
let mut server = TestServer::start(&deterministic).await;
let client_a = server.create_client(cx_a, "user_a").await;
let client_b = server.create_client(cx_b, "user_b").await;
client_a.fs.insert_tree("/a", json!({})).await;
client_b.fs.insert_tree("/b", json!({})).await;
client_a.fs().insert_tree("/a", json!({})).await;
client_b.fs().insert_tree("/b", json!({})).await;
let active_call_a = cx_a.read(ActiveCall::global);
let active_call_b = cx_b.read(ActiveCall::global);
@ -2204,12 +2204,12 @@ async fn test_propagate_saves_and_fs_changes(
Some(tree_sitter_rust::language()),
));
for client in [&client_a, &client_b, &client_c] {
client.language_registry.add(rust.clone());
client.language_registry.add(javascript.clone());
client.language_registry().add(rust.clone());
client.language_registry().add(javascript.clone());
}
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -2279,7 +2279,7 @@ async fn test_propagate_saves_and_fs_changes(
buffer_a.update(cx_a, |buf, cx| buf.edit([(0..0, "hi-a, ")], None, cx));
save_b.await.unwrap();
assert_eq!(
client_a.fs.load("/a/file1.rs".as_ref()).await.unwrap(),
client_a.fs().load("/a/file1.rs".as_ref()).await.unwrap(),
"hi-a, i-am-c, i-am-b, i-am-a"
);
@ -2290,7 +2290,7 @@ async fn test_propagate_saves_and_fs_changes(
// Make changes on host's file system, see those changes on guest worktrees.
client_a
.fs
.fs()
.rename(
"/a/file1.rs".as_ref(),
"/a/file1.js".as_ref(),
@ -2299,11 +2299,11 @@ async fn test_propagate_saves_and_fs_changes(
.await
.unwrap();
client_a
.fs
.fs()
.rename("/a/file2".as_ref(), "/a/file3".as_ref(), Default::default())
.await
.unwrap();
client_a.fs.insert_file("/a/file4", "4".into()).await;
client_a.fs().insert_file("/a/file4", "4".into()).await;
deterministic.run_until_parked();
worktree_a.read_with(cx_a, |tree, _| {
@ -2397,7 +2397,7 @@ async fn test_git_diff_base_change(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -2441,7 +2441,7 @@ async fn test_git_diff_base_change(
"
.unindent();
client_a.fs.as_fake().set_index_for_repo(
client_a.fs().set_index_for_repo(
Path::new("/dir/.git"),
&[(Path::new("a.txt"), diff_base.clone())],
);
@ -2486,7 +2486,7 @@ async fn test_git_diff_base_change(
);
});
client_a.fs.as_fake().set_index_for_repo(
client_a.fs().set_index_for_repo(
Path::new("/dir/.git"),
&[(Path::new("a.txt"), new_diff_base.clone())],
);
@ -2531,7 +2531,7 @@ async fn test_git_diff_base_change(
"
.unindent();
client_a.fs.as_fake().set_index_for_repo(
client_a.fs().set_index_for_repo(
Path::new("/dir/sub/.git"),
&[(Path::new("b.txt"), diff_base.clone())],
);
@ -2576,7 +2576,7 @@ async fn test_git_diff_base_change(
);
});
client_a.fs.as_fake().set_index_for_repo(
client_a.fs().set_index_for_repo(
Path::new("/dir/sub/.git"),
&[(Path::new("b.txt"), new_diff_base.clone())],
);
@ -2635,7 +2635,7 @@ async fn test_git_branch_name(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -2654,8 +2654,7 @@ async fn test_git_branch_name(
let project_remote = client_b.build_remote_project(project_id, cx_b).await;
client_a
.fs
.as_fake()
.fs()
.set_branch_name(Path::new("/dir/.git"), Some("branch-1"));
// Wait for it to catch up to the new branch
@ -2680,8 +2679,7 @@ async fn test_git_branch_name(
});
client_a
.fs
.as_fake()
.fs()
.set_branch_name(Path::new("/dir/.git"), Some("branch-2"));
// Wait for buffer_local_a to receive it
@ -2720,7 +2718,7 @@ async fn test_git_status_sync(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -2734,7 +2732,7 @@ async fn test_git_status_sync(
const A_TXT: &'static str = "a.txt";
const B_TXT: &'static str = "b.txt";
client_a.fs.as_fake().set_status_for_repo_via_git_operation(
client_a.fs().set_status_for_repo_via_git_operation(
Path::new("/dir/.git"),
&[
(&Path::new(A_TXT), GitFileStatus::Added),
@ -2780,16 +2778,13 @@ async fn test_git_status_sync(
assert_status(&Path::new(B_TXT), Some(GitFileStatus::Added), project, cx);
});
client_a
.fs
.as_fake()
.set_status_for_repo_via_working_copy_change(
Path::new("/dir/.git"),
&[
(&Path::new(A_TXT), GitFileStatus::Modified),
(&Path::new(B_TXT), GitFileStatus::Modified),
],
);
client_a.fs().set_status_for_repo_via_working_copy_change(
Path::new("/dir/.git"),
&[
(&Path::new(A_TXT), GitFileStatus::Modified),
(&Path::new(B_TXT), GitFileStatus::Modified),
],
);
// Wait for buffer_local_a to receive it
deterministic.run_until_parked();
@ -2860,7 +2855,7 @@ async fn test_fs_operations(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -3133,7 +3128,7 @@ async fn test_local_settings(
// As client A, open a project that contains some local settings files
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -3175,7 +3170,7 @@ async fn test_local_settings(
// As client A, update a settings file. As Client B, see the changed settings.
client_a
.fs
.fs()
.insert_file("/dir/.zed/settings.json", r#"{}"#.into())
.await;
deterministic.run_until_parked();
@ -3192,17 +3187,17 @@ async fn test_local_settings(
// As client A, create and remove some settings files. As client B, see the changed settings.
client_a
.fs
.fs()
.remove_file("/dir/.zed/settings.json".as_ref(), Default::default())
.await
.unwrap();
client_a
.fs
.fs()
.create_dir("/dir/b/.zed".as_ref())
.await
.unwrap();
client_a
.fs
.fs()
.insert_file("/dir/b/.zed/settings.json", r#"{"tab_size": 4}"#.into())
.await;
deterministic.run_until_parked();
@ -3223,11 +3218,11 @@ async fn test_local_settings(
// As client A, change and remove settings files while client B is disconnected.
client_a
.fs
.fs()
.insert_file("/dir/a/.zed/settings.json", r#"{"hard_tabs":true}"#.into())
.await;
client_a
.fs
.fs()
.remove_file("/dir/b/.zed/settings.json".as_ref(), Default::default())
.await
.unwrap();
@ -3261,7 +3256,7 @@ async fn test_buffer_conflict_after_save(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -3323,7 +3318,7 @@ async fn test_buffer_reloading(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -3351,7 +3346,7 @@ async fn test_buffer_reloading(
let new_contents = Rope::from("d\ne\nf");
client_a
.fs
.fs()
.save("/dir/a.txt".as_ref(), &new_contents, LineEnding::Windows)
.await
.unwrap();
@ -3380,7 +3375,7 @@ async fn test_editing_while_guest_opens_buffer(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree("/dir", json!({ "a.txt": "a-contents" }))
.await;
let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await;
@ -3429,7 +3424,7 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree("/dir", json!({ "a.txt": "Some text\n" }))
.await;
let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await;
@ -3527,7 +3522,7 @@ async fn test_leaving_worktree_while_opening_buffer(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree("/dir", json!({ "a.txt": "a-contents" }))
.await;
let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await;
@ -3570,7 +3565,7 @@ async fn test_canceling_buffer_opening(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -3626,7 +3621,7 @@ async fn test_leaving_project(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -3714,9 +3709,9 @@ async fn test_leaving_project(
cx_b.spawn(|cx| {
Project::remote(
project_id,
client_b.client.clone(),
client_b.user_store.clone(),
client_b.language_registry.clone(),
client_b.app_state.client.clone(),
client_b.user_store().clone(),
client_b.language_registry().clone(),
FakeFs::new(cx.background()),
cx,
)
@ -3768,11 +3763,11 @@ async fn test_collaborating_with_diagnostics(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
// Share a project as client A
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -4040,11 +4035,11 @@ async fn test_collaborating_with_lsp_progress_updates_and_diagnostics_ordering(
..Default::default()
}))
.await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
let file_names = &["one.rs", "two.rs", "three.rs", "four.rs", "five.rs"];
client_a
.fs
.fs()
.insert_tree(
"/test",
json!({
@ -4181,10 +4176,10 @@ async fn test_collaborating_with_completion(
..Default::default()
}))
.await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -4342,7 +4337,7 @@ async fn test_reloading_buffer_manually(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree("/a", json!({ "a.rs": "let one = 1;" }))
.await;
let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await;
@ -4373,7 +4368,7 @@ async fn test_reloading_buffer_manually(
buffer_a.read_with(cx_a, |buffer, _| assert_eq!(buffer.text(), "let six = 6;"));
client_a
.fs
.fs()
.save(
"/a/a.rs".as_ref(),
&Rope::from("let seven = 7;"),
@ -4444,14 +4439,14 @@ async fn test_formatting_buffer(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
// Here we insert a fake tree with a directory that exists on disk. This is needed
// because later we'll invoke a command, which requires passing a working directory
// that points to a valid location on disk.
let directory = env::current_dir().unwrap();
client_a
.fs
.fs()
.insert_tree(&directory, json!({ "a.rs": "let one = \"two\"" }))
.await;
let (project_a, worktree_id) = client_a.build_local_project(&directory, cx_a).await;
@ -4553,10 +4548,10 @@ async fn test_definition(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/root",
json!({
@ -4701,10 +4696,10 @@ async fn test_references(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/root",
json!({
@ -4797,7 +4792,7 @@ async fn test_project_search(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/root",
json!({
@ -4883,7 +4878,7 @@ async fn test_document_highlights(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/root-1",
json!({
@ -4902,7 +4897,7 @@ async fn test_document_highlights(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
let (project_a, worktree_id) = client_a.build_local_project("/root-1", cx_a).await;
let project_id = active_call_a
@ -4989,7 +4984,7 @@ async fn test_lsp_hover(
let active_call_a = cx_a.read(ActiveCall::global);
client_a
.fs
.fs()
.insert_tree(
"/root-1",
json!({
@ -5008,7 +5003,7 @@ async fn test_lsp_hover(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
let (project_a, worktree_id) = client_a.build_local_project("/root-1", cx_a).await;
let project_id = active_call_a
@ -5107,10 +5102,10 @@ async fn test_project_symbols(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/code",
json!({
@ -5218,10 +5213,10 @@ async fn test_open_buffer_while_getting_definition_pointing_to_it(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/root",
json!({
@ -5278,6 +5273,7 @@ async fn test_collaborating_with_code_actions(
deterministic.forbid_parking();
let mut server = TestServer::start(&deterministic).await;
let client_a = server.create_client(cx_a, "user_a").await;
//
let client_b = server.create_client(cx_b, "user_b").await;
server
.create_room(&mut [(&client_a, cx_a), (&client_b, cx_b)])
@ -5296,10 +5292,10 @@ async fn test_collaborating_with_code_actions(
Some(tree_sitter_rust::language()),
);
let mut fake_language_servers = language.set_fake_lsp_adapter(Default::default()).await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -5316,7 +5312,8 @@ async fn test_collaborating_with_code_actions(
// Join the project as client B.
let project_b = client_b.build_remote_project(project_id, cx_b).await;
let (_window_b, workspace_b) = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));
let (_window_b, workspace_b) =
cx_b.add_window(|cx| Workspace::new(0, project_b.clone(), client_b.app_state.clone(), cx));
let editor_b = workspace_b
.update(cx_b, |workspace, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, cx)
@ -5521,10 +5518,10 @@ async fn test_collaborating_with_renames(
..Default::default()
}))
.await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -5540,7 +5537,8 @@ async fn test_collaborating_with_renames(
.unwrap();
let project_b = client_b.build_remote_project(project_id, cx_b).await;
let (_window_b, workspace_b) = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));
let (_window_b, workspace_b) =
cx_b.add_window(|cx| Workspace::new(0, project_b.clone(), client_b.app_state.clone(), cx));
let editor_b = workspace_b
.update(cx_b, |workspace, cx| {
workspace.open_path((worktree_id, "one.rs"), None, true, cx)
@ -5706,10 +5704,10 @@ async fn test_language_server_statuses(
..Default::default()
}))
.await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/dir",
json!({
@ -6166,7 +6164,7 @@ async fn test_contacts(
// Test removing a contact
client_b
.user_store
.user_store()
.update(cx_b, |store, cx| {
store.remove_contact(client_c.user_id().unwrap(), cx)
})
@ -6189,7 +6187,7 @@ async fn test_contacts(
client: &TestClient,
cx: &TestAppContext,
) -> Vec<(String, &'static str, &'static str)> {
client.user_store.read_with(cx, |store, _| {
client.user_store().read_with(cx, |store, _| {
store
.contacts()
.iter()
@ -6232,14 +6230,14 @@ async fn test_contact_requests(
// User A and User C request that user B become their contact.
client_a
.user_store
.user_store()
.update(cx_a, |store, cx| {
store.request_contact(client_b.user_id().unwrap(), cx)
})
.await
.unwrap();
client_c
.user_store
.user_store()
.update(cx_c, |store, cx| {
store.request_contact(client_b.user_id().unwrap(), cx)
})
@ -6293,7 +6291,7 @@ async fn test_contact_requests(
// User B accepts the request from user A.
client_b
.user_store
.user_store()
.update(cx_b, |store, cx| {
store.respond_to_contact_request(client_a.user_id().unwrap(), true, cx)
})
@ -6337,7 +6335,7 @@ async fn test_contact_requests(
// User B rejects the request from user C.
client_b
.user_store
.user_store()
.update(cx_b, |store, cx| {
store.respond_to_contact_request(client_c.user_id().unwrap(), false, cx)
})
@ -6419,7 +6417,7 @@ async fn test_basic_following(
cx_b.update(editor::init);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -6980,7 +6978,7 @@ async fn test_join_call_after_screen_was_shared(
.await
.unwrap();
client_b.user_store.update(cx_b, |user_store, _| {
client_b.user_store().update(cx_b, |user_store, _| {
user_store.clear_cache();
});
@ -7040,7 +7038,7 @@ async fn test_following_tab_order(
cx_b.update(editor::init);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -7163,7 +7161,7 @@ async fn test_peers_following_each_other(
// Client A shares a project.
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -7336,7 +7334,7 @@ async fn test_auto_unfollowing(
// Client A shares a project.
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -7500,7 +7498,7 @@ async fn test_peers_simultaneously_following_each_other(
cx_a.update(editor::init);
cx_b.update(editor::init);
client_a.fs.insert_tree("/a", json!({})).await;
client_a.fs().insert_tree("/a", json!({})).await;
let (project_a, _) = client_a.build_local_project("/a", cx_a).await;
let workspace_a = client_a.build_workspace(&project_a, cx_a);
let project_id = active_call_a
@ -7577,10 +7575,10 @@ async fn test_on_input_format_from_host_to_guest(
..Default::default()
}))
.await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -7706,10 +7704,10 @@ async fn test_on_input_format_from_guest_to_host(
..Default::default()
}))
.await;
client_a.language_registry.add(Arc::new(language));
client_a.language_registry().add(Arc::new(language));
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -7862,11 +7860,11 @@ async fn test_mutual_editor_inlay_hint_cache_update(
}))
.await;
let language = Arc::new(language);
client_a.language_registry.add(Arc::clone(&language));
client_b.language_registry.add(language);
client_a.language_registry().add(Arc::clone(&language));
client_b.language_registry().add(language);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({
@ -8169,11 +8167,11 @@ async fn test_inlay_hint_refresh_is_forwarded(
}))
.await;
let language = Arc::new(language);
client_a.language_registry.add(Arc::clone(&language));
client_b.language_registry.add(language);
client_a.language_registry().add(Arc::clone(&language));
client_b.language_registry().add(language);
client_a
.fs
.fs()
.insert_tree(
"/a",
json!({

View file

@ -396,9 +396,9 @@ async fn apply_client_operation(
);
let root_path = Path::new("/").join(&first_root_name);
client.fs.create_dir(&root_path).await.unwrap();
client.fs().create_dir(&root_path).await.unwrap();
client
.fs
.fs()
.create_file(&root_path.join("main.rs"), Default::default())
.await
.unwrap();
@ -422,8 +422,8 @@ async fn apply_client_operation(
);
ensure_project_shared(&project, client, cx).await;
if !client.fs.paths(false).contains(&new_root_path) {
client.fs.create_dir(&new_root_path).await.unwrap();
if !client.fs().paths(false).contains(&new_root_path) {
client.fs().create_dir(&new_root_path).await.unwrap();
}
project
.update(cx, |project, cx| {
@ -475,7 +475,7 @@ async fn apply_client_operation(
Some(room.update(cx, |room, cx| {
room.join_project(
project_id,
client.language_registry.clone(),
client.language_registry().clone(),
FakeFs::new(cx.background().clone()),
cx,
)
@ -743,7 +743,7 @@ async fn apply_client_operation(
content,
} => {
if !client
.fs
.fs()
.directories(false)
.contains(&path.parent().unwrap().to_owned())
{
@ -752,14 +752,14 @@ async fn apply_client_operation(
if is_dir {
log::info!("{}: creating dir at {:?}", client.username, path);
client.fs.create_dir(&path).await.unwrap();
client.fs().create_dir(&path).await.unwrap();
} else {
let exists = client.fs.metadata(&path).await?.is_some();
let exists = client.fs().metadata(&path).await?.is_some();
let verb = if exists { "updating" } else { "creating" };
log::info!("{}: {} file at {:?}", verb, client.username, path);
client
.fs
.fs()
.save(&path, &content.as_str().into(), fs::LineEnding::Unix)
.await
.unwrap();
@ -771,12 +771,12 @@ async fn apply_client_operation(
repo_path,
contents,
} => {
if !client.fs.directories(false).contains(&repo_path) {
if !client.fs().directories(false).contains(&repo_path) {
return Err(TestError::Inapplicable);
}
for (path, _) in contents.iter() {
if !client.fs.files().contains(&repo_path.join(path)) {
if !client.fs().files().contains(&repo_path.join(path)) {
return Err(TestError::Inapplicable);
}
}
@ -793,16 +793,16 @@ async fn apply_client_operation(
.iter()
.map(|(path, contents)| (path.as_path(), contents.clone()))
.collect::<Vec<_>>();
if client.fs.metadata(&dot_git_dir).await?.is_none() {
client.fs.create_dir(&dot_git_dir).await?;
if client.fs().metadata(&dot_git_dir).await?.is_none() {
client.fs().create_dir(&dot_git_dir).await?;
}
client.fs.set_index_for_repo(&dot_git_dir, &contents);
client.fs().set_index_for_repo(&dot_git_dir, &contents);
}
GitOperation::WriteGitBranch {
repo_path,
new_branch,
} => {
if !client.fs.directories(false).contains(&repo_path) {
if !client.fs().directories(false).contains(&repo_path) {
return Err(TestError::Inapplicable);
}
@ -814,21 +814,21 @@ async fn apply_client_operation(
);
let dot_git_dir = repo_path.join(".git");
if client.fs.metadata(&dot_git_dir).await?.is_none() {
client.fs.create_dir(&dot_git_dir).await?;
if client.fs().metadata(&dot_git_dir).await?.is_none() {
client.fs().create_dir(&dot_git_dir).await?;
}
client.fs.set_branch_name(&dot_git_dir, new_branch);
client.fs().set_branch_name(&dot_git_dir, new_branch);
}
GitOperation::WriteGitStatuses {
repo_path,
statuses,
git_operation,
} => {
if !client.fs.directories(false).contains(&repo_path) {
if !client.fs().directories(false).contains(&repo_path) {
return Err(TestError::Inapplicable);
}
for (path, _) in statuses.iter() {
if !client.fs.files().contains(&repo_path.join(path)) {
if !client.fs().files().contains(&repo_path.join(path)) {
return Err(TestError::Inapplicable);
}
}
@ -847,16 +847,16 @@ async fn apply_client_operation(
.map(|(path, val)| (path.as_path(), val.clone()))
.collect::<Vec<_>>();
if client.fs.metadata(&dot_git_dir).await?.is_none() {
client.fs.create_dir(&dot_git_dir).await?;
if client.fs().metadata(&dot_git_dir).await?.is_none() {
client.fs().create_dir(&dot_git_dir).await?;
}
if git_operation {
client
.fs
.fs()
.set_status_for_repo_via_git_operation(&dot_git_dir, statuses.as_slice());
} else {
client.fs.set_status_for_repo_via_working_copy_change(
client.fs().set_status_for_repo_via_working_copy_change(
&dot_git_dir,
statuses.as_slice(),
);
@ -1499,7 +1499,7 @@ impl TestPlan {
// Invite a contact to the current call
0..=70 => {
let available_contacts =
client.user_store.read_with(cx, |user_store, _| {
client.user_store().read_with(cx, |user_store, _| {
user_store
.contacts()
.iter()
@ -1596,7 +1596,7 @@ impl TestPlan {
.choose(&mut self.rng)
.cloned() else { continue };
let project_root_name = root_name_for_project(&project, cx);
let mut paths = client.fs.paths(false);
let mut paths = client.fs().paths(false);
paths.remove(0);
let new_root_path = if paths.is_empty() || self.rng.gen() {
Path::new("/").join(&self.next_root_dir_name(user_id))
@ -1776,7 +1776,7 @@ impl TestPlan {
let is_dir = self.rng.gen::<bool>();
let content;
let mut path;
let dir_paths = client.fs.directories(false);
let dir_paths = client.fs().directories(false);
if is_dir {
content = String::new();
@ -1786,7 +1786,7 @@ impl TestPlan {
content = Alphanumeric.sample_string(&mut self.rng, 16);
// Create a new file or overwrite an existing file
let file_paths = client.fs.files();
let file_paths = client.fs().files();
if file_paths.is_empty() || self.rng.gen_bool(0.5) {
path = dir_paths.choose(&mut self.rng).unwrap().clone();
path.push(gen_file_name(&mut self.rng));
@ -1812,7 +1812,7 @@ impl TestPlan {
client: &TestClient,
) -> Vec<PathBuf> {
let mut paths = client
.fs
.fs()
.files()
.into_iter()
.filter(|path| path.starts_with(repo_path))
@ -1829,7 +1829,7 @@ impl TestPlan {
}
let repo_path = client
.fs
.fs()
.directories(false)
.choose(&mut self.rng)
.unwrap()
@ -1928,7 +1928,7 @@ async fn simulate_client(
name: "the-fake-language-server",
capabilities: lsp::LanguageServer::full_capabilities(),
initializer: Some(Box::new({
let fs = client.fs.clone();
let fs = client.app_state.fs.clone();
move |fake_server: &mut FakeLanguageServer| {
fake_server.handle_request::<lsp::request::Completion, _, _>(
|_, _| async move {
@ -1973,7 +1973,7 @@ async fn simulate_client(
let background = cx.background();
let mut rng = background.rng();
let count = rng.gen_range::<usize, _>(1..3);
let files = fs.files();
let files = fs.as_fake().files();
let files = (0..count)
.map(|_| files.choose(&mut *rng).unwrap().clone())
.collect::<Vec<_>>();
@ -2023,7 +2023,7 @@ async fn simulate_client(
..Default::default()
}))
.await;
client.language_registry.add(Arc::new(language));
client.app_state.languages.add(Arc::new(language));
while let Some(batch_id) = operation_rx.next().await {
let Some((operation, applied)) = plan.lock().next_client_operation(&client, batch_id, &cx) else { break };