Clean up RelPath API (#38912)

Consolidate constructors and accessors.

Release Notes:

- N/A

---------

Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Max Brunsfeld
2025-09-25 14:42:32 -07:00
committed by GitHub
co-authored by Cole Miller
parent 301e976465
commit 495a7b0a84
70 changed files with 483 additions and 408 deletions
+12 -12
View File
@@ -1408,12 +1408,12 @@ async fn test_share_project(
project_b.read_with(cx_b, |project, cx| {
let worktree = project.worktrees(cx).next().unwrap().read(cx);
assert_eq!(
worktree.paths().map(AsRef::as_ref).collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
[
Path::new(".gitignore"),
Path::new("a.txt"),
Path::new("b.txt"),
Path::new("ignored-dir"),
rel_path(".gitignore"),
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("ignored-dir"),
]
);
});
@@ -1433,14 +1433,14 @@ async fn test_share_project(
project_b.read_with(cx_b, |project, cx| {
let worktree = project.worktrees(cx).next().unwrap().read(cx);
assert_eq!(
worktree.paths().map(AsRef::as_ref).collect::<Vec<_>>(),
worktree.paths().collect::<Vec<_>>(),
[
Path::new(".gitignore"),
Path::new("a.txt"),
Path::new("b.txt"),
Path::new("ignored-dir"),
Path::new("ignored-dir/c.txt"),
Path::new("ignored-dir/d.txt"),
rel_path(".gitignore"),
rel_path("a.txt"),
rel_path("b.txt"),
rel_path("ignored-dir"),
rel_path("ignored-dir/c.txt"),
rel_path("ignored-dir/d.txt"),
]
);
});
+25 -5
View File
@@ -632,13 +632,16 @@ 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.as_str().to_owned())
.map(|item| item.project_path(cx).unwrap().path)
.collect::<Vec<_>>()
})
};
//Verify that the tabs opened in the order we expect
assert_eq!(&pane_paths(&pane_a, cx_a), &["1.txt", "3.txt"]);
assert_eq!(
&pane_paths(&pane_a, cx_a),
&[rel_path("1.txt").into(), rel_path("3.txt").into()]
);
//Follow client B as client A
workspace_a.update_in(cx_a, |workspace, window, cx| {
@@ -656,7 +659,14 @@ async fn test_following_tab_order(
executor.run_until_parked();
// Verify that newly opened followed file is at the end
assert_eq!(&pane_paths(&pane_a, cx_a), &["1.txt", "3.txt", "2.txt"]);
assert_eq!(
&pane_paths(&pane_a, cx_a),
&[
rel_path("1.txt").into(),
rel_path("3.txt").into(),
rel_path("2.txt").into()
]
);
//Open just 1 on client B
workspace_b
@@ -665,11 +675,21 @@ async fn test_following_tab_order(
})
.await
.unwrap();
assert_eq!(&pane_paths(&pane_b, cx_b), &["2.txt", "1.txt"]);
assert_eq!(
&pane_paths(&pane_b, cx_b),
&[rel_path("2.txt").into(), rel_path("1.txt").into()]
);
executor.run_until_parked();
// Verify that following into 1 did not reorder
assert_eq!(&pane_paths(&pane_a, cx_a), &["1.txt", "3.txt", "2.txt"]);
assert_eq!(
&pane_paths(&pane_a, cx_a),
&[
rel_path("1.txt").into(),
rel_path("3.txt").into(),
rel_path("2.txt").into()
]
);
}
#[gpui::test(iterations = 10)]
+47 -32
View File
@@ -1699,13 +1699,8 @@ async fn test_project_reconnect(
);
assert!(worktree_a3.read(cx).has_update_observer());
assert_eq!(
worktree_a3
.read(cx)
.snapshot()
.paths()
.map(|p| p.as_str())
.collect::<Vec<_>>(),
vec!["w.txt", "x.txt", "y.txt"]
worktree_a3.read(cx).snapshot().paths().collect::<Vec<_>>(),
vec![rel_path("w.txt"), rel_path("x.txt"), rel_path("y.txt")]
);
});
@@ -1737,9 +1732,8 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.as_str())
.collect::<Vec<_>>(),
vec!["w.txt", "x.txt", "y.txt"]
vec![rel_path("w.txt"), rel_path("x.txt"), rel_path("y.txt")]
);
});
@@ -1833,7 +1827,7 @@ async fn test_project_reconnect(
.read(cx)
.snapshot()
.paths()
.map(|p| p.as_str())
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
vec!["z.txt"]
);
@@ -2471,39 +2465,39 @@ async fn test_propagate_saves_and_fs_changes(
worktree_a.read_with(cx_a, |tree, _| {
assert_eq!(
tree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["file1.js", "file3", "file4"]
tree.paths().collect::<Vec<_>>(),
[rel_path("file1.js"), rel_path("file3"), rel_path("file4")]
)
});
worktree_b.read_with(cx_b, |tree, _| {
assert_eq!(
tree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["file1.js", "file3", "file4"]
tree.paths().collect::<Vec<_>>(),
[rel_path("file1.js"), rel_path("file3"), rel_path("file4")]
)
});
worktree_c.read_with(cx_c, |tree, _| {
assert_eq!(
tree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["file1.js", "file3", "file4"]
tree.paths().collect::<Vec<_>>(),
[rel_path("file1.js"), rel_path("file3"), rel_path("file4")]
)
});
// Ensure buffer files are updated as well.
buffer_a.read_with(cx_a, |buffer, _| {
assert_eq!(buffer.file().unwrap().path().as_str(), "file1.js");
assert_eq!(buffer.file().unwrap().path().as_ref(), rel_path("file1.js"));
assert_eq!(buffer.language().unwrap().name(), "JavaScript".into());
});
buffer_b.read_with(cx_b, |buffer, _| {
assert_eq!(buffer.file().unwrap().path().as_str(), "file1.js");
assert_eq!(buffer.file().unwrap().path().as_ref(), rel_path("file1.js"));
assert_eq!(buffer.language().unwrap().name(), "JavaScript".into());
});
buffer_c.read_with(cx_c, |buffer, _| {
assert_eq!(buffer.file().unwrap().path().as_str(), "file1.js");
assert_eq!(buffer.file().unwrap().path().as_ref(), rel_path("file1.js"));
assert_eq!(buffer.language().unwrap().name(), "JavaScript".into());
});
@@ -3217,15 +3211,15 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "c.txt"]
worktree.paths().collect::<Vec<_>>(),
[rel_path("a.txt"), rel_path("b.txt"), rel_path("c.txt")]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "c.txt"]
worktree.paths().collect::<Vec<_>>(),
[rel_path("a.txt"), rel_path("b.txt"), rel_path("c.txt")]
);
});
@@ -3240,14 +3234,17 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt"]
worktree.paths().collect::<Vec<_>>(),
[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.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt"]
);
});
@@ -3263,14 +3260,20 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
["DIR", "a.txt", "b.txt", "d.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
["DIR", "a.txt", "b.txt", "d.txt"]
);
});
@@ -3386,14 +3389,20 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_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.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
["a.txt", "b.txt", "d.txt", "f.txt"]
);
});
@@ -3407,14 +3416,20 @@ async fn test_fs_operations(
worktree_a.read_with(cx_a, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
["a.txt", "b.txt", "f.txt"]
);
});
worktree_b.read_with(cx_b, |worktree, _| {
assert_eq!(
worktree.paths().map(|p| p.as_str()).collect::<Vec<_>>(),
worktree
.paths()
.map(|p| p.as_unix_str())
.collect::<Vec<_>>(),
["a.txt", "b.txt", "f.txt"]
);
});
@@ -973,7 +973,7 @@ impl RandomizedTest for ProjectCollaborationTest {
let dot_git_dir = repo_path.join(".git");
let contents = contents
.iter()
.map(|(path, contents)| (path.as_str(), contents.clone()))
.map(|(path, contents)| (path.as_unix_str(), contents.clone()))
.collect::<Vec<_>>();
if client.fs().metadata(&dot_git_dir).await?.is_none() {
client.fs().create_dir(&dot_git_dir).await?;
@@ -1031,7 +1031,7 @@ impl RandomizedTest for ProjectCollaborationTest {
let statuses = statuses
.iter()
.map(|(path, val)| (path.as_str(), *val))
.map(|(path, val)| (path.as_unix_str(), *val))
.collect::<Vec<_>>();
if client.fs().metadata(&dot_git_dir).await?.is_none() {
@@ -1463,7 +1463,7 @@ fn generate_git_operation(rng: &mut StdRng, client: &TestClient) -> GitOperation
paths
.iter()
.map(|path| {
RelPath::from_std_path(path.strip_prefix(repo_path).unwrap(), PathStyle::local())
RelPath::new(path.strip_prefix(repo_path).unwrap(), PathStyle::local())
.unwrap()
.to_rel_path_buf()
})