Represent relative paths using a dedicated, separator-agnostic type (#38744)

Closes https://github.com/zed-industries/zed/issues/38690
Closes #37353

### Background

On Windows, paths are normally separated by `\`, unlike mac and linux
where they are separated by `/`. When editing code in a project that
uses a different path style than your local system (e.g. remoting from
Windows to Linux, using WSL, and collaboration between windows and unix
users), the correct separator for a path may differ from the "native"
separator.

Previously, to work around this, Zed converted paths' separators in
numerous places. This was applied to both absolute and relative paths,
leading to incorrect conversions in some cases.

### Solution

Many code paths in Zed use paths that are *relative* to either a
worktree root or a git repository. This PR introduces a dedicated type
for these paths called `RelPath`, which stores the path in the same way
regardless of host platform, and offers `Path`-like manipulation APIs.
RelPath supports *displaying* the path using either separator, so that
we can display paths in a style that is determined at runtime based on
the current project.

The representation of absolute paths is left untouched, for now.
Absolute paths are different from relative paths because (except in
contexts where we know that the path refers to the local filesystem)
they should generally be treated as opaque strings. Currently we use a
mix of types for these paths (std::path::Path, String, SanitizedPath).

Release Notes:

- N/A

---------

Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: Peter Tripp <petertripp@gmail.com>
Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
This commit is contained in:
Max Brunsfeld
2025-09-24 18:57:33 -04:00
committed by GitHub
co-authored by Cole Miller Piotr Osiewicz Peter Tripp Smit Barmase Lukas Wirth
parent 3c626f3758
commit 03f9cf4414
216 changed files with 5873 additions and 5257 deletions
@@ -13,6 +13,7 @@ use gpui::{BackgroundExecutor, Context, Entity, TestAppContext, Window};
use rpc::{RECEIVE_TIMEOUT, proto::PeerId};
use serde_json::json;
use std::ops::Range;
use util::rel_path::rel_path;
use workspace::CollaboratorId;
#[gpui::test]
@@ -256,7 +257,13 @@ async fn test_channel_notes_participant_indices(
executor.start_waiting();
let editor_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id_a, "file.txt"), None, true, window, cx)
workspace.open_path(
(worktree_id_a, rel_path("file.txt")),
None,
true,
window,
cx,
)
})
.await
.unwrap()
@@ -265,7 +272,13 @@ async fn test_channel_notes_participant_indices(
executor.start_waiting();
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id_a, "file.txt"), None, true, window, cx)
workspace.open_path(
(worktree_id_a, rel_path("file.txt")),
None,
true,
window,
cx,
)
})
.await
.unwrap()
@@ -4,6 +4,7 @@ use chrono::Utc;
use editor::Editor;
use gpui::{BackgroundExecutor, TestAppContext};
use rpc::proto;
use util::rel_path::rel_path;
#[gpui::test]
async fn test_channel_guests(
@@ -55,7 +56,7 @@ async fn test_channel_guests(
project_b
.update(cx_b, |project, cx| {
let worktree_id = project.worktrees(cx).next().unwrap().read(cx).id();
project.create_entry((worktree_id, "b.txt"), false, cx)
project.create_entry((worktree_id, rel_path("b.txt")), false, cx)
})
.await
.is_err()
+61 -37
View File
@@ -16,6 +16,7 @@ use editor::{
};
use fs::Fs;
use futures::{SinkExt, StreamExt, channel::mpsc, lock::Mutex};
use git::repository::repo_path;
use gpui::{App, Rgba, TestAppContext, UpdateGlobal, VisualContext, VisualTestContext};
use indoc::indoc;
use language::FakeLspAdapter;
@@ -38,7 +39,7 @@ use std::{
},
};
use text::Point;
use util::{path, uri};
use util::{path, rel_path::rel_path, uri};
use workspace::{CloseIntent, Workspace};
#[gpui::test(iterations = 10)]
@@ -97,7 +98,7 @@ async fn test_host_disconnect(
let editor_b = workspace_b
.update(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "b.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("b.txt")), None, true, window, cx)
})
.unwrap()
.await
@@ -205,7 +206,9 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
// Open a buffer as client A
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
let cx_a = cx_a.add_empty_window();
@@ -222,7 +225,9 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
let cx_b = cx_b.add_empty_window();
// Open a buffer as client B
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
let editor_b = cx_b
@@ -334,7 +339,9 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
// Open a file in an editor as the guest.
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
let cx_b = cx_b.add_empty_window();
@@ -408,7 +415,9 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
// Open the buffer on the host.
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
cx_a.executor().run_until_parked();
@@ -599,7 +608,7 @@ async fn test_collaborating_with_code_actions(
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -825,7 +834,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "one.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("one.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -1072,7 +1081,7 @@ async fn test_slow_lsp_server(cx_a: &mut TestAppContext, cx_b: &mut TestAppConte
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "one.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("one.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -1412,7 +1421,10 @@ async fn test_share_project(
project_b
.update(cx_b, |project, cx| {
let worktree = project.worktrees(cx).next().unwrap();
let entry = worktree.read(cx).entry_for_path("ignored-dir").unwrap();
let entry = worktree
.read(cx)
.entry_for_path(rel_path("ignored-dir"))
.unwrap();
project.expand_entry(worktree_id, entry.id, cx).unwrap()
})
.await
@@ -1435,17 +1447,21 @@ async fn test_share_project(
// Open the same file as client B and client A.
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "b.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("b.txt")), cx)
})
.await
.unwrap();
buffer_b.read_with(cx_b, |buf, _| assert_eq!(buf.text(), "b-contents"));
project_a.read_with(cx_a, |project, cx| {
assert!(project.has_open_buffer((worktree_id, "b.txt"), cx))
assert!(project.has_open_buffer((worktree_id, rel_path("b.txt")), cx))
});
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "b.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("b.txt")), cx)
})
.await
.unwrap();
@@ -1553,7 +1569,9 @@ async fn test_on_input_format_from_host_to_guest(
// Open a file in an editor as the host.
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
let cx_a = cx_a.add_empty_window();
@@ -1586,7 +1604,9 @@ async fn test_on_input_format_from_host_to_guest(
// Open the buffer on the guest and see that the formatting worked
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
@@ -1686,7 +1706,9 @@ async fn test_on_input_format_from_guest_to_host(
// Open a file in an editor as the guest.
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
let cx_b = cx_b.add_empty_window();
@@ -1732,7 +1754,9 @@ async fn test_on_input_format_from_guest_to_host(
// Open the buffer on the host and see that the formatting worked
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
executor.run_until_parked();
@@ -1881,7 +1905,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
.unwrap();
let editor_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -1931,7 +1955,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -2126,7 +2150,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
let editor_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -2135,7 +2159,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -2313,7 +2337,7 @@ async fn test_lsp_document_color(cx_a: &mut TestAppContext, cx_b: &mut TestAppCo
.unwrap();
let editor_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -2373,7 +2397,7 @@ async fn test_lsp_document_color(cx_a: &mut TestAppContext, cx_b: &mut TestAppCo
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -2594,7 +2618,7 @@ async fn test_lsp_pull_diagnostics(
.unwrap();
let editor_a_main = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -2953,7 +2977,7 @@ async fn test_lsp_pull_diagnostics(
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b_main = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -3001,7 +3025,7 @@ async fn test_lsp_pull_diagnostics(
let editor_b_lib = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "lib.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("lib.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -3355,7 +3379,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA
};
client_a.fs().set_blame_for_repo(
Path::new(path!("/my-repo/.git")),
vec![("file.txt".into(), blame)],
vec![(repo_path("file.txt"), blame)],
);
let (project_a, worktree_id) = client_a.build_local_project(path!("/my-repo"), cx_a).await;
@@ -3368,7 +3392,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA
let (workspace_a, cx_a) = client_a.build_workspace(&project_a, cx_a);
let editor_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "file.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("file.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -3380,7 +3404,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "file.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("file.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -3558,13 +3582,13 @@ async fn test_collaborating_with_editorconfig(
.unwrap();
let main_buffer_a = project_a
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, "src/main.rs"), cx)
p.open_buffer((worktree_id, rel_path("src/main.rs")), cx)
})
.await
.unwrap();
let other_buffer_a = project_a
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, "src/other_mod/other.rs"), cx)
p.open_buffer((worktree_id, rel_path("src/other_mod/other.rs")), cx)
})
.await
.unwrap();
@@ -3592,13 +3616,13 @@ async fn test_collaborating_with_editorconfig(
let project_b = client_b.join_remote_project(project_id, cx_b).await;
let main_buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, "src/main.rs"), cx)
p.open_buffer((worktree_id, rel_path("src/main.rs")), cx)
})
.await
.unwrap();
let other_buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, "src/other_mod/other.rs"), cx)
p.open_buffer((worktree_id, rel_path("src/other_mod/other.rs")), cx)
})
.await
.unwrap();
@@ -3717,7 +3741,7 @@ fn main() { let foo = other::foo(); }"};
let editorconfig_buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, "src/other_mod/.editorconfig"), cx)
p.open_buffer((worktree_id, rel_path("src/other_mod/.editorconfig")), cx)
})
.await
.unwrap();
@@ -3794,7 +3818,7 @@ async fn test_add_breakpoints(cx_a: &mut TestAppContext, cx_b: &mut TestAppConte
let (project_a, worktree_id) = client_a.build_local_project("/a", cx_a).await;
let project_path = ProjectPath {
worktree_id,
path: Arc::from(Path::new(&"test.txt")),
path: rel_path(&"test.txt").into(),
};
let abs_path = project_a.read_with(cx_a, |project, cx| {
project
@@ -4017,7 +4041,7 @@ async fn test_client_can_query_lsp_ext(cx_a: &mut TestAppContext, cx_b: &mut Tes
let editor_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
@@ -4026,7 +4050,7 @@ async fn test_client_can_query_lsp_ext(cx_a: &mut TestAppContext, cx_b: &mut Tes
let editor_b = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "main.rs"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("main.rs")), None, true, window, cx)
})
.await
.unwrap()
+31 -32
View File
@@ -16,7 +16,7 @@ use rpc::proto::PeerId;
use serde_json::json;
use settings::SettingsStore;
use text::{Point, ToPoint};
use util::{path, test::sample_text};
use util::{path, rel_path::rel_path, test::sample_text};
use workspace::{CollaboratorId, SplitDirection, Workspace, item::ItemHandle as _};
use super::TestClient;
@@ -86,7 +86,7 @@ async fn test_basic_following(
let pane_a = workspace_a.update(cx_a, |workspace, _| workspace.active_pane().clone());
let editor_a1 = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -94,7 +94,7 @@ async fn test_basic_following(
.unwrap();
let editor_a2 = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "2.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("2.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -104,7 +104,7 @@ async fn test_basic_following(
// Client B opens an editor.
let editor_b1 = workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -146,7 +146,7 @@ async fn test_basic_following(
});
assert_eq!(
cx_b.read(|cx| editor_b2.project_path(cx)),
Some((worktree_id, "2.txt").into())
Some((worktree_id, rel_path("2.txt")).into())
);
assert_eq!(
editor_b2.update(cx_b, |editor, cx| editor.selections.ranges(cx)),
@@ -286,12 +286,12 @@ async fn test_basic_following(
let multibuffer_a = cx_a.new(|cx| {
let buffer_a1 = project_a.update(cx, |project, cx| {
project
.get_open_buffer(&(worktree_id, "1.txt").into(), cx)
.get_open_buffer(&(worktree_id, rel_path("1.txt")).into(), cx)
.unwrap()
});
let buffer_a2 = project_a.update(cx, |project, cx| {
project
.get_open_buffer(&(worktree_id, "2.txt").into(), cx)
.get_open_buffer(&(worktree_id, rel_path("2.txt")).into(), cx)
.unwrap()
});
let mut result = MultiBuffer::new(Capability::ReadWrite);
@@ -618,13 +618,13 @@ async fn test_following_tab_order(
//Open 1, 3 in that order on client A
workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap();
workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "3.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("3.txt")), None, true, window, cx)
})
.await
.unwrap();
@@ -632,14 +632,7 @@ async fn test_following_tab_order(
let pane_paths = |pane: &Entity<workspace::Pane>, cx: &mut VisualTestContext| {
pane.update(cx, |pane, cx| {
pane.items()
.map(|item| {
item.project_path(cx)
.unwrap()
.path
.to_str()
.unwrap()
.to_owned()
})
.map(|item| item.project_path(cx).unwrap().path.as_str().to_owned())
.collect::<Vec<_>>()
})
};
@@ -656,7 +649,7 @@ async fn test_following_tab_order(
//Open just 2 on client B
workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "2.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("2.txt")), None, true, window, cx)
})
.await
.unwrap();
@@ -668,7 +661,7 @@ async fn test_following_tab_order(
//Open just 1 on client B
workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap();
@@ -728,7 +721,7 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
let (workspace_a, cx_a) = client_a.build_workspace(&project_a, cx_a);
workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -739,7 +732,7 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "2.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("2.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -816,14 +809,14 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
// Clients A and B each open a new file.
workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "3.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("3.txt")), None, true, window, cx)
})
.await
.unwrap();
workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "4.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("4.txt")), None, true, window, cx)
})
.await
.unwrap();
@@ -1259,7 +1252,7 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
let _editor_a1 = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -1359,7 +1352,7 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
// When client B activates a different item in the original pane, it automatically stops following client A.
workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id, "2.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("2.txt")), None, true, window, cx)
})
.await
.unwrap();
@@ -1492,7 +1485,7 @@ async fn test_following_across_workspaces(cx_a: &mut TestAppContext, cx_b: &mut
workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id_a, "w.rs"), None, true, window, cx)
workspace.open_path((worktree_id_a, rel_path("w.rs")), None, true, window, cx)
})
.await
.unwrap();
@@ -1545,7 +1538,7 @@ async fn test_following_across_workspaces(cx_a: &mut TestAppContext, cx_b: &mut
// b moves to x.rs in a's project, and a follows
workspace_b_project_a
.update_in(&mut cx_b2, |workspace, window, cx| {
workspace.open_path((worktree_id_a, "x.rs"), None, true, window, cx)
workspace.open_path((worktree_id_a, rel_path("x.rs")), None, true, window, cx)
})
.await
.unwrap();
@@ -1574,7 +1567,7 @@ async fn test_following_across_workspaces(cx_a: &mut TestAppContext, cx_b: &mut
// b moves to y.rs in b's project, a is still following but can't yet see
workspace_b
.update_in(cx_b, |workspace, window, cx| {
workspace.open_path((worktree_id_b, "y.rs"), None, true, window, cx)
workspace.open_path((worktree_id_b, rel_path("y.rs")), None, true, window, cx)
})
.await
.unwrap();
@@ -1759,7 +1752,7 @@ async fn test_following_into_excluded_file(
// Client A opens editors for a regular file and an excluded file.
let editor_for_regular = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap()
@@ -1767,7 +1760,13 @@ async fn test_following_into_excluded_file(
.unwrap();
let editor_for_excluded_a = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, ".git/COMMIT_EDITMSG"), None, true, window, cx)
workspace.open_path(
(worktree_id, rel_path(".git/COMMIT_EDITMSG")),
None,
true,
window,
cx,
)
})
.await
.unwrap()
@@ -1805,7 +1804,7 @@ async fn test_following_into_excluded_file(
});
assert_eq!(
cx_b.read(|cx| editor_for_excluded_b.project_path(cx)),
Some((worktree_id, ".git/COMMIT_EDITMSG").into())
Some((worktree_id, rel_path(".git/COMMIT_EDITMSG")).into())
);
assert_eq!(
editor_for_excluded_b.update(cx_b, |editor, cx| editor.selections.ranges(cx)),
@@ -2051,7 +2050,7 @@ async fn test_following_to_channel_notes_without_a_shared_project(
// Client A opens a local buffer in their unshared project.
let _unshared_editor_a1 = workspace_a
.update_in(cx_a, |workspace, window, cx| {
workspace.open_path((worktree_id, "1.txt"), None, true, window, cx)
workspace.open_path((worktree_id, rel_path("1.txt")), None, true, window, cx)
})
.await
.unwrap()
+8 -11
View File
@@ -1,7 +1,4 @@
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use std::path::Path;
use call::ActiveCall;
use git::status::{FileStatus, StatusCode, TrackedStatus};
@@ -9,7 +6,7 @@ use git_ui::project_diff::ProjectDiff;
use gpui::{TestAppContext, VisualTestContext};
use project::ProjectPath;
use serde_json::json;
use util::path;
use util::{path, rel_path::rel_path};
use workspace::Workspace;
//
@@ -41,13 +38,13 @@ async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext)
)
.await;
client_a.fs().set_git_content_for_repo(
client_a.fs().set_head_and_index_for_repo(
Path::new(path!("/a/.git")),
&[
("changed.txt".into(), "before\n".to_string(), None),
("unchanged.txt".into(), "unchanged\n".to_string(), None),
("deleted.txt".into(), "deleted\n".to_string(), None),
("secret.pem".into(), "shh\n".to_string(), None),
("changed.txt", "before\n".to_string()),
("unchanged.txt", "unchanged\n".to_string()),
("deleted.txt", "deleted\n".to_string()),
("secret.pem", "shh\n".to_string()),
],
);
let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await;
@@ -109,7 +106,7 @@ async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext)
project_b.update(cx_b, |project, cx| {
let project_path = ProjectPath {
worktree_id,
path: Arc::from(PathBuf::from("unchanged.txt")),
path: rel_path("unchanged.txt").into(),
};
let status = project.project_path_git_status(&project_path, cx);
assert_eq!(
+207 -217
View File
@@ -14,7 +14,10 @@ use client::{RECEIVE_TIMEOUT, User};
use collections::{HashMap, HashSet};
use fs::{FakeFs, Fs as _, RemoveOptions};
use futures::{StreamExt as _, channel::mpsc};
use git::status::{FileStatus, StatusCode, TrackedStatus, UnmergedStatus, UnmergedStatusCode};
use git::{
repository::repo_path,
status::{FileStatus, StatusCode, TrackedStatus, UnmergedStatus, UnmergedStatusCode},
};
use gpui::{
App, BackgroundExecutor, Entity, Modifiers, MouseButton, MouseDownEvent, TestAppContext,
UpdateGlobal, px, size,
@@ -30,7 +33,7 @@ use parking_lot::Mutex;
use pretty_assertions::assert_eq;
use project::{
DiagnosticSummary, HoverBlockKind, Project, ProjectPath,
lsp_store::{FormatTrigger, LspFormatTarget},
lsp_store::{FormatTrigger, LspFormatTarget, SymbolLocation},
search::{SearchQuery, SearchResult},
};
use prompt_store::PromptBuilder;
@@ -49,7 +52,7 @@ use std::{
time::Duration,
};
use unindent::Unindent as _;
use util::{path, uri};
use util::{path, rel_path::rel_path, uri};
use workspace::Pane;
#[ctor::ctor]
@@ -1418,7 +1421,9 @@ async fn test_unshare_project(
assert!(worktree_a.read_with(cx_a, |tree, _| tree.has_update_observer()));
project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -1454,7 +1459,9 @@ async fn test_unshare_project(
assert!(worktree_a.read_with(cx_a, |tree, _| tree.has_update_observer()));
project_c2
.update(cx_c, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_c, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -1584,11 +1591,15 @@ async fn test_project_reconnect(
});
let buffer_a1 = project_a1
.update(cx_a, |p, cx| p.open_buffer((worktree1_id, "a.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree1_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
let buffer_b1 = project_b1
.update(cx_b, |p, cx| p.open_buffer((worktree1_id, "a.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree1_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -1675,20 +1686,15 @@ async fn test_project_reconnect(
assert!(project.is_shared());
assert!(worktree_a1.read(cx).has_update_observer());
assert_eq!(
worktree_a1
.read(cx)
.snapshot()
.paths()
.map(|p| p.to_str().unwrap())
.collect::<Vec<_>>(),
worktree_a1.read(cx).snapshot().paths().collect::<Vec<_>>(),
vec![
path!("a.txt"),
path!("b.txt"),
path!("subdir2"),
path!("subdir2/f.txt"),
path!("subdir2/g.txt"),
path!("subdir2/h.txt"),
path!("subdir2/i.txt")
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("subdir2"),
rel_path("subdir2/f.txt"),
rel_path("subdir2/g.txt"),
rel_path("subdir2/h.txt"),
rel_path("subdir2/i.txt")
]
);
assert!(worktree_a3.read(cx).has_update_observer());
@@ -1697,7 +1703,7 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.to_str().unwrap())
.map(|p| p.as_str())
.collect::<Vec<_>>(),
vec!["w.txt", "x.txt", "y.txt"]
);
@@ -1712,16 +1718,15 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.to_str().unwrap())
.collect::<Vec<_>>(),
vec![
path!("a.txt"),
path!("b.txt"),
path!("subdir2"),
path!("subdir2/f.txt"),
path!("subdir2/g.txt"),
path!("subdir2/h.txt"),
path!("subdir2/i.txt")
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("subdir2"),
rel_path("subdir2/f.txt"),
rel_path("subdir2/g.txt"),
rel_path("subdir2/h.txt"),
rel_path("subdir2/i.txt")
]
);
assert!(project.worktree_for_id(worktree2_id, cx).is_none());
@@ -1732,7 +1737,7 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.to_str().unwrap())
.map(|p| p.as_str())
.collect::<Vec<_>>(),
vec!["w.txt", "x.txt", "y.txt"]
);
@@ -1809,16 +1814,15 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.to_str().unwrap())
.collect::<Vec<_>>(),
vec![
path!("a.txt"),
path!("b.txt"),
path!("subdir2"),
path!("subdir2/f.txt"),
path!("subdir2/g.txt"),
path!("subdir2/h.txt"),
path!("subdir2/j.txt")
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("subdir2"),
rel_path("subdir2/f.txt"),
rel_path("subdir2/g.txt"),
rel_path("subdir2/h.txt"),
rel_path("subdir2/j.txt")
]
);
assert!(project.worktree_for_id(worktree2_id, cx).is_none());
@@ -1829,7 +1833,7 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.to_str().unwrap())
.map(|p| p.as_str())
.collect::<Vec<_>>(),
vec!["z.txt"]
);
@@ -2370,11 +2374,15 @@ async fn test_propagate_saves_and_fs_changes(
// Open and edit a buffer as both guests B and C.
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "file1.rs"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("file1.rs")), cx)
})
.await
.unwrap();
let buffer_c = project_c
.update(cx_c, |p, cx| p.open_buffer((worktree_id, "file1.rs"), cx))
.update(cx_c, |p, cx| {
p.open_buffer((worktree_id, rel_path("file1.rs")), cx)
})
.await
.unwrap();
@@ -2390,7 +2398,9 @@ async fn test_propagate_saves_and_fs_changes(
// Open and edit that buffer as the host.
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "file1.rs"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("file1.rs")), cx)
})
.await
.unwrap();
@@ -2461,27 +2471,21 @@ async fn test_propagate_saves_and_fs_changes(
worktree_a.read_with(cx_a, |tree, _| {
assert_eq!(
tree.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
tree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["file1.js", "file3", "file4"]
)
});
worktree_b.read_with(cx_b, |tree, _| {
assert_eq!(
tree.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
tree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["file1.js", "file3", "file4"]
)
});
worktree_c.read_with(cx_c, |tree, _| {
assert_eq!(
tree.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
tree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["file1.js", "file3", "file4"]
)
});
@@ -2489,17 +2493,17 @@ async fn test_propagate_saves_and_fs_changes(
// Ensure buffer files are updated as well.
buffer_a.read_with(cx_a, |buffer, _| {
assert_eq!(buffer.file().unwrap().path().to_str(), Some("file1.js"));
assert_eq!(buffer.file().unwrap().path().as_str(), "file1.js");
assert_eq!(buffer.language().unwrap().name(), "JavaScript".into());
});
buffer_b.read_with(cx_b, |buffer, _| {
assert_eq!(buffer.file().unwrap().path().to_str(), Some("file1.js"));
assert_eq!(buffer.file().unwrap().path().as_str(), "file1.js");
assert_eq!(buffer.language().unwrap().name(), "JavaScript".into());
});
buffer_c.read_with(cx_c, |buffer, _| {
assert_eq!(buffer.file().unwrap().path().to_str(), Some("file1.js"));
assert_eq!(buffer.file().unwrap().path().as_str(), "file1.js");
assert_eq!(buffer.language().unwrap().name(), "JavaScript".into());
});
@@ -2524,7 +2528,7 @@ async fn test_propagate_saves_and_fs_changes(
project_a
.update(cx_a, |project, cx| {
let path = ProjectPath {
path: Arc::from(Path::new("file3.rs")),
path: rel_path("file3.rs").into(),
worktree_id: worktree_a.read(cx).id(),
};
@@ -2538,7 +2542,7 @@ async fn test_propagate_saves_and_fs_changes(
new_buffer_b.read_with(cx_b, |buffer_b, _| {
assert_eq!(
buffer_b.file().unwrap().path().as_ref(),
Path::new("file3.rs")
rel_path("file3.rs")
);
new_buffer_a.read_with(cx_a, |buffer_a, _| {
@@ -2621,19 +2625,20 @@ async fn test_git_diff_base_change(
"
.unindent();
client_a.fs().set_index_for_repo(
Path::new("/dir/.git"),
&[("a.txt".into(), staged_text.clone())],
);
client_a
.fs()
.set_index_for_repo(Path::new("/dir/.git"), &[("a.txt", staged_text.clone())]);
client_a.fs().set_head_for_repo(
Path::new("/dir/.git"),
&[("a.txt".into(), committed_text.clone())],
&[("a.txt", committed_text.clone())],
"deadbeef",
);
// Create the buffer
let buffer_local_a = project_local
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
let local_unstaged_diff_a = project_local
@@ -2661,7 +2666,9 @@ async fn test_git_diff_base_change(
// Create remote buffer
let remote_buffer_a = project_remote
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
let remote_unstaged_diff_a = project_remote
@@ -2717,11 +2724,11 @@ async fn test_git_diff_base_change(
// Update the index text of the open buffer
client_a.fs().set_index_for_repo(
Path::new("/dir/.git"),
&[("a.txt".into(), new_staged_text.clone())],
&[("a.txt", new_staged_text.clone())],
);
client_a.fs().set_head_for_repo(
Path::new("/dir/.git"),
&[("a.txt".into(), new_committed_text.clone())],
&[("a.txt", new_committed_text.clone())],
"deadbeef",
);
@@ -2790,12 +2797,14 @@ async fn test_git_diff_base_change(
client_a.fs().set_index_for_repo(
Path::new("/dir/sub/.git"),
&[("b.txt".into(), staged_text.clone())],
&[("b.txt", staged_text.clone())],
);
// Create the buffer
let buffer_local_b = project_local
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "sub/b.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("sub/b.txt")), cx)
})
.await
.unwrap();
let local_unstaged_diff_b = project_local
@@ -2823,7 +2832,9 @@ async fn test_git_diff_base_change(
// Create remote buffer
let remote_buffer_b = project_remote
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "sub/b.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("sub/b.txt")), cx)
})
.await
.unwrap();
let remote_unstaged_diff_b = project_remote
@@ -2851,7 +2862,7 @@ async fn test_git_diff_base_change(
// Updatet the staged text
client_a.fs().set_index_for_repo(
Path::new("/dir/sub/.git"),
&[("b.txt".into(), new_staged_text.clone())],
&[("b.txt", new_staged_text.clone())],
);
// Wait for buffer_local_b to receive it
@@ -3011,21 +3022,21 @@ async fn test_git_status_sync(
// and b.txt is unmerged.
client_a.fs().set_head_for_repo(
path!("/dir/.git").as_ref(),
&[("b.txt".into(), "B".into()), ("c.txt".into(), "c".into())],
&[("b.txt", "B".into()), ("c.txt", "c".into())],
"deadbeef",
);
client_a.fs().set_index_for_repo(
path!("/dir/.git").as_ref(),
&[
("a.txt".into(), "".into()),
("b.txt".into(), "B".into()),
("c.txt".into(), "c".into()),
("a.txt", "".into()),
("b.txt", "B".into()),
("c.txt", "c".into()),
],
);
client_a.fs().set_unmerged_paths_for_repo(
path!("/dir/.git").as_ref(),
&[(
"b.txt".into(),
repo_path("b.txt"),
UnmergedStatus {
first_head: UnmergedStatusCode::Updated,
second_head: UnmergedStatusCode::Deleted,
@@ -3056,13 +3067,8 @@ async fn test_git_status_sync(
executor.run_until_parked();
#[track_caller]
fn assert_status(
file: impl AsRef<Path>,
status: Option<FileStatus>,
project: &Project,
cx: &App,
) {
let file = file.as_ref();
fn assert_status(file: &str, status: Option<FileStatus>, project: &Project, cx: &App) {
let file = repo_path(file);
let repos = project
.repositories(cx)
.values()
@@ -3072,7 +3078,7 @@ async fn test_git_status_sync(
let repo = repos.into_iter().next().unwrap();
assert_eq!(
repo.read(cx)
.status_for_path(&file.into())
.status_for_path(&file)
.map(|entry| entry.status),
status
);
@@ -3107,7 +3113,7 @@ async fn test_git_status_sync(
// and modify c.txt in the working copy.
client_a.fs().set_index_for_repo(
path!("/dir/.git").as_ref(),
&[("a.txt".into(), "a".into()), ("c.txt".into(), "c".into())],
&[("a.txt", "a".into()), ("c.txt", "c".into())],
);
client_a
.fs()
@@ -3202,7 +3208,7 @@ async fn test_fs_operations(
let entry = project_b
.update(cx_b, |project, cx| {
project.create_entry((worktree_id, "c.txt"), false, cx)
project.create_entry((worktree_id, rel_path("c.txt")), false, cx)
})
.await
.unwrap()
@@ -3211,27 +3217,21 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "c.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "c.txt"]
);
});
project_b
.update(cx_b, |project, cx| {
project.rename_entry(entry.id, Path::new("d.txt"), cx)
project.rename_entry(entry.id, (worktree_id, rel_path("d.txt")).into(), cx)
})
.await
.unwrap()
@@ -3240,27 +3240,21 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt"]
);
});
let dir_entry = project_b
.update(cx_b, |project, cx| {
project.create_entry((worktree_id, "DIR"), true, cx)
project.create_entry((worktree_id, rel_path("DIR")), true, cx)
})
.await
.unwrap()
@@ -3269,27 +3263,21 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["DIR", "a.txt", "b.txt", "d.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["DIR", "a.txt", "b.txt", "d.txt"]
);
});
project_b
.update(cx_b, |project, cx| {
project.create_entry((worktree_id, "DIR/e.txt"), false, cx)
project.create_entry((worktree_id, rel_path("DIR/e.txt")), false, cx)
})
.await
.unwrap()
@@ -3298,7 +3286,7 @@ async fn test_fs_operations(
project_b
.update(cx_b, |project, cx| {
project.create_entry((worktree_id, "DIR/SUBDIR"), true, cx)
project.create_entry((worktree_id, rel_path("DIR/SUBDIR")), true, cx)
})
.await
.unwrap()
@@ -3307,7 +3295,7 @@ async fn test_fs_operations(
project_b
.update(cx_b, |project, cx| {
project.create_entry((worktree_id, "DIR/SUBDIR/f.txt"), false, cx)
project.create_entry((worktree_id, rel_path("DIR/SUBDIR/f.txt")), false, cx)
})
.await
.unwrap()
@@ -3316,43 +3304,41 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
[
path!("DIR"),
path!("DIR/SUBDIR"),
path!("DIR/SUBDIR/f.txt"),
path!("DIR/e.txt"),
path!("a.txt"),
path!("b.txt"),
path!("d.txt")
rel_path("DIR"),
rel_path("DIR/SUBDIR"),
rel_path("DIR/SUBDIR/f.txt"),
rel_path("DIR/e.txt"),
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("d.txt")
]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
[
path!("DIR"),
path!("DIR/SUBDIR"),
path!("DIR/SUBDIR/f.txt"),
path!("DIR/e.txt"),
path!("a.txt"),
path!("b.txt"),
path!("d.txt")
rel_path("DIR"),
rel_path("DIR/SUBDIR"),
rel_path("DIR/SUBDIR/f.txt"),
rel_path("DIR/e.txt"),
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("d.txt")
]
);
});
project_b
.update(cx_b, |project, cx| {
project.copy_entry(entry.id, None, Path::new("f.txt"), cx)
project.copy_entry(
entry.id,
(worktree_b.read(cx).id(), rel_path("f.txt")).into(),
cx,
)
})
.await
.unwrap()
@@ -3360,38 +3346,32 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
[
path!("DIR"),
path!("DIR/SUBDIR"),
path!("DIR/SUBDIR/f.txt"),
path!("DIR/e.txt"),
path!("a.txt"),
path!("b.txt"),
path!("d.txt"),
path!("f.txt")
rel_path("DIR"),
rel_path("DIR/SUBDIR"),
rel_path("DIR/SUBDIR/f.txt"),
rel_path("DIR/e.txt"),
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("d.txt"),
rel_path("f.txt")
]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
[
path!("DIR"),
path!("DIR/SUBDIR"),
path!("DIR/SUBDIR/f.txt"),
path!("DIR/e.txt"),
path!("a.txt"),
path!("b.txt"),
path!("d.txt"),
path!("f.txt")
rel_path("DIR"),
rel_path("DIR/SUBDIR"),
rel_path("DIR/SUBDIR/f.txt"),
rel_path("DIR/e.txt"),
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("d.txt"),
rel_path("f.txt")
]
);
});
@@ -3406,20 +3386,14 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt", "f.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt", "f.txt"]
);
});
@@ -3433,20 +3407,14 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "f.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree
.paths()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>(),
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "f.txt"]
);
});
@@ -3511,8 +3479,8 @@ async fn test_local_settings(
))
.collect::<Vec<_>>(),
&[
(Path::new("").into(), Some(2)),
(Path::new("a").into(), Some(8)),
(rel_path("").into(), Some(2)),
(rel_path("a").into(), Some(8)),
]
)
});
@@ -3533,10 +3501,7 @@ async fn test_local_settings(
content.all_languages.defaults.tab_size.map(Into::into)
))
.collect::<Vec<_>>(),
&[
(Path::new("").into(), None),
(Path::new("a").into(), Some(8)),
]
&[(rel_path("").into(), None), (rel_path("a").into(), Some(8)),]
)
});
@@ -3567,8 +3532,8 @@ async fn test_local_settings(
))
.collect::<Vec<_>>(),
&[
(Path::new("a").into(), Some(8)),
(Path::new("b").into(), Some(4)),
(rel_path("a").into(), Some(8)),
(rel_path("b").into(), Some(4)),
]
)
});
@@ -3599,7 +3564,7 @@ async fn test_local_settings(
.local_settings(worktree_b.read(cx).id())
.map(|(path, content)| (path, content.all_languages.defaults.hard_tabs))
.collect::<Vec<_>>(),
&[(Path::new("a").into(), Some(true))],
&[(rel_path("a").into(), Some(true))],
)
});
}
@@ -3636,7 +3601,9 @@ async fn test_buffer_conflict_after_save(
// Open a buffer as client B
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -3700,7 +3667,9 @@ async fn test_buffer_reloading(
// Open a buffer as client B
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -3758,12 +3727,16 @@ async fn test_editing_while_guest_opens_buffer(
// Open a buffer as client A
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
// Start opening the same buffer as client B
let open_buffer = project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx));
let open_buffer = project_b.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
});
let buffer_b = cx_b.executor().spawn(open_buffer);
// Edit the buffer as client A while client B is still opening it.
@@ -3810,7 +3783,9 @@ async fn test_leaving_worktree_while_opening_buffer(
project_a.read_with(cx_a, |p, _| assert_eq!(p.collaborators().len(), 1));
// Begin opening a buffer as client B, but leave the project before the open completes.
let open_buffer = project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx));
let open_buffer = project_b.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
});
let buffer_b = cx_b.executor().spawn(open_buffer);
cx_b.update(|_| drop(project_b));
drop(buffer_b);
@@ -3852,7 +3827,9 @@ async fn test_canceling_buffer_opening(
let project_b = client_b.join_remote_project(project_id, cx_b).await;
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -3928,7 +3905,7 @@ async fn test_leaving_project(
let buffer_b1 = project_b1
.update(cx_b, |project, cx| {
let worktree_id = project.worktrees(cx).next().unwrap().read(cx).id();
project.open_buffer((worktree_id, "a.txt"), cx)
project.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -3966,7 +3943,7 @@ async fn test_leaving_project(
let buffer_b2 = project_b2
.update(cx_b, |project, cx| {
let worktree_id = project.worktrees(cx).next().unwrap().read(cx).id();
project.open_buffer((worktree_id, "a.txt"), cx)
project.open_buffer((worktree_id, rel_path("a.txt")), cx)
})
.await
.unwrap();
@@ -4131,7 +4108,7 @@ async fn test_collaborating_with_diagnostics(
&[(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("a.rs")),
path: rel_path("a.rs").into(),
},
LanguageServerId(0),
DiagnosticSummary {
@@ -4167,7 +4144,7 @@ async fn test_collaborating_with_diagnostics(
&[(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("a.rs")),
path: rel_path("a.rs").into(),
},
LanguageServerId(0),
DiagnosticSummary {
@@ -4208,7 +4185,7 @@ async fn test_collaborating_with_diagnostics(
[(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("a.rs")),
path: rel_path("a.rs").into(),
},
LanguageServerId(0),
DiagnosticSummary {
@@ -4225,7 +4202,7 @@ async fn test_collaborating_with_diagnostics(
[(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("a.rs")),
path: rel_path("a.rs").into(),
},
LanguageServerId(0),
DiagnosticSummary {
@@ -4237,7 +4214,9 @@ async fn test_collaborating_with_diagnostics(
});
// Open the file with the errors on client B. They should be present.
let open_buffer = project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx));
let open_buffer = project_b.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.rs")), cx)
});
let buffer_b = cx_b.executor().spawn(open_buffer).await.unwrap();
buffer_b.read_with(cx_b, |buffer, _| {
@@ -4356,7 +4335,7 @@ async fn test_collaborating_with_lsp_progress_updates_and_diagnostics_ordering(
let project_b = client_b.join_remote_project(project_id, cx_b).await;
let guest_buffers = futures::future::try_join_all(file_names.iter().map(|file_name| {
project_b.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, file_name), cx)
p.open_buffer_with_lsp((worktree_id, rel_path(file_name)), cx)
})
}))
.await
@@ -4454,7 +4433,9 @@ async fn test_reloading_buffer_manually(
.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))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.rs")), cx)
})
.await
.unwrap();
let project_id = active_call_a
@@ -4464,7 +4445,9 @@ async fn test_reloading_buffer_manually(
let project_b = client_b.join_remote_project(project_id, cx_b).await;
let open_buffer = project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx));
let open_buffer = project_b.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.rs")), cx)
});
let buffer_b = cx_b.executor().spawn(open_buffer).await.unwrap();
buffer_b.update(cx_b, |buffer, cx| {
buffer.edit([(4..7, "six")], None, cx);
@@ -4562,7 +4545,9 @@ async fn test_formatting_buffer(
let project_b = client_b.join_remote_project(project_id, cx_b).await;
let buffer_b = project_b
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx))
.update(cx_b, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.rs")), cx)
})
.await
.unwrap();
@@ -4688,7 +4673,9 @@ async fn test_prettier_formatting_buffer(
.await;
let (project_a, worktree_id) = client_a.build_local_project(&directory, cx_a).await;
let prettier_format_suffix = project::TEST_PRETTIER_FORMAT_SUFFIX;
let open_buffer = project_a.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.ts"), cx));
let open_buffer = project_a.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.ts")), cx)
});
let buffer_a = cx_a.executor().spawn(open_buffer).await.unwrap();
let project_id = active_call_a
@@ -4698,7 +4685,7 @@ async fn test_prettier_formatting_buffer(
let project_b = client_b.join_remote_project(project_id, cx_b).await;
let (buffer_b, _) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "a.ts"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("a.ts")), cx)
})
.await
.unwrap();
@@ -4838,7 +4825,7 @@ async fn test_definition(
// Open the file on client B.
let (buffer_b, _handle) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "a.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("a.rs")), cx)
})
.await
.unwrap();
@@ -5016,7 +5003,7 @@ async fn test_references(
// Open the file on client B.
let (buffer_b, _handle) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "one.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("one.rs")), cx)
})
.await
.unwrap();
@@ -5088,7 +5075,7 @@ async fn test_references(
let three_buffer = references[2].buffer.read(cx);
assert_eq!(
two_buffer.file().unwrap().path().as_ref(),
Path::new("two.rs")
rel_path("two.rs")
);
assert_eq!(references[1].buffer, references[0].buffer);
assert_eq!(
@@ -5288,7 +5275,7 @@ async fn test_document_highlights(
// Open the file on client B.
let (buffer_b, _handle) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "main.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
@@ -5431,7 +5418,7 @@ async fn test_lsp_hover(
// Open the file as the guest
let (buffer_b, _handle) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "main.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("main.rs")), cx)
})
.await
.unwrap();
@@ -5623,7 +5610,7 @@ async fn test_project_symbols(
// Cause the language server to start.
let _buffer = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "one.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("one.rs")), cx)
})
.await
.unwrap();
@@ -5673,7 +5660,10 @@ async fn test_project_symbols(
// 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(path!("/code/secrets")).into();
fake_symbol.path = SymbolLocation::OutsideProject {
abs_path: Path::new(path!("/code/secrets")).into(),
signature: [0x17; 32],
};
let error = project_b
.update(cx_b, |project, cx| {
project.open_buffer_for_symbol(&fake_symbol, cx)
@@ -5738,7 +5728,7 @@ async fn test_open_buffer_while_getting_definition_pointing_to_it(
let (buffer_b1, _lsp) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "a.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("a.rs")), cx)
})
.await
.unwrap();
@@ -5763,14 +5753,14 @@ async fn test_open_buffer_while_getting_definition_pointing_to_it(
definitions = project_b.update(cx_b, |p, cx| p.definitions(&buffer_b1, 23, cx));
(buffer_b2, _) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "b.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("b.rs")), cx)
})
.await
.unwrap();
} else {
(buffer_b2, _) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "b.rs"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("b.rs")), cx)
})
.await
.unwrap();
@@ -6587,15 +6577,15 @@ async fn test_preview_tabs(cx: &mut TestAppContext) {
let path_1 = ProjectPath {
worktree_id,
path: Path::new("1.txt").into(),
path: rel_path("1.txt").into(),
};
let path_2 = ProjectPath {
worktree_id,
path: Path::new("2.js").into(),
path: rel_path("2.js").into(),
};
let path_3 = ProjectPath {
worktree_id,
path: Path::new("3.rs").into(),
path: rel_path("3.rs").into(),
};
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
@@ -27,7 +27,11 @@ use std::{
rc::Rc,
sync::Arc,
};
use util::{ResultExt, path};
use util::{
ResultExt, path,
paths::PathStyle,
rel_path::{RelPath, RelPathBuf, rel_path},
};
#[gpui::test(
iterations = 100,
@@ -66,7 +70,7 @@ enum ClientOperation {
OpenBuffer {
project_root_name: String,
is_local: bool,
full_path: PathBuf,
full_path: RelPathBuf,
},
SearchProject {
project_root_name: String,
@@ -77,24 +81,24 @@ enum ClientOperation {
EditBuffer {
project_root_name: String,
is_local: bool,
full_path: PathBuf,
full_path: RelPathBuf,
edits: Vec<(Range<usize>, Arc<str>)>,
},
CloseBuffer {
project_root_name: String,
is_local: bool,
full_path: PathBuf,
full_path: RelPathBuf,
},
SaveBuffer {
project_root_name: String,
is_local: bool,
full_path: PathBuf,
full_path: RelPathBuf,
detach: bool,
},
RequestLspDataInBuffer {
project_root_name: String,
is_local: bool,
full_path: PathBuf,
full_path: RelPathBuf,
offset: usize,
kind: LspRequestKind,
detach: bool,
@@ -102,7 +106,7 @@ enum ClientOperation {
CreateWorktreeEntry {
project_root_name: String,
is_local: bool,
full_path: PathBuf,
full_path: RelPathBuf,
is_dir: bool,
},
WriteFsEntry {
@@ -119,7 +123,7 @@ enum ClientOperation {
enum GitOperation {
WriteGitIndex {
repo_path: PathBuf,
contents: Vec<(PathBuf, String)>,
contents: Vec<(RelPathBuf, String)>,
},
WriteGitBranch {
repo_path: PathBuf,
@@ -127,7 +131,7 @@ enum GitOperation {
},
WriteGitStatuses {
repo_path: PathBuf,
statuses: Vec<(PathBuf, FileStatus)>,
statuses: Vec<(RelPathBuf, FileStatus)>,
},
}
@@ -311,8 +315,8 @@ impl RandomizedTest for ProjectCollaborationTest {
let Some(worktree) = worktree else { continue };
let is_dir = rng.random::<bool>();
let mut full_path =
worktree.read_with(cx, |w, _| PathBuf::from(w.root_name()));
full_path.push(gen_file_name(rng));
worktree.read_with(cx, |w, _| w.root_name().to_rel_path_buf());
full_path.push(rel_path(&gen_file_name(rng)));
if !is_dir {
full_path.set_extension("rs");
}
@@ -346,8 +350,18 @@ impl RandomizedTest for ProjectCollaborationTest {
continue;
};
let full_path = buffer
.read_with(cx, |buffer, cx| buffer.file().unwrap().full_path(cx));
let full_path = buffer.read_with(cx, |buffer, cx| {
let file = buffer.file().unwrap();
let worktree = project
.read(cx)
.worktree_for_id(file.worktree_id(cx), cx)
.unwrap();
worktree
.read(cx)
.root_name()
.join(file.path())
.to_rel_path_buf()
});
match rng.random_range(0..100_u32) {
// Close the buffer
@@ -436,16 +450,16 @@ impl RandomizedTest for ProjectCollaborationTest {
.filter(|e| e.is_file())
.choose(rng)
.unwrap();
if entry.path.as_ref() == Path::new("") {
Path::new(worktree.root_name()).into()
if entry.path.as_ref().is_empty() {
worktree.root_name().into()
} else {
Path::new(worktree.root_name()).join(&entry.path)
worktree.root_name().join(&entry.path)
}
});
break ClientOperation::OpenBuffer {
project_root_name,
is_local,
full_path,
full_path: full_path.to_rel_path_buf(),
};
}
}
@@ -940,7 +954,11 @@ impl RandomizedTest for ProjectCollaborationTest {
}
for (path, _) in contents.iter() {
if !client.fs().files().contains(&repo_path.join(path)) {
if !client
.fs()
.files()
.contains(&repo_path.join(path.as_std_path()))
{
return Err(TestError::Inapplicable);
}
}
@@ -954,8 +972,8 @@ impl RandomizedTest for ProjectCollaborationTest {
let dot_git_dir = repo_path.join(".git");
let contents = contents
.into_iter()
.map(|(path, contents)| (path.into(), contents))
.iter()
.map(|(path, contents)| (path.as_str(), contents.clone()))
.collect::<Vec<_>>();
if client.fs().metadata(&dot_git_dir).await?.is_none() {
client.fs().create_dir(&dot_git_dir).await?;
@@ -993,7 +1011,11 @@ impl RandomizedTest for ProjectCollaborationTest {
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.as_std_path()))
{
return Err(TestError::Inapplicable);
}
}
@@ -1009,7 +1031,7 @@ impl RandomizedTest for ProjectCollaborationTest {
let statuses = statuses
.iter()
.map(|(path, val)| (path.as_path(), *val))
.map(|(path, val)| (path.as_str(), *val))
.collect::<Vec<_>>();
if client.fs().metadata(&dot_git_dir).await?.is_none() {
@@ -1426,7 +1448,7 @@ fn generate_git_operation(rng: &mut StdRng, client: &TestClient) -> GitOperation
repo_path: &Path,
rng: &mut StdRng,
client: &TestClient,
) -> Vec<PathBuf> {
) -> Vec<RelPathBuf> {
let mut paths = client
.fs()
.files()
@@ -1440,7 +1462,11 @@ fn generate_git_operation(rng: &mut StdRng, client: &TestClient) -> GitOperation
paths
.iter()
.map(|path| path.strip_prefix(repo_path).unwrap().to_path_buf())
.map(|path| {
RelPath::from_std_path(path.strip_prefix(repo_path).unwrap(), PathStyle::local())
.unwrap()
.to_rel_path_buf()
})
.collect::<Vec<_>>()
}
@@ -1487,7 +1513,7 @@ fn generate_git_operation(rng: &mut StdRng, client: &TestClient) -> GitOperation
fn buffer_for_full_path(
client: &TestClient,
project: &Entity<Project>,
full_path: &PathBuf,
full_path: &RelPath,
cx: &TestAppContext,
) -> Option<Entity<language::Buffer>> {
client
@@ -1495,7 +1521,12 @@ fn buffer_for_full_path(
.iter()
.find(|buffer| {
buffer.read_with(cx, |buffer, cx| {
buffer.file().unwrap().full_path(cx) == *full_path
let file = buffer.file().unwrap();
let Some(worktree) = project.read(cx).worktree_for_id(file.worktree_id(cx), cx)
else {
return false;
};
worktree.read(cx).root_name().join(&file.path()).as_ref() == full_path
})
})
.cloned()
@@ -1536,23 +1567,23 @@ fn root_name_for_project(project: &Entity<Project>, cx: &TestAppContext) -> Stri
.next()
.unwrap()
.read(cx)
.root_name()
.root_name_str()
.to_string()
})
}
fn project_path_for_full_path(
project: &Entity<Project>,
full_path: &Path,
full_path: &RelPath,
cx: &TestAppContext,
) -> Option<ProjectPath> {
let mut components = full_path.components();
let root_name = components.next().unwrap().as_os_str().to_str().unwrap();
let path = components.as_path().into();
let root_name = components.next().unwrap();
let path = components.rest().into();
let worktree_id = project.read_with(cx, |project, cx| {
project.worktrees(cx).find_map(|worktree| {
let worktree = worktree.read(cx);
if worktree.root_name() == root_name {
if worktree.root_name_str() == root_name {
Some(worktree.id())
} else {
None
@@ -33,7 +33,7 @@ use std::{
sync::{Arc, atomic::AtomicUsize},
};
use task::TcpArgumentsTemplate;
use util::path;
use util::{path, rel_path::rel_path};
#[gpui::test(iterations = 10)]
async fn test_sharing_an_ssh_remote_project(
@@ -124,26 +124,26 @@ async fn test_sharing_an_ssh_remote_project(
worktree_a.update(cx_a, |worktree, _cx| {
assert_eq!(
worktree.paths().map(Arc::as_ref).collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
vec![
Path::new(".zed"),
Path::new(".zed/settings.json"),
Path::new("README.md"),
Path::new("src"),
Path::new("src/lib.rs"),
rel_path(".zed"),
rel_path(".zed/settings.json"),
rel_path("README.md"),
rel_path("src"),
rel_path("src/lib.rs"),
]
);
});
worktree_b.update(cx_b, |worktree, _cx| {
assert_eq!(
worktree.paths().map(Arc::as_ref).collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
vec![
Path::new(".zed"),
Path::new(".zed/settings.json"),
Path::new("README.md"),
Path::new("src"),
Path::new("src/lib.rs"),
rel_path(".zed"),
rel_path(".zed/settings.json"),
rel_path("README.md"),
rel_path("src"),
rel_path("src/lib.rs"),
]
);
});
@@ -151,7 +151,7 @@ async fn test_sharing_an_ssh_remote_project(
// User B can open buffers in the remote project.
let buffer_b = project_b
.update(cx_b, |project, cx| {
project.open_buffer((worktree_id, "src/lib.rs"), cx)
project.open_buffer((worktree_id, rel_path("src/lib.rs")), cx)
})
.await
.unwrap();
@@ -177,7 +177,7 @@ async fn test_sharing_an_ssh_remote_project(
buffer_b.clone(),
ProjectPath {
worktree_id: worktree_id.to_owned(),
path: Arc::from(Path::new("src/renamed.rs")),
path: rel_path("src/renamed.rs").into(),
},
cx,
)
@@ -194,14 +194,8 @@ async fn test_sharing_an_ssh_remote_project(
cx_b.run_until_parked();
cx_b.update(|cx| {
assert_eq!(
buffer_b
.read(cx)
.file()
.unwrap()
.path()
.to_string_lossy()
.to_string(),
path!("src/renamed.rs").to_string()
buffer_b.read(cx).file().unwrap().path().as_ref(),
rel_path("src/renamed.rs")
);
});
}
@@ -489,7 +483,7 @@ async fn test_ssh_collaboration_formatting_with_prettier(
// Opens the buffer and formats it
let (buffer_b, _handle) = project_b
.update(cx_b, |p, cx| {
p.open_buffer_with_lsp((worktree_id, "a.ts"), cx)
p.open_buffer_with_lsp((worktree_id, rel_path("a.ts")), cx)
})
.await
.expect("user B opens buffer for formatting");
@@ -547,7 +541,9 @@ async fn test_ssh_collaboration_formatting_with_prettier(
// User A opens and formats the same buffer too
let buffer_a = project_a
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.ts"), cx))
.update(cx_a, |p, cx| {
p.open_buffer((worktree_id, rel_path("a.ts")), cx)
})
.await
.expect("user A opens buffer for formatting");