From 06960670bdb2d2c82095cecb1eb2f233406c0a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Thu, 27 Mar 2025 20:42:22 +0800 Subject: [PATCH] windows: Enable `collab` tests (#27587) Release Notes: - N/A --- crates/collab/src/tests.rs | 3 - crates/collab/src/tests/editor_tests.rs | 102 +++--- crates/collab/src/tests/following_tests.rs | 25 +- crates/collab/src/tests/git_tests.rs | 9 +- crates/collab/src/tests/integration_tests.rs | 345 ++++++++++-------- .../random_project_collaboration_tests.rs | 6 +- .../remote_editing_collaboration_tests.rs | 16 +- crates/collab/src/tests/test_server.rs | 5 +- 8 files changed, 277 insertions(+), 234 deletions(-) diff --git a/crates/collab/src/tests.rs b/crates/collab/src/tests.rs index 5ec4937168..8a57d07a45 100644 --- a/crates/collab/src/tests.rs +++ b/crates/collab/src/tests.rs @@ -1,6 +1,3 @@ -// todo(windows): Actually run the tests -#![cfg(not(target_os = "windows"))] - use std::sync::Arc; use call::Room; diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index d2bc38be55..6e52e5df84 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -36,6 +36,7 @@ use std::{ }, }; use text::Point; +use util::{path, uri}; use workspace::{CloseIntent, Workspace}; #[gpui::test(iterations = 10)] @@ -190,9 +191,9 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor( client_a .fs() - .insert_tree("/dir", json!({ "a.txt": "Some text\n" })) + .insert_tree(path!("/dir"), json!({ "a.txt": "Some text\n" })) .await; - let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -306,14 +307,14 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "main.rs": "fn main() { a }", "other.rs": "", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -351,7 +352,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu .set_request_handler::(|params, _| async move { assert_eq!( params.text_document_position.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); assert_eq!( params.text_document_position.position, @@ -468,7 +469,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu .set_request_handler::(|params, _| async move { assert_eq!( params.text_document_position.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); assert_eq!( params.text_document_position.position, @@ -562,14 +563,14 @@ async fn test_collaborating_with_code_actions( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "main.rs": "mod other;\nfn main() { let foo = other::foo(); }", "other.rs": "pub fn foo() -> usize { 4 }", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -592,7 +593,7 @@ async fn test_collaborating_with_code_actions( .set_request_handler::(|params, _| async move { assert_eq!( params.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); assert_eq!(params.range.start, lsp::Position::new(0, 0)); assert_eq!(params.range.end, lsp::Position::new(0, 0)); @@ -614,7 +615,7 @@ async fn test_collaborating_with_code_actions( .set_request_handler::(|params, _| async move { assert_eq!( params.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); assert_eq!(params.range.start, lsp::Position::new(1, 31)); assert_eq!(params.range.end, lsp::Position::new(1, 31)); @@ -626,7 +627,7 @@ async fn test_collaborating_with_code_actions( changes: Some( [ ( - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), vec![lsp::TextEdit::new( lsp::Range::new( lsp::Position::new(1, 22), @@ -636,7 +637,7 @@ async fn test_collaborating_with_code_actions( )], ), ( - lsp::Url::from_file_path("/a/other.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/other.rs")).unwrap(), vec![lsp::TextEdit::new( lsp::Range::new( lsp::Position::new(0, 0), @@ -697,7 +698,7 @@ async fn test_collaborating_with_code_actions( changes: Some( [ ( - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), vec![lsp::TextEdit::new( lsp::Range::new( lsp::Position::new(1, 22), @@ -707,7 +708,7 @@ async fn test_collaborating_with_code_actions( )], ), ( - lsp::Url::from_file_path("/a/other.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/other.rs")).unwrap(), vec![lsp::TextEdit::new( lsp::Range::new( lsp::Position::new(0, 0), @@ -780,14 +781,14 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T client_a .fs() .insert_tree( - "/dir", + path!("/dir"), json!({ "one.rs": "const ONE: usize = 1;", "two.rs": "const TWO: usize = one::ONE + one::ONE;" }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -813,7 +814,10 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T fake_language_server .set_request_handler::(|params, _| async move { - assert_eq!(params.text_document.uri.as_str(), "file:///dir/one.rs"); + assert_eq!( + params.text_document.uri.as_str(), + uri!("file:///dir/one.rs") + ); assert_eq!(params.position, lsp::Position::new(0, 7)); Ok(Some(lsp::PrepareRenameResponse::Range(lsp::Range::new( lsp::Position::new(0, 6), @@ -856,7 +860,10 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T fake_language_server .set_request_handler::(|params, _| async move { - assert_eq!(params.text_document.uri.as_str(), "file:///dir/one.rs"); + assert_eq!( + params.text_document.uri.as_str(), + uri!("file:///dir/one.rs") + ); assert_eq!(params.position, lsp::Position::new(0, 8)); Ok(Some(lsp::PrepareRenameResponse::Range(lsp::Range::new( lsp::Position::new(0, 6), @@ -894,7 +901,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T .set_request_handler::(|params, _| async move { assert_eq!( params.text_document_position.text_document.uri.as_str(), - "file:///dir/one.rs" + uri!("file:///dir/one.rs") ); assert_eq!( params.text_document_position.position, @@ -905,14 +912,14 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T changes: Some( [ ( - lsp::Url::from_file_path("/dir/one.rs").unwrap(), + lsp::Url::from_file_path(path!("/dir/one.rs")).unwrap(), vec![lsp::TextEdit::new( lsp::Range::new(lsp::Position::new(0, 6), lsp::Position::new(0, 9)), "THREE".to_string(), )], ), ( - lsp::Url::from_file_path("/dir/two.rs").unwrap(), + lsp::Url::from_file_path(path!("/dir/two.rs")).unwrap(), vec![ lsp::TextEdit::new( lsp::Range::new( @@ -999,17 +1006,17 @@ async fn test_language_server_statuses(cx_a: &mut TestAppContext, cx_b: &mut Tes client_a .fs() .insert_tree( - "/dir", + path!("/dir"), json!({ "main.rs": "const ONE: usize = 1;", }), ) .await; - let (project_a, _) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, _) = client_a.build_local_project(path!("/dir"), cx_a).await; let _buffer_a = project_a .update(cx_a, |p, cx| { - p.open_local_buffer_with_lsp("/dir/main.rs", cx) + p.open_local_buffer_with_lsp(path!("/dir/main.rs"), cx) }) .await .unwrap(); @@ -1106,7 +1113,7 @@ async fn test_share_project( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ ".gitignore": "ignored-dir", "a.txt": "a-contents", @@ -1120,7 +1127,7 @@ async fn test_share_project( .await; // Invite client B to collaborate on a project - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; active_call_a .update(cx_a, |call, cx| { call.invite(client_b.user_id().unwrap(), Some(project_a.clone()), cx) @@ -1292,14 +1299,14 @@ async fn test_on_input_format_from_host_to_guest( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "main.rs": "fn main() { a }", "other.rs": "// Test file", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -1325,7 +1332,7 @@ async fn test_on_input_format_from_host_to_guest( |params, _| async move { assert_eq!( params.text_document_position.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); assert_eq!( params.text_document_position.position, @@ -1414,14 +1421,14 @@ async fn test_on_input_format_from_guest_to_host( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "main.rs": "fn main() { a }", "other.rs": "// Test file", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -1455,7 +1462,7 @@ async fn test_on_input_format_from_guest_to_host( .set_request_handler::(|params, _| async move { assert_eq!( params.text_document_position.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); assert_eq!( params.text_document_position.position, @@ -1575,14 +1582,14 @@ async fn test_mutual_editor_inlay_hint_cache_update( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "main.rs": "fn main() { a } // and some long comment to ensure inlay hints are not trimmed out", "other.rs": "// Test file", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; active_call_a .update(cx_a, |call, cx| call.set_location(Some(&project_a), cx)) .await @@ -1605,7 +1612,7 @@ async fn test_mutual_editor_inlay_hint_cache_update( // The host opens a rust file. let _buffer_a = project_a .update(cx_a, |project, cx| { - project.open_local_buffer("/a/main.rs", cx) + project.open_local_buffer(path!("/a/main.rs"), cx) }) .await .unwrap(); @@ -1629,7 +1636,7 @@ async fn test_mutual_editor_inlay_hint_cache_update( async move { assert_eq!( params.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); let edits_made = task_edits_made.load(atomic::Ordering::Acquire); Ok(Some(vec![lsp::InlayHint { @@ -1809,14 +1816,14 @@ async fn test_inlay_hint_refresh_is_forwarded( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "main.rs": "fn main() { a } // and some long comment to ensure inlay hints are not trimmed out", "other.rs": "// Test file", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; active_call_a .update(cx_a, |call, cx| call.set_location(Some(&project_a), cx)) .await @@ -1864,7 +1871,7 @@ async fn test_inlay_hint_refresh_is_forwarded( async move { assert_eq!( params.text_document.uri, - lsp::Url::from_file_path("/a/main.rs").unwrap(), + lsp::Url::from_file_path(path!("/a/main.rs")).unwrap(), ); let other_hints = task_other_hints.load(atomic::Ordering::Acquire); let character = if other_hints { 0 } else { 2 }; @@ -1967,7 +1974,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA client_a .fs() .insert_tree( - "/my-repo", + path!("/my-repo"), json!({ ".git": {}, "file.txt": "line1\nline2\nline3\nline\n", @@ -1993,11 +2000,12 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA .collect(), remote_url: Some("git@github.com:zed-industries/zed.git".to_string()), }; - client_a - .fs() - .set_blame_for_repo(Path::new("/my-repo/.git"), vec![("file.txt".into(), blame)]); + client_a.fs().set_blame_for_repo( + Path::new(path!("/my-repo/.git")), + vec![("file.txt".into(), blame)], + ); - let (project_a, worktree_id) = client_a.build_local_project("/my-repo", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/my-repo"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -2177,7 +2185,7 @@ async fn test_collaborating_with_editorconfig( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "src": { "main.rs": "mod other;\nfn main() { let foo = other::foo(); }", @@ -2190,7 +2198,7 @@ async fn test_collaborating_with_editorconfig( }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -2309,7 +2317,7 @@ fn main() { let foo = other::foo(); }"}; client_a .fs() .atomic_write( - PathBuf::from("/a/src/.editorconfig"), + PathBuf::from(path!("/a/src/.editorconfig")), "[*]\ntab_width = 3\n".to_owned(), ) .await diff --git a/crates/collab/src/tests/following_tests.rs b/crates/collab/src/tests/following_tests.rs index fa5caf0116..6a449dfd2f 100644 --- a/crates/collab/src/tests/following_tests.rs +++ b/crates/collab/src/tests/following_tests.rs @@ -16,6 +16,7 @@ use project::WorktreeSettings; use rpc::proto::PeerId; use serde_json::json; use settings::SettingsStore; +use util::path; use workspace::{item::ItemHandle as _, SplitDirection, Workspace}; use super::TestClient; @@ -50,7 +51,7 @@ async fn test_basic_following( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "1.txt": "one\none\none", "2.txt": "two\ntwo\ntwo", @@ -58,7 +59,7 @@ async fn test_basic_following( }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; active_call_a .update(cx_a, |call, cx| call.set_location(Some(&project_a), cx)) .await @@ -436,7 +437,9 @@ async fn test_basic_following( ); // TODO: Re-enable this test once we can replace our swift Livekit SDK with the rust SDK - #[cfg(not(target_os = "macos"))] + // todo(windows) + // Fix this on Windows + #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] { use crate::rpc::RECONNECT_TIMEOUT; use gpui::TestScreenCaptureSource; @@ -1220,7 +1223,7 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "1.txt": "one", "2.txt": "two", @@ -1228,7 +1231,7 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; active_call_a .update(cx_a, |call, cx| call.set_location(Some(&project_a), cx)) .await @@ -1435,7 +1438,7 @@ async fn test_following_across_workspaces(cx_a: &mut TestAppContext, cx_b: &mut client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "w.rs": "", "x.rs": "", @@ -1446,7 +1449,7 @@ async fn test_following_across_workspaces(cx_a: &mut TestAppContext, cx_b: &mut client_b .fs() .insert_tree( - "/b", + path!("/b"), json!({ "y.rs": "", "z.rs": "", @@ -1460,8 +1463,8 @@ async fn test_following_across_workspaces(cx_a: &mut TestAppContext, cx_b: &mut let active_call_a = cx_a.read(ActiveCall::global); let active_call_b = cx_b.read(ActiveCall::global); - let (project_a, worktree_id_a) = client_a.build_local_project("/a", cx_a).await; - let (project_b, worktree_id_b) = client_b.build_local_project("/b", cx_b).await; + let (project_a, worktree_id_a) = client_a.build_local_project(path!("/a"), cx_a).await; + let (project_b, worktree_id_b) = client_b.build_local_project(path!("/b"), cx_b).await; let (workspace_a, cx_a) = client_a.build_workspace(&project_a, cx_a); let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b); @@ -1718,7 +1721,7 @@ async fn test_following_into_excluded_file( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ ".git": { "COMMIT_EDITMSG": "write your commit message here", @@ -1729,7 +1732,7 @@ async fn test_following_into_excluded_file( }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; active_call_a .update(cx_a, |call, cx| call.set_location(Some(&project_a), cx)) .await diff --git a/crates/collab/src/tests/git_tests.rs b/crates/collab/src/tests/git_tests.rs index ed74b9f7cf..3f78bd1158 100644 --- a/crates/collab/src/tests/git_tests.rs +++ b/crates/collab/src/tests/git_tests.rs @@ -9,6 +9,7 @@ use git_ui::project_diff::ProjectDiff; use gpui::{TestAppContext, VisualTestContext}; use project::ProjectPath; use serde_json::json; +use util::path; use workspace::Workspace; // @@ -29,7 +30,7 @@ async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ ".git": {}, "changed.txt": "after\n", @@ -41,7 +42,7 @@ async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) .await; client_a.fs().set_git_content_for_repo( - Path::new("/a/.git"), + Path::new(path!("/a/.git")), &[ ("changed.txt".into(), "before\n".to_string(), None), ("unchanged.txt".into(), "unchanged\n".to_string(), None), @@ -49,7 +50,7 @@ async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) ("secret.pem".into(), "shh\n".to_string(), None), ], ); - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let active_call_a = cx_a.read(ActiveCall::global); let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) @@ -93,7 +94,7 @@ async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ ".git": {}, "changed.txt": "before\n", diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index 9fdea06696..ee4c7cb3ec 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -50,6 +50,7 @@ use std::{ time::Duration, }; use unindent::Unindent as _; +use util::{path, separator, uri}; use workspace::Pane; #[ctor::ctor] @@ -1459,7 +1460,7 @@ async fn test_project_reconnect( client_a .fs() .insert_tree( - "/root-1", + path!("/root-1"), json!({ "dir1": { "a.txt": "a", @@ -1487,7 +1488,7 @@ async fn test_project_reconnect( client_a .fs() .insert_tree( - "/root-2", + path!("/root-2"), json!({ "2.txt": "2", }), @@ -1496,7 +1497,7 @@ async fn test_project_reconnect( client_a .fs() .insert_tree( - "/root-3", + path!("/root-3"), json!({ "3.txt": "3", }), @@ -1504,9 +1505,11 @@ async fn test_project_reconnect( .await; let active_call_a = cx_a.read(ActiveCall::global); - let (project_a1, _) = client_a.build_local_project("/root-1/dir1", cx_a).await; - let (project_a2, _) = client_a.build_local_project("/root-2", cx_a).await; - let (project_a3, _) = client_a.build_local_project("/root-3", cx_a).await; + let (project_a1, _) = client_a + .build_local_project(path!("/root-1/dir1"), cx_a) + .await; + let (project_a2, _) = client_a.build_local_project(path!("/root-2"), cx_a).await; + let (project_a3, _) = client_a.build_local_project(path!("/root-3"), cx_a).await; let worktree_a1 = project_a1.read_with(cx_a, |project, cx| project.worktrees(cx).next().unwrap()); let project1_id = active_call_a @@ -1533,7 +1536,7 @@ async fn test_project_reconnect( }); let (worktree_a2, _) = project_a1 .update(cx_a, |p, cx| { - p.find_or_create_worktree("/root-1/dir2", true, cx) + p.find_or_create_worktree(path!("/root-1/dir2"), true, cx) }) .await .unwrap(); @@ -1579,7 +1582,7 @@ async fn test_project_reconnect( client_a .fs() .insert_tree( - "/root-1/dir1/subdir2", + path!("/root-1/dir1/subdir2"), json!({ "f.txt": "f-contents", "g.txt": "g-contents", @@ -1591,7 +1594,7 @@ async fn test_project_reconnect( client_a .fs() .remove_dir( - "/root-1/dir1/subdir1".as_ref(), + path!("/root-1/dir1/subdir1").as_ref(), RemoveOptions { recursive: true, ..Default::default() @@ -1606,7 +1609,7 @@ async fn test_project_reconnect( }); let (worktree_a3, _) = project_a1 .update(cx_a, |p, cx| { - p.find_or_create_worktree("/root-1/dir3", true, cx) + p.find_or_create_worktree(path!("/root-1/dir3"), true, cx) }) .await .unwrap(); @@ -1647,13 +1650,13 @@ async fn test_project_reconnect( .map(|p| p.to_str().unwrap()) .collect::>(), vec![ - "a.txt", - "b.txt", - "subdir2", - "subdir2/f.txt", - "subdir2/g.txt", - "subdir2/h.txt", - "subdir2/i.txt" + separator!("a.txt"), + separator!("b.txt"), + separator!("subdir2"), + separator!("subdir2/f.txt"), + separator!("subdir2/g.txt"), + separator!("subdir2/h.txt"), + separator!("subdir2/i.txt") ] ); assert!(worktree_a3.read(cx).has_update_observer()); @@ -1680,13 +1683,13 @@ async fn test_project_reconnect( .map(|p| p.to_str().unwrap()) .collect::>(), vec![ - "a.txt", - "b.txt", - "subdir2", - "subdir2/f.txt", - "subdir2/g.txt", - "subdir2/h.txt", - "subdir2/i.txt" + separator!("a.txt"), + separator!("b.txt"), + separator!("subdir2"), + separator!("subdir2/f.txt"), + separator!("subdir2/g.txt"), + separator!("subdir2/h.txt"), + separator!("subdir2/i.txt") ] ); assert!(project.worktree_for_id(worktree2_id, cx).is_none()); @@ -1719,18 +1722,21 @@ async fn test_project_reconnect( // While client B is disconnected, add and remove files from client A's project client_a .fs() - .insert_file("/root-1/dir1/subdir2/j.txt", "j-contents".into()) + .insert_file(path!("/root-1/dir1/subdir2/j.txt"), "j-contents".into()) .await; client_a .fs() - .remove_file("/root-1/dir1/subdir2/i.txt".as_ref(), Default::default()) + .remove_file( + path!("/root-1/dir1/subdir2/i.txt").as_ref(), + Default::default(), + ) .await .unwrap(); // While client B is disconnected, add and remove worktrees from client A's project. let (worktree_a4, _) = project_a1 .update(cx_a, |p, cx| { - p.find_or_create_worktree("/root-1/dir4", true, cx) + p.find_or_create_worktree(path!("/root-1/dir4"), true, cx) }) .await .unwrap(); @@ -1773,13 +1779,13 @@ async fn test_project_reconnect( .map(|p| p.to_str().unwrap()) .collect::>(), vec![ - "a.txt", - "b.txt", - "subdir2", - "subdir2/f.txt", - "subdir2/g.txt", - "subdir2/h.txt", - "subdir2/j.txt" + separator!("a.txt"), + separator!("b.txt"), + separator!("subdir2"), + separator!("subdir2/f.txt"), + separator!("subdir2/g.txt"), + separator!("subdir2/h.txt"), + separator!("subdir2/j.txt") ] ); assert!(project.worktree_for_id(worktree2_id, cx).is_none()); @@ -2316,14 +2322,14 @@ async fn test_propagate_saves_and_fs_changes( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "file1.rs": "", "file2": "" }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let worktree_a = project_a.read_with(cx_a, |p, cx| p.worktrees(cx).next().unwrap()); let project_id = active_call_a @@ -2409,18 +2415,25 @@ async fn test_propagate_saves_and_fs_changes( client_a .fs() .rename( - "/a/file1.rs".as_ref(), - "/a/file1.js".as_ref(), + path!("/a/file1.rs").as_ref(), + path!("/a/file1.js").as_ref(), Default::default(), ) .await .unwrap(); client_a .fs() - .rename("/a/file2".as_ref(), "/a/file3".as_ref(), Default::default()) + .rename( + path!("/a/file2").as_ref(), + path!("/a/file3").as_ref(), + Default::default(), + ) .await .unwrap(); - client_a.fs().insert_file("/a/file4", "4".into()).await; + client_a + .fs() + .insert_file(path!("/a/file4"), "4".into()) + .await; executor.run_until_parked(); worktree_a.read_with(cx_a, |tree, _| { @@ -2959,7 +2972,7 @@ async fn test_git_status_sync( client_a .fs() .insert_tree( - "/dir", + path!("/dir"), json!({ ".git": {}, "a.txt": "a", @@ -2972,11 +2985,11 @@ async fn test_git_status_sync( // Initially, a.txt is uncommitted, but present in the index, // and b.txt is unmerged. client_a.fs().set_head_for_repo( - "/dir/.git".as_ref(), + path!("/dir/.git").as_ref(), &[("b.txt".into(), "B".into()), ("c.txt".into(), "c".into())], ); client_a.fs().set_index_for_repo( - "/dir/.git".as_ref(), + path!("/dir/.git").as_ref(), &[ ("a.txt".into(), "".into()), ("b.txt".into(), "B".into()), @@ -2984,7 +2997,7 @@ async fn test_git_status_sync( ], ); client_a.fs().set_unmerged_paths_for_repo( - "/dir/.git".as_ref(), + path!("/dir/.git").as_ref(), &[( "b.txt".into(), UnmergedStatus { @@ -3003,7 +3016,7 @@ async fn test_git_status_sync( second_head: UnmergedStatusCode::Deleted, }); - let (project_local, _worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_local, _worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| { call.share_project(project_local.clone(), cx) @@ -3068,15 +3081,15 @@ async fn test_git_status_sync( // Delete b.txt from the index, mark conflict as resolved, // and modify c.txt in the working copy. client_a.fs().set_index_for_repo( - "/dir/.git".as_ref(), + path!("/dir/.git").as_ref(), &[("a.txt".into(), "a".into()), ("c.txt".into(), "c".into())], ); client_a .fs() - .set_unmerged_paths_for_repo("/dir/.git".as_ref(), &[]); + .set_unmerged_paths_for_repo(path!("/dir/.git").as_ref(), &[]); client_a .fs() - .atomic_write("/dir/c.txt".into(), "CC".into()) + .atomic_write(path!("/dir/c.txt").into(), "CC".into()) .await .unwrap(); @@ -3109,7 +3122,7 @@ async fn test_git_status_sync( // Now remove the original git repository and check that collaborators are notified. client_a .fs() - .remove_dir("/dir/.git".as_ref(), RemoveOptions::default()) + .remove_dir(path!("/dir/.git").as_ref(), RemoveOptions::default()) .await .unwrap(); @@ -3145,14 +3158,14 @@ async fn test_fs_operations( client_a .fs() .insert_tree( - "/dir", + path!("/dir"), json!({ "a.txt": "a-contents", "b.txt": "b-contents", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -3283,13 +3296,13 @@ async fn test_fs_operations( .map(|p| p.to_string_lossy()) .collect::>(), [ - "DIR", - "DIR/SUBDIR", - "DIR/SUBDIR/f.txt", - "DIR/e.txt", - "a.txt", - "b.txt", - "d.txt" + separator!("DIR"), + separator!("DIR/SUBDIR"), + separator!("DIR/SUBDIR/f.txt"), + separator!("DIR/e.txt"), + separator!("a.txt"), + separator!("b.txt"), + separator!("d.txt") ] ); }); @@ -3301,13 +3314,13 @@ async fn test_fs_operations( .map(|p| p.to_string_lossy()) .collect::>(), [ - "DIR", - "DIR/SUBDIR", - "DIR/SUBDIR/f.txt", - "DIR/e.txt", - "a.txt", - "b.txt", - "d.txt" + separator!("DIR"), + separator!("DIR/SUBDIR"), + separator!("DIR/SUBDIR/f.txt"), + separator!("DIR/e.txt"), + separator!("a.txt"), + separator!("b.txt"), + separator!("d.txt") ] ); }); @@ -3327,14 +3340,14 @@ async fn test_fs_operations( .map(|p| p.to_string_lossy()) .collect::>(), [ - "DIR", - "DIR/SUBDIR", - "DIR/SUBDIR/f.txt", - "DIR/e.txt", - "a.txt", - "b.txt", - "d.txt", - "f.txt" + separator!("DIR"), + separator!("DIR/SUBDIR"), + separator!("DIR/SUBDIR/f.txt"), + separator!("DIR/e.txt"), + separator!("a.txt"), + separator!("b.txt"), + separator!("d.txt"), + separator!("f.txt") ] ); }); @@ -3346,14 +3359,14 @@ async fn test_fs_operations( .map(|p| p.to_string_lossy()) .collect::>(), [ - "DIR", - "DIR/SUBDIR", - "DIR/SUBDIR/f.txt", - "DIR/e.txt", - "a.txt", - "b.txt", - "d.txt", - "f.txt" + separator!("DIR"), + separator!("DIR/SUBDIR"), + separator!("DIR/SUBDIR/f.txt"), + separator!("DIR/e.txt"), + separator!("a.txt"), + separator!("b.txt"), + separator!("d.txt"), + separator!("f.txt") ] ); }); @@ -3570,13 +3583,13 @@ async fn test_buffer_conflict_after_save( client_a .fs() .insert_tree( - "/dir", + path!("/dir"), json!({ "a.txt": "a-contents", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -3634,13 +3647,13 @@ async fn test_buffer_reloading( client_a .fs() .insert_tree( - "/dir", + path!("/dir"), json!({ "a.txt": "a\nb\nc", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -3662,7 +3675,11 @@ async fn test_buffer_reloading( let new_contents = Rope::from("d\ne\nf"); client_a .fs() - .save("/dir/a.txt".as_ref(), &new_contents, LineEnding::Windows) + .save( + path!("/dir/a.txt").as_ref(), + &new_contents, + LineEnding::Windows, + ) .await .unwrap(); @@ -3692,9 +3709,9 @@ async fn test_editing_while_guest_opens_buffer( client_a .fs() - .insert_tree("/dir", json!({ "a.txt": "a-contents" })) + .insert_tree(path!("/dir"), json!({ "a.txt": "a-contents" })) .await; - let (project_a, worktree_id) = client_a.build_local_project("/dir", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/dir"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -4007,19 +4024,19 @@ async fn test_collaborating_with_diagnostics( client_a .fs() .insert_tree( - "/a", + path!("/a"), json!({ "a.rs": "let one = two", "other.rs": "", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; // Cause the language server to start. let _buffer = project_a .update(cx_a, |project, cx| { - project.open_local_buffer_with_lsp("/a/other.rs", cx) + project.open_local_buffer_with_lsp(path!("/a/other.rs"), cx) }) .await .unwrap(); @@ -4031,7 +4048,7 @@ async fn test_collaborating_with_diagnostics( .await; fake_language_server.notify::( &lsp::PublishDiagnosticsParams { - uri: lsp::Url::from_file_path("/a/a.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/a/a.rs")).unwrap(), version: None, diagnostics: vec![lsp::Diagnostic { severity: Some(lsp::DiagnosticSeverity::WARNING), @@ -4051,7 +4068,7 @@ async fn test_collaborating_with_diagnostics( .unwrap(); fake_language_server.notify::( &lsp::PublishDiagnosticsParams { - uri: lsp::Url::from_file_path("/a/a.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/a/a.rs")).unwrap(), version: None, diagnostics: vec![lsp::Diagnostic { severity: Some(lsp::DiagnosticSeverity::ERROR), @@ -4125,7 +4142,7 @@ async fn test_collaborating_with_diagnostics( // Simulate a language server reporting more errors for a file. fake_language_server.notify::( &lsp::PublishDiagnosticsParams { - uri: lsp::Url::from_file_path("/a/a.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/a/a.rs")).unwrap(), version: None, diagnostics: vec![ lsp::Diagnostic { @@ -4219,7 +4236,7 @@ async fn test_collaborating_with_diagnostics( // Simulate a language server reporting no errors for a file. fake_language_server.notify::( &lsp::PublishDiagnosticsParams { - uri: lsp::Url::from_file_path("/a/a.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/a/a.rs")).unwrap(), version: None, diagnostics: vec![], }, @@ -4275,7 +4292,7 @@ async fn test_collaborating_with_lsp_progress_updates_and_diagnostics_ordering( client_a .fs() .insert_tree( - "/test", + path!("/test"), json!({ "one.rs": "const ONE: usize = 1;", "two.rs": "const TWO: usize = 2;", @@ -4286,7 +4303,7 @@ async fn test_collaborating_with_lsp_progress_updates_and_diagnostics_ordering( ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/test", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/test"), cx_a).await; // Share a project as client A let active_call_a = cx_a.read(ActiveCall::global); @@ -4325,7 +4342,7 @@ async fn test_collaborating_with_lsp_progress_updates_and_diagnostics_ordering( for file_name in file_names { fake_language_server.notify::( &lsp::PublishDiagnosticsParams { - uri: lsp::Url::from_file_path(Path::new("/test").join(file_name)).unwrap(), + uri: lsp::Url::from_file_path(Path::new(path!("/test")).join(file_name)).unwrap(), version: None, diagnostics: vec![lsp::Diagnostic { severity: Some(lsp::DiagnosticSeverity::WARNING), @@ -4392,9 +4409,9 @@ async fn test_reloading_buffer_manually( client_a .fs() - .insert_tree("/a", json!({ "a.rs": "let one = 1;" })) + .insert_tree(path!("/a"), json!({ "a.rs": "let one = 1;" })) .await; - let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await; let buffer_a = project_a .update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)) .await @@ -4422,7 +4439,7 @@ async fn test_reloading_buffer_manually( client_a .fs() .save( - "/a/a.rs".as_ref(), + path!("/a/a.rs").as_ref(), &Rope::from("let seven = 7;"), LineEnding::Unix, ) @@ -4544,39 +4561,45 @@ async fn test_formatting_buffer( "let honey = \"two\"\n" ); - // Ensure buffer can be formatted using an external command. Notice how the - // host's configuration is honored as opposed to using the guest's settings. - cx_a.update(|cx| { - SettingsStore::update_global(cx, |store, cx| { - store.update_user_settings::(cx, |file| { - file.defaults.formatter = Some(SelectedFormatter::List(FormatterList( - vec![Formatter::External { - command: "awk".into(), - arguments: Some(vec!["{sub(/two/,\"{buffer_path}\")}1".to_string()].into()), - }] - .into(), - ))); + // There is no `awk` command on Windows. + #[cfg(not(target_os = "windows"))] + { + // Ensure buffer can be formatted using an external command. Notice how the + // host's configuration is honored as opposed to using the guest's settings. + cx_a.update(|cx| { + SettingsStore::update_global(cx, |store, cx| { + store.update_user_settings::(cx, |file| { + file.defaults.formatter = Some(SelectedFormatter::List(FormatterList( + vec![Formatter::External { + command: "awk".into(), + arguments: Some( + vec!["{sub(/two/,\"{buffer_path}\")}1".to_string()].into(), + ), + }] + .into(), + ))); + }); }); }); - }); - executor.allow_parking(); - project_b - .update(cx_b, |project, cx| { - project.format( - HashSet::from_iter([buffer_b.clone()]), - LspFormatTarget::Buffers, - true, - FormatTrigger::Save, - cx, - ) - }) - .await - .unwrap(); - assert_eq!( - buffer_b.read_with(cx_b, |buffer, _| buffer.text()), - format!("let honey = \"{}/a.rs\"\n", directory.to_str().unwrap()) - ); + executor.allow_parking(); + project_b + .update(cx_b, |project, cx| { + project.format( + HashSet::from_iter([buffer_b.clone()]), + LspFormatTarget::Buffers, + true, + FormatTrigger::Save, + cx, + ) + }) + .await + .unwrap(); + assert_eq!( + buffer_b.read_with(cx_b, |buffer, _| buffer.text()), + format!("let honey = \"{}/a.rs\"\n", directory.to_str().unwrap()) + ); + } } #[gpui::test(iterations = 10)] @@ -4734,7 +4757,7 @@ async fn test_definition( client_a .fs() .insert_tree( - "/root", + path!("/root"), json!({ "dir-1": { "a.rs": "const ONE: usize = b::TWO + b::THREE;", @@ -4746,7 +4769,9 @@ async fn test_definition( }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/root/dir-1", cx_a).await; + let (project_a, worktree_id) = client_a + .build_local_project(path!("/root/dir-1"), cx_a) + .await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -4767,7 +4792,7 @@ async fn test_definition( |_, _| async move { Ok(Some(lsp::GotoDefinitionResponse::Scalar( lsp::Location::new( - lsp::Url::from_file_path("/root/dir-2/b.rs").unwrap(), + lsp::Url::from_file_path(path!("/root/dir-2/b.rs")).unwrap(), lsp::Range::new(lsp::Position::new(0, 6), lsp::Position::new(0, 9)), ), ))) @@ -4798,7 +4823,7 @@ async fn test_definition( |_, _| async move { Ok(Some(lsp::GotoDefinitionResponse::Scalar( lsp::Location::new( - lsp::Url::from_file_path("/root/dir-2/b.rs").unwrap(), + lsp::Url::from_file_path(path!("/root/dir-2/b.rs")).unwrap(), lsp::Range::new(lsp::Position::new(1, 6), lsp::Position::new(1, 11)), ), ))) @@ -4835,7 +4860,7 @@ async fn test_definition( ); Ok(Some(lsp::GotoDefinitionResponse::Scalar( lsp::Location::new( - lsp::Url::from_file_path("/root/dir-2/c.rs").unwrap(), + lsp::Url::from_file_path(path!("/root/dir-2/c.rs")).unwrap(), lsp::Range::new(lsp::Position::new(0, 5), lsp::Position::new(0, 7)), ), ))) @@ -4887,7 +4912,7 @@ async fn test_references( client_a .fs() .insert_tree( - "/root", + path!("/root"), json!({ "dir-1": { "one.rs": "const ONE: usize = 1;", @@ -4899,7 +4924,9 @@ async fn test_references( }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/root/dir-1", cx_a).await; + let (project_a, worktree_id) = client_a + .build_local_project(path!("/root/dir-1"), cx_a) + .await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -4922,7 +4949,7 @@ async fn test_references( move |params, _| { assert_eq!( params.text_document_position.text_document.uri.as_str(), - "file:///root/dir-1/one.rs" + uri!("file:///root/dir-1/one.rs") ); let rx = rx.clone(); async move { @@ -4951,15 +4978,15 @@ async fn test_references( lsp_response_tx .unbounded_send(Ok(Some(vec![ lsp::Location { - uri: lsp::Url::from_file_path("/root/dir-1/two.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/root/dir-1/two.rs")).unwrap(), range: lsp::Range::new(lsp::Position::new(0, 24), lsp::Position::new(0, 27)), }, lsp::Location { - uri: lsp::Url::from_file_path("/root/dir-1/two.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/root/dir-1/two.rs")).unwrap(), range: lsp::Range::new(lsp::Position::new(0, 35), lsp::Position::new(0, 38)), }, lsp::Location { - uri: lsp::Url::from_file_path("/root/dir-2/three.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/root/dir-2/three.rs")).unwrap(), range: lsp::Range::new(lsp::Position::new(0, 37), lsp::Position::new(0, 40)), }, ]))) @@ -4984,7 +5011,7 @@ async fn test_references( assert_eq!(references[1].buffer, references[0].buffer); assert_eq!( three_buffer.file().unwrap().full_path(cx), - Path::new("/root/dir-2/three.rs") + Path::new(path!("/root/dir-2/three.rs")) ); assert_eq!(references[0].range.to_offset(two_buffer), 24..27); @@ -5138,7 +5165,7 @@ async fn test_document_highlights( client_a .fs() .insert_tree( - "/root-1", + path!("/root-1"), json!({ "main.rs": "fn double(number: i32) -> i32 { number + number }", }), @@ -5150,7 +5177,7 @@ async fn test_document_highlights( .register_fake_lsp("Rust", Default::default()); client_a.language_registry().add(rust_lang()); - let (project_a, worktree_id) = client_a.build_local_project("/root-1", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/root-1"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -5175,7 +5202,7 @@ async fn test_document_highlights( .text_document .uri .as_str(), - "file:///root-1/main.rs" + uri!("file:///root-1/main.rs") ); assert_eq!( params.text_document_position_params.position, @@ -5238,7 +5265,7 @@ async fn test_lsp_hover( client_a .fs() .insert_tree( - "/root-1", + path!("/root-1"), json!({ "main.rs": "use std::collections::HashMap;", }), @@ -5272,7 +5299,7 @@ async fn test_lsp_hover( ), ]; - let (project_a, worktree_id) = client_a.build_local_project("/root-1", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/root-1"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -5312,7 +5339,7 @@ async fn test_lsp_hover( .text_document .uri .as_str(), - "file:///root-1/main.rs" + uri!("file:///root-1/main.rs") ); let name = new_server_name.clone(); async move { @@ -5338,7 +5365,7 @@ async fn test_lsp_hover( .text_document .uri .as_str(), - "file:///root-1/main.rs" + uri!("file:///root-1/main.rs") ); assert_eq!( params.text_document_position_params.position, @@ -5445,7 +5472,7 @@ async fn test_project_symbols( client_a .fs() .insert_tree( - "/code", + path!("/code"), json!({ "crate-1": { "one.rs": "const ONE: usize = 1;", @@ -5459,7 +5486,9 @@ async fn test_project_symbols( }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/code/crate-1", cx_a).await; + let (project_a, worktree_id) = client_a + .build_local_project(path!("/code/crate-1"), cx_a) + .await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -5482,7 +5511,7 @@ async fn test_project_symbols( lsp::SymbolInformation { name: "TWO".into(), location: lsp::Location { - uri: lsp::Url::from_file_path("/code/crate-2/two.rs").unwrap(), + uri: lsp::Url::from_file_path(path!("/code/crate-2/two.rs")).unwrap(), range: lsp::Range::new(lsp::Position::new(0, 6), lsp::Position::new(0, 9)), }, kind: lsp::SymbolKind::CONSTANT, @@ -5513,13 +5542,13 @@ async fn test_project_symbols( buffer_b_2.read_with(cx_b, |buffer, cx| { assert_eq!( buffer.file().unwrap().full_path(cx), - Path::new("/code/crate-2/two.rs") + Path::new(path!("/code/crate-2/two.rs")) ); }); // Attempt to craft a symbol and violate host's privacy by opening an arbitrary file. let mut fake_symbol = symbols[0].clone(); - fake_symbol.path.path = Path::new("/code/secrets").into(); + fake_symbol.path.path = Path::new(path!("/code/secrets")).into(); let error = project_b .update(cx_b, |project, cx| { project.open_buffer_for_symbol(&fake_symbol, cx) @@ -5552,14 +5581,14 @@ async fn test_open_buffer_while_getting_definition_pointing_to_it( client_a .fs() .insert_tree( - "/root", + path!("/root"), json!({ "a.rs": "const ONE: usize = b::TWO;", "b.rs": "const TWO: usize = 2", }), ) .await; - let (project_a, worktree_id) = client_a.build_local_project("/root", cx_a).await; + let (project_a, worktree_id) = client_a.build_local_project(path!("/root"), cx_a).await; let project_id = active_call_a .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx)) .await @@ -5578,7 +5607,7 @@ async fn test_open_buffer_while_getting_definition_pointing_to_it( |_, _| async move { Ok(Some(lsp::GotoDefinitionResponse::Scalar( lsp::Location::new( - lsp::Url::from_file_path("/root/b.rs").unwrap(), + lsp::Url::from_file_path(path!("/root/b.rs")).unwrap(), lsp::Range::new(lsp::Position::new(0, 6), lsp::Position::new(0, 9)), ), ))) diff --git a/crates/collab/src/tests/random_project_collaboration_tests.rs b/crates/collab/src/tests/random_project_collaboration_tests.rs index 060aec3aeb..c997c90457 100644 --- a/crates/collab/src/tests/random_project_collaboration_tests.rs +++ b/crates/collab/src/tests/random_project_collaboration_tests.rs @@ -27,7 +27,7 @@ use std::{ rc::Rc, sync::Arc, }; -use util::ResultExt; +use util::{path, ResultExt}; #[gpui::test( iterations = 100, @@ -280,7 +280,7 @@ impl RandomizedTest for ProjectCollaborationTest { let mut paths = client.fs().paths(false); paths.remove(0); let new_root_path = if paths.is_empty() || rng.gen() { - Path::new("/").join(plan.next_root_dir_name()) + Path::new(path!("/")).join(plan.next_root_dir_name()) } else { paths.choose(rng).unwrap().clone() }; @@ -547,7 +547,7 @@ impl RandomizedTest for ProjectCollaborationTest { first_root_name ); - let root_path = Path::new("/").join(&first_root_name); + let root_path = Path::new(path!("/")).join(&first_root_name); client.fs().create_dir(&root_path).await.unwrap(); client .fs() diff --git a/crates/collab/src/tests/remote_editing_collaboration_tests.rs b/crates/collab/src/tests/remote_editing_collaboration_tests.rs index f4c0bdb44a..515a7bd2f7 100644 --- a/crates/collab/src/tests/remote_editing_collaboration_tests.rs +++ b/crates/collab/src/tests/remote_editing_collaboration_tests.rs @@ -26,6 +26,7 @@ use remote_server::{HeadlessAppState, HeadlessProject}; use serde_json::json; use settings::SettingsStore; use std::{path::Path, sync::Arc}; +use util::{path, separator}; #[gpui::test(iterations = 10)] async fn test_sharing_an_ssh_remote_project( @@ -52,7 +53,7 @@ async fn test_sharing_an_ssh_remote_project( let remote_fs = FakeFs::new(server_cx.executor()); remote_fs .insert_tree( - "/code", + path!("/code"), json!({ "project1": { ".zed": { @@ -92,7 +93,7 @@ async fn test_sharing_an_ssh_remote_project( let client_ssh = SshRemoteClient::fake_client(opts, cx_a).await; let (project_a, worktree_id) = client_a - .build_ssh_project("/code/project1", client_ssh, cx_a) + .build_ssh_project(path!("/code/project1"), client_ssh, cx_a) .await; // While the SSH worktree is being scanned, user A shares the remote project. @@ -178,7 +179,7 @@ async fn test_sharing_an_ssh_remote_project( .unwrap(); assert_eq!( remote_fs - .load("/code/project1/src/renamed.rs".as_ref()) + .load(path!("/code/project1/src/renamed.rs").as_ref()) .await .unwrap(), "fn one() -> usize { 100 }" @@ -193,7 +194,7 @@ async fn test_sharing_an_ssh_remote_project( .path() .to_string_lossy() .to_string(), - "src/renamed.rs".to_string() + separator!("src/renamed.rs").to_string() ); }); } @@ -408,7 +409,10 @@ async fn test_ssh_collaboration_formatting_with_prettier( let buffer_text = "let one = \"two\""; let prettier_format_suffix = project::TEST_PRETTIER_FORMAT_SUFFIX; remote_fs - .insert_tree("/project", serde_json::json!({ "a.ts": buffer_text })) + .insert_tree( + path!("/project"), + serde_json::json!({ "a.ts": buffer_text }), + ) .await; let test_plugin = "test_plugin"; @@ -455,7 +459,7 @@ async fn test_ssh_collaboration_formatting_with_prettier( let client_ssh = SshRemoteClient::fake_client(opts, cx_a).await; let (project_a, worktree_id) = client_a - .build_ssh_project("/project", client_ssh, cx_a) + .build_ssh_project(path!("/project"), client_ssh, cx_a) .await; // While the SSH worktree is being scanned, user A shares the remote project. diff --git a/crates/collab/src/tests/test_server.rs b/crates/collab/src/tests/test_server.rs index 11a5d0530d..18be5cb21b 100644 --- a/crates/collab/src/tests/test_server.rs +++ b/crates/collab/src/tests/test_server.rs @@ -43,6 +43,7 @@ use std::{ Arc, }, }; +use util::path; use workspace::{Workspace, WorkspaceStore}; #[cfg(not(target_os = "macos"))] @@ -741,7 +742,7 @@ impl TestClient { pub async fn build_test_project(&self, cx: &mut TestAppContext) -> Entity { self.fs() .insert_tree( - "/a", + path!("/a"), json!({ "1.txt": "one\none\none", "2.js": "function two() { return 2; }", @@ -749,7 +750,7 @@ impl TestClient { }), ) .await; - self.build_local_project("/a", cx).await.0 + self.build_local_project(path!("/a"), cx).await.0 } pub async fn host_workspace(