diff --git a/Cargo.lock b/Cargo.lock index 1aab9dfae0c66e5c8cce3ac14374cabccfac9a4b..2a33d3d16893655a1a0f81614448875d6b558141 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17528,6 +17528,7 @@ dependencies = [ "libc", "log", "nix 0.29.0", + "pretty_assertions", "rand 0.9.1", "regex", "rust-embed", diff --git a/crates/agent/src/thread_store.rs b/crates/agent/src/thread_store.rs index fe73b959b7fbe96f139a2b8267748c78cce88e2e..91b2f3b684bbbe9e3849e5b27c3a962a137869c5 100644 --- a/crates/agent/src/thread_store.rs +++ b/crates/agent/src/thread_store.rs @@ -235,7 +235,7 @@ impl ThreadStore { if items.iter().any(|(path, _, _)| { RULES_FILE_NAMES .iter() - .any(|name| path.as_ref() == RelPath::new(name).unwrap()) + .any(|name| path.as_ref() == RelPath::unix(name).unwrap()) }) { self.enqueue_system_prompt_reload(); } @@ -368,7 +368,7 @@ impl ThreadStore { .into_iter() .filter_map(|name| { worktree - .entry_for_path(RelPath::new(name).unwrap()) + .entry_for_path(RelPath::unix(name).unwrap()) .filter(|entry| entry.is_file()) .map(|entry| entry.path.clone()) }) diff --git a/crates/agent2/src/agent.rs b/crates/agent2/src/agent.rs index 7fb7a114cfaa28bfa678a2b9bfe79545218a9d5b..fe47c66feac33f5f9ddfc46c3c192bc5c54477a0 100644 --- a/crates/agent2/src/agent.rs +++ b/crates/agent2/src/agent.rs @@ -475,7 +475,7 @@ impl NativeAgent { .into_iter() .filter_map(|name| { worktree - .entry_for_path(RelPath::new(name).unwrap()) + .entry_for_path(RelPath::unix(name).unwrap()) .filter(|entry| entry.is_file()) .map(|entry| entry.path.clone()) }) @@ -559,7 +559,7 @@ impl NativeAgent { if items.iter().any(|(path, _, _)| { RULES_FILE_NAMES .iter() - .any(|name| path.as_ref() == RelPath::new(name).unwrap()) + .any(|name| path.as_ref() == RelPath::unix(name).unwrap()) }) { self.project_context_needs_refresh.send(()).ok(); } diff --git a/crates/agent2/src/tools/edit_file_tool.rs b/crates/agent2/src/tools/edit_file_tool.rs index 9f2e8e3e313c1a0fbf32e8fe2b3da0c0d822ad69..3b1bf6f408e88ed0e6bf80b0b55815d122ab1854 100644 --- a/crates/agent2/src/tools/edit_file_tool.rs +++ b/crates/agent2/src/tools/edit_file_tool.rs @@ -541,7 +541,7 @@ fn resolve_path( .path .file_name() .and_then(|file_name| file_name.to_str()) - .and_then(|file_name| RelPath::new(file_name).ok()) + .and_then(|file_name| RelPath::unix(file_name).ok()) .context("Can't create file: invalid filename")?; let new_file_path = parent_project_path.map(|parent| ProjectPath { @@ -565,7 +565,7 @@ mod tests { use prompt_store::ProjectContext; use serde_json::json; use settings::SettingsStore; - use util::path; + use util::{path, rel_path::rel_path}; #[gpui::test] async fn test_edit_nonexistent_file(cx: &mut TestAppContext) { @@ -614,13 +614,13 @@ mod tests { let mode = &EditFileMode::Create; let result = test_resolve_path(mode, "root/new.txt", cx); - assert_resolved_path_eq(result.await, "new.txt"); + assert_resolved_path_eq(result.await, rel_path("new.txt")); let result = test_resolve_path(mode, "new.txt", cx); - assert_resolved_path_eq(result.await, "new.txt"); + assert_resolved_path_eq(result.await, rel_path("new.txt")); let result = test_resolve_path(mode, "dir/new.txt", cx); - assert_resolved_path_eq(result.await, "dir/new.txt"); + assert_resolved_path_eq(result.await, rel_path("dir/new.txt")); let result = test_resolve_path(mode, "root/dir/subdir/existing.txt", cx); assert_eq!( @@ -642,10 +642,10 @@ mod tests { let path_with_root = "root/dir/subdir/existing.txt"; let path_without_root = "dir/subdir/existing.txt"; let result = test_resolve_path(mode, path_with_root, cx); - assert_resolved_path_eq(result.await, path_without_root); + assert_resolved_path_eq(result.await, rel_path(path_without_root)); let result = test_resolve_path(mode, path_without_root, cx); - assert_resolved_path_eq(result.await, path_without_root); + assert_resolved_path_eq(result.await, rel_path(path_without_root)); let result = test_resolve_path(mode, "root/nonexistent.txt", cx); assert_eq!( @@ -691,10 +691,9 @@ mod tests { } #[track_caller] - fn assert_resolved_path_eq(path: anyhow::Result, expected: &str) { + fn assert_resolved_path_eq(path: anyhow::Result, expected: &RelPath) { let actual = path.expect("Should return valid path").path; - let actual = actual.as_str(); - assert_eq!(actual, expected); + assert_eq!(actual.as_ref(), expected); } #[gpui::test] diff --git a/crates/assistant_slash_commands/src/file_command.rs b/crates/assistant_slash_commands/src/file_command.rs index afb3d942fefe13b679cf9fbe7b711dfe32eb0195..53a631e68f73b151ea830c9ba6594c95014f2e4b 100644 --- a/crates/assistant_slash_commands/src/file_command.rs +++ b/crates/assistant_slash_commands/src/file_command.rs @@ -290,7 +290,7 @@ fn collect_files( folded_directory_names.join(&path_including_worktree_name); } else { folded_directory_names = - folded_directory_names.join(RelPath::new(&filename).unwrap()); + folded_directory_names.join(RelPath::unix(&filename).unwrap()); } continue; } @@ -320,7 +320,7 @@ fn collect_files( directory_stack.push(entry.path.clone()); } else { let entry_name = - folded_directory_names.join(RelPath::new(&filename).unwrap()); + folded_directory_names.join(RelPath::unix(&filename).unwrap()); let entry_name = entry_name.display(path_style); events_tx.unbounded_send(Ok(SlashCommandEvent::StartSection { icon: IconName::Folder, @@ -505,7 +505,7 @@ mod custom_path_matcher { .iter() .zip(self.sources_with_trailing_slash.iter()) .any(|(source, with_slash)| { - let as_bytes = other.as_str().as_bytes(); + let as_bytes = other.as_unix_str().as_bytes(); let with_slash = if source.ends_with('/') { source.as_bytes() } else { @@ -514,12 +514,12 @@ mod custom_path_matcher { as_bytes.starts_with(with_slash) || as_bytes.ends_with(source.as_bytes()) }) - || self.glob.is_match(other) + || self.glob.is_match(other.as_std_path()) || self.check_with_end_separator(other) } fn check_with_end_separator(&self, path: &RelPath) -> bool { - let path_str = path.as_str(); + let path_str = path.as_unix_str(); let separator = "/"; if path_str.ends_with(separator) { false diff --git a/crates/assistant_tools/src/edit_file_tool.rs b/crates/assistant_tools/src/edit_file_tool.rs index f7ed5e28bf8cf8e4d1452620c7c13732ad28ff8f..c8b7add0b8f17f70d2157681b3ae115535a7616e 100644 --- a/crates/assistant_tools/src/edit_file_tool.rs +++ b/crates/assistant_tools/src/edit_file_tool.rs @@ -554,7 +554,7 @@ fn resolve_path( .context("Can't create file: invalid filename")?; let new_file_path = parent_project_path.map(|parent| ProjectPath { - path: parent.path.join(RelPath::new(file_name).unwrap()), + path: parent.path.join(RelPath::unix(file_name).unwrap()), ..parent }); diff --git a/crates/assistant_tools/src/list_directory_tool.rs b/crates/assistant_tools/src/list_directory_tool.rs index d46ac3ac0dc6bd1210472cad13acadd4ce209def..7d70f41a8c5000b433d47e8caa2a60d3a8024b99 100644 --- a/crates/assistant_tools/src/list_directory_tool.rs +++ b/crates/assistant_tools/src/list_directory_tool.rs @@ -86,6 +86,7 @@ impl Tool for ListDirectoryTool { _window: Option, cx: &mut App, ) -> ToolResult { + let path_style = project.read(cx).path_style(cx); let input = match serde_json::from_value::(input) { Ok(input) => input, Err(err) => return Task::ready(Err(anyhow!(err))).into(), @@ -100,7 +101,7 @@ impl Tool for ListDirectoryTool { .filter_map(|worktree| { worktree.read(cx).root_entry().and_then(|entry| { if entry.is_dir() { - Some(entry.path.as_str()) + Some(entry.path.display(path_style)) } else { None } diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 5d43b4543c2e28b07953567f3eb54d19e8b218b5..35c8d0d7d022a96068914a10898d88c46f8dabd6 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -858,7 +858,7 @@ mod tests { .enumerate() .filter_map(|(i, path)| { Some(( - Arc::from(RelPath::new(path).ok()?), + Arc::from(RelPath::unix(path).ok()?), ProjectEntryId::from_proto(i as u64 + 1), PathChange::Added, )) diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index 947af01224fdc55284dc3a8166f652a9782d5e5f..5ead2cd1d1b0bd2e224cff8db71fe2908c9da060 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -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::>(), + worktree.paths().collect::>(), [ - 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::>(), + worktree.paths().collect::>(), [ - 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"), ] ); }); diff --git a/crates/collab/src/tests/following_tests.rs b/crates/collab/src/tests/following_tests.rs index 1bf0a28e341cf1e74dd12d962f875eb18f4474db..6f4a819f440929a9cc004cc018169420f758d264 100644 --- a/crates/collab/src/tests/following_tests.rs +++ b/crates/collab/src/tests/following_tests.rs @@ -632,13 +632,16 @@ async fn test_following_tab_order( let pane_paths = |pane: &Entity, 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::>() }) }; //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)] diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index 93c3665c11edebcb371dc8f1b819f84c00b2dda8..98acecb1088b75aaec6b07d75d95c67517b56779 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -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!["w.txt", "x.txt", "y.txt"] + worktree_a3.read(cx).snapshot().paths().collect::>(), + 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!["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!["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::>(), - ["file1.js", "file3", "file4"] + tree.paths().collect::>(), + [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::>(), - ["file1.js", "file3", "file4"] + tree.paths().collect::>(), + [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::>(), - ["file1.js", "file3", "file4"] + tree.paths().collect::>(), + [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::>(), - ["a.txt", "b.txt", "c.txt"] + worktree.paths().collect::>(), + [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::>(), - ["a.txt", "b.txt", "c.txt"] + worktree.paths().collect::>(), + [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::>(), - ["a.txt", "b.txt", "d.txt"] + worktree.paths().collect::>(), + [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::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["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::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["DIR", "a.txt", "b.txt", "d.txt"] ); }); worktree_b.read_with(cx_b, |worktree, _| { assert_eq!( - worktree.paths().map(|p| p.as_str()).collect::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["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::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["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::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["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::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["a.txt", "b.txt", "f.txt"] ); }); worktree_b.read_with(cx_b, |worktree, _| { assert_eq!( - worktree.paths().map(|p| p.as_str()).collect::>(), + worktree + .paths() + .map(|p| p.as_unix_str()) + .collect::>(), ["a.txt", "b.txt", "f.txt"] ); }); diff --git a/crates/collab/src/tests/random_project_collaboration_tests.rs b/crates/collab/src/tests/random_project_collaboration_tests.rs index 0cc4a4eadea213dc4f40d14be2cdf379915686c7..7e9b84c0571ed6dff19702ce3532c45d56f6413f 100644 --- a/crates/collab/src/tests/random_project_collaboration_tests.rs +++ b/crates/collab/src/tests/random_project_collaboration_tests.rs @@ -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::>(); 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::>(); 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() }) diff --git a/crates/dap_adapters/src/python.rs b/crates/dap_adapters/src/python.rs index 468edf5664f1a56c45ea5308747be2b8bcd0a468..5a6bd729ce4cf174822f7977fd0e86b826d45601 100644 --- a/crates/dap_adapters/src/python.rs +++ b/crates/dap_adapters/src/python.rs @@ -726,7 +726,7 @@ impl DebugAdapter for PythonDebugAdapter { .config .get("cwd") .and_then(|cwd| { - RelPath::from_std_path( + RelPath::new( cwd.as_str() .map(Path::new)? .strip_prefix(delegate.worktree_root_path()) @@ -740,7 +740,7 @@ impl DebugAdapter for PythonDebugAdapter { .toolchain_store() .active_toolchain( delegate.worktree_id(), - base_path, + base_path.into_arc(), language::LanguageName::new(Self::LANGUAGE_NAME), cx, ) diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index 57f17e577e82bc8f97c6d9a82544324182e3d2f9..9154047aa54b43a726834e62a3a4a397ae91d74b 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -1062,10 +1062,10 @@ impl DebugPanel { directory_in_worktree: dir, .. } => { - let relative_path = if dir.ends_with(RelPath::new(".vscode").unwrap()) { - dir.join(RelPath::new("launch.json").unwrap()) + let relative_path = if dir.ends_with(RelPath::unix(".vscode").unwrap()) { + dir.join(RelPath::unix("launch.json").unwrap()) } else { - dir.join(RelPath::new("debug.json").unwrap()) + dir.join(RelPath::unix("debug.json").unwrap()) }; ProjectPath { worktree_id: id, @@ -1136,7 +1136,7 @@ impl DebugPanel { } path.pop(); - path.push(paths::local_debug_file_relative_path()); + path.push(paths::local_debug_file_relative_path().as_std_path()); let path = path.as_path(); if !fs.is_file(path).await { diff --git a/crates/debugger_ui/src/new_process_modal.rs b/crates/debugger_ui/src/new_process_modal.rs index 2ee8d13732f09c517015437691aae659d7449f5c..cb8edb88b5d108a48d919bb17cb1f320a6c9bdaa 100644 --- a/crates/debugger_ui/src/new_process_modal.rs +++ b/crates/debugger_ui/src/new_process_modal.rs @@ -1037,10 +1037,10 @@ impl DebugDelegate { match path.components().next_back() { Some(".zed") => { - path.push(RelPath::new("debug.json").unwrap()); + path.push(RelPath::unix("debug.json").unwrap()); } Some(".vscode") => { - path.push(RelPath::new("launch.json").unwrap()); + path.push(RelPath::unix("launch.json").unwrap()); } _ => {} } @@ -1133,7 +1133,7 @@ impl DebugDelegate { id: _, directory_in_worktree: dir, id_base: _, - } => dir.ends_with(RelPath::new(".zed").unwrap()), + } => dir.ends_with(RelPath::unix(".zed").unwrap()), _ => false, }); @@ -1154,7 +1154,7 @@ impl DebugDelegate { id_base: _, } => { !(hide_vscode - && dir.ends_with(RelPath::new(".vscode").unwrap())) + && dir.ends_with(RelPath::unix(".vscode").unwrap())) } _ => true, }) diff --git a/crates/debugger_ui/src/session/running/breakpoint_list.rs b/crates/debugger_ui/src/session/running/breakpoint_list.rs index f0f86b124a711922a452afc1a74cd4cab9fe28fd..cec906e293485f3ab7b3685f65834d2b143ef8e2 100644 --- a/crates/debugger_ui/src/session/running/breakpoint_list.rs +++ b/crates/debugger_ui/src/session/running/breakpoint_list.rs @@ -682,10 +682,11 @@ impl Render for BreakpointList { breakpoints.into_iter().filter_map(move |breakpoint| { debug_assert_eq!(&path, &breakpoint.path); let file_name = breakpoint.path.file_name()?; + let breakpoint_path = RelPath::new(&breakpoint.path, path_style).ok(); let dir = relative_worktree_path - .clone() - .or_else(|| RelPath::from_std_path(&breakpoint.path, path_style).ok())? + .as_deref() + .or(breakpoint_path.as_deref())? .parent() .map(|parent| SharedString::from(parent.display(path_style).to_string())); let name = file_name diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index df1640a716b3e5dae648f33aabac4d0aefecb02e..b85998c6b821560df8abc17e8ef4bb01ca1a7b6e 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -20905,7 +20905,10 @@ async fn test_display_diff_hunks(cx: &mut TestAppContext) { for buffer in &buffers { let snapshot = buffer.read(cx).snapshot(); multibuffer.set_excerpts_for_path( - PathKey::namespaced(0, buffer.read(cx).file().unwrap().path().as_str().into()), + PathKey::namespaced( + 0, + buffer.read(cx).file().unwrap().path().as_unix_str().into(), + ), buffer.clone(), vec![text::Anchor::MIN.to_point(&snapshot)..text::Anchor::MAX.to_point(&snapshot)], 2, diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rs index 06fd01c85f8d2371a9ff181b6720e25353a396c7..8cf160837420a67a76e7b72a135ed0795191e5d3 100644 --- a/crates/editor/src/test/editor_test_context.rs +++ b/crates/editor/src/test/editor_test_context.rs @@ -296,7 +296,7 @@ impl EditorTestContext { let path = self.update_buffer(|buffer, _| buffer.file().unwrap().path().clone()); fs.set_head_for_repo( &Self::root_path().join(".git"), - &[(path.as_str(), diff_base.to_string())], + &[(path.as_unix_str(), diff_base.to_string())], "deadbeef", ); self.cx.run_until_parked(); @@ -317,7 +317,7 @@ impl EditorTestContext { let path = self.update_buffer(|buffer, _| buffer.file().unwrap().path().clone()); fs.set_index_for_repo( &Self::root_path().join(".git"), - &[(path.as_str(), diff_base.to_string())], + &[(path.as_unix_str(), diff_base.to_string())], ); self.cx.run_until_parked(); } diff --git a/crates/eval/src/examples/add_arg_to_trait_method.rs b/crates/eval/src/examples/add_arg_to_trait_method.rs index 0626be5a4e2d620337e1bd8896e25f519de86811..41fa7c3dc6361c25868e2bbe73b71010b5d07d80 100644 --- a/crates/eval/src/examples/add_arg_to_trait_method.rs +++ b/crates/eval/src/examples/add_arg_to_trait_method.rs @@ -67,7 +67,7 @@ impl Example for AddArgToTraitMethod { for tool_name in add_ignored_window_paths { let path_str = format!("crates/assistant_tools/src/{}.rs", tool_name); - let edits = edits.get(RelPath::new(&path_str).unwrap()); + let edits = edits.get(RelPath::unix(&path_str).unwrap()); let ignored = edits.is_some_and(|edits| { edits.has_added_line(" _window: Option,\n") @@ -86,7 +86,7 @@ impl Example for AddArgToTraitMethod { // Adds unignored argument to `batch_tool` let batch_tool_edits = - edits.get(RelPath::new("crates/assistant_tools/src/batch_tool.rs").unwrap()); + edits.get(RelPath::unix("crates/assistant_tools/src/batch_tool.rs").unwrap()); cx.assert( batch_tool_edits.is_some_and(|edits| { diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs index 16e695f04fc52b307a08ffce48bfcca77ba816c0..73207b30366565df1584b259bfd0712b6d1f6ae1 100644 --- a/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs +++ b/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs @@ -425,7 +425,7 @@ impl ExtensionImports for WasmState { let location = location.as_ref().and_then(|location| { Some(::settings::SettingsLocation { worktree_id: WorktreeId::from_proto(location.worktree_id), - path: RelPath::new(&location.path).ok()?, + path: RelPath::unix(&location.path).ok()?, }) }); diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs index 9e608b9e8e68ee93cfcb47c39708a8a0c2499d71..861f73f4a4e766932b92a869a52b8174a206cdda 100644 --- a/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs +++ b/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs @@ -564,7 +564,7 @@ impl HostWorktree for WasmState { ) -> wasmtime::Result> { let delegate = self.table.get(&delegate)?; Ok(delegate - .read_text_file(RelPath::new(&path)?) + .read_text_file(RelPath::unix(&path)?) .await .map_err(|error| error.to_string())) } @@ -917,7 +917,7 @@ impl ExtensionImports for WasmState { let location = location.as_ref().and_then(|location| { Some(::settings::SettingsLocation { worktree_id: WorktreeId::from_proto(location.worktree_id), - path: RelPath::new(&location.path).ok()?, + path: RelPath::unix(&location.path).ok()?, }) }); diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 4cc7f1d664c8c743cf19404ab6858369735c0abd..08c54dabc23b44140404072c97fcb38f86bee947 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -666,7 +666,7 @@ impl Matches { } if let Some(filename) = panel_match.0.path.file_name() { - let path_str = panel_match.0.path.as_str(); + let path_str = panel_match.0.path.as_unix_str(); if let Some(filename_pos) = path_str.rfind(filename) && panel_match.0.positions[0] >= filename_pos @@ -940,7 +940,7 @@ impl FileFinderDelegate { let path_style = self.project.read(cx).path_style(cx); let query_path = query.raw_query.as_str(); - if let Ok(mut query_path) = RelPath::from_std_path(Path::new(query_path), path_style) { + if let Ok(mut query_path) = RelPath::new(Path::new(query_path), path_style) { let available_worktree = self .project .read(cx) @@ -953,7 +953,7 @@ impl FileFinderDelegate { let worktree_root = worktree.read(cx).root_name(); if worktree_count > 1 { if let Ok(suffix) = query_path.strip_prefix(worktree_root) { - query_path = suffix.into(); + query_path = Cow::Owned(suffix.to_owned()); expect_worktree = Some(worktree); break; } @@ -973,7 +973,7 @@ impl FileFinderDelegate { { self.matches.matches.push(Match::CreateNew(ProjectPath { worktree_id: worktree.id(), - path: query_path, + path: query_path.into_arc(), })); } } @@ -1128,7 +1128,7 @@ impl FileFinderDelegate { let mut path_positions = path_match.positions.clone(); let file_name = full_path.file_name().unwrap_or(""); - let file_name_start = full_path.as_str().len() - file_name.len(); + let file_name_start = full_path.as_unix_str().len() - file_name.len(); let file_name_positions = path_positions .iter() .filter_map(|pos| { @@ -1325,7 +1325,7 @@ impl PickerDelegate for FileFinderDelegate { .all(|worktree| { worktree .read(cx) - .entry_for_path(RelPath::new(prefix.split_at(1).0).unwrap()) + .entry_for_path(RelPath::unix(prefix.split_at(1).0).unwrap()) .is_none_or(|entry| !entry.is_dir()) }) { diff --git a/crates/file_finder/src/file_finder_tests.rs b/crates/file_finder/src/file_finder_tests.rs index 75b2101101bcdddf4112f6ea1f3d864f71924aa2..dffbaff7978c9267f814d5250fd8c167c4a2bd10 100644 --- a/crates/file_finder/src/file_finder_tests.rs +++ b/crates/file_finder/src/file_finder_tests.rs @@ -2192,7 +2192,7 @@ async fn test_nonexistent_history_items_not_shown(cx: &mut gpui::TestAppContext) collect_search_matches(picker).history, vec![ rel_path("test/first.rs").into(), - rel_path("test/third.rs").into(), + rel_path("test/third.rs").into() ], "Should have all opened files in the history, except the ones that do not exist on disk" ); diff --git a/crates/fs/src/fake_git_repo.rs b/crates/fs/src/fake_git_repo.rs index 940210a7105a38baf472eafc4638f955b4acc6ae..91c7113214adc6af722739e946588838b7bdd7a6 100644 --- a/crates/fs/src/fake_git_repo.rs +++ b/crates/fs/src/fake_git_repo.rs @@ -226,7 +226,7 @@ impl GitRepository for FakeGitRepository { .read_file_sync(path) .ok() .map(|content| String::from_utf8(content).unwrap())?; - let repo_path = RelPath::from_std_path(repo_path, PathStyle::local()).ok()?; + let repo_path = RelPath::new(repo_path, PathStyle::local()).ok()?; Some((repo_path.into(), (content, is_ignored))) }) .collect(); diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index a1ee23cf5f33ea20d479d534d87596701dac1a16..11ff637ad4316499c95a1bd032daa48b72766eb2 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -1671,10 +1671,10 @@ impl FakeFs { for (path, content) in workdir_contents { use util::{paths::PathStyle, rel_path::RelPath}; - let repo_path: RepoPath = RelPath::from_std_path(path.strip_prefix(&workdir_path).unwrap(), PathStyle::local()).unwrap().into(); + let repo_path: RepoPath = RelPath::new(path.strip_prefix(&workdir_path).unwrap(), PathStyle::local()).unwrap().into(); let status = statuses .iter() - .find_map(|(p, status)| (*p == repo_path.as_str()).then_some(status)); + .find_map(|(p, status)| (*p == repo_path.as_unix_str()).then_some(status)); let mut content = String::from_utf8_lossy(&content).to_string(); let mut index_content = None; diff --git a/crates/fuzzy/src/paths.rs b/crates/fuzzy/src/paths.rs index fa6d3f850465e62106d2b84f8f0a9be56c4ca19d..6fc52361e37750400aa308733865fc6fee435134 100644 --- a/crates/fuzzy/src/paths.rs +++ b/crates/fuzzy/src/paths.rs @@ -52,7 +52,7 @@ impl<'a> MatchCandidate for PathMatchCandidate<'a> { } fn candidate_chars(&self) -> impl Iterator { - self.path.as_str().chars() + self.path.as_unix_str().chars() } } @@ -184,8 +184,11 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>( let candidates = candidate_set.candidates(start).take(end - start); let worktree_id = candidate_set.id(); - let mut prefix = - candidate_set.prefix().as_str().chars().collect::>(); + let mut prefix = candidate_set + .prefix() + .as_unix_str() + .chars() + .collect::>(); if !candidate_set.root_is_file() && !prefix.is_empty() { prefix.push('/'); } diff --git a/crates/git/src/blame.rs b/crates/git/src/blame.rs index a06d5081b77672a7578e6fc74c6db56dd9705471..e58b9cb7e0427bf3af1c88f473debba0b6f94f59 100644 --- a/crates/git/src/blame.rs +++ b/crates/git/src/blame.rs @@ -77,7 +77,7 @@ async fn run_git_blame( .arg("-w") .arg("--contents") .arg("-") - .arg(path.as_str()) + .arg(path.as_unix_str()) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index b455f5b14c7b1bb90fe93ecd94e51c4907a5d36f..570899986020a3ecc185beadd747ab0b5fea2460 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -12,6 +12,7 @@ use parking_lot::Mutex; use rope::Rope; use schemars::JsonSchema; use serde::Deserialize; +use std::borrow::Cow; use std::ffi::{OsStr, OsString}; use std::io::prelude::*; use std::process::{ExitStatus, Stdio}; @@ -719,7 +720,7 @@ impl GitRepository for RealGitRepository { let mut newline = [b'\0']; for (path, status_code) in changes { // git-show outputs `/`-delimited paths even on Windows. - let Ok(rel_path) = RelPath::new(path) else { + let Some(rel_path) = RelPath::unix(path).log_err() else { continue; }; @@ -828,7 +829,7 @@ impl GitRepository for RealGitRepository { .current_dir(&working_directory?) .envs(env.iter()) .args(["checkout", &commit, "--"]) - .args(paths.iter().map(|path| path.as_str())) + .args(paths.iter().map(|path| path.as_unix_str())) .output() .await?; anyhow::ensure!( @@ -920,7 +921,7 @@ impl GitRepository for RealGitRepository { .current_dir(&working_directory) .envs(env.iter()) .args(["update-index", "--add", "--cacheinfo", "100644", sha]) - .arg(path.as_str()) + .arg(path.as_unix_str()) .output() .await?; @@ -935,7 +936,7 @@ impl GitRepository for RealGitRepository { .current_dir(&working_directory) .envs(env.iter()) .args(["update-index", "--force-remove"]) - .arg(path.as_str()) + .arg(path.as_unix_str()) .output() .await?; anyhow::ensure!( @@ -1253,7 +1254,7 @@ impl GitRepository for RealGitRepository { .current_dir(&working_directory?) .envs(env.iter()) .args(["update-index", "--add", "--remove", "--"]) - .args(paths.iter().map(|p| p.as_str())) + .args(paths.iter().map(|p| p.as_unix_str())) .output() .await?; anyhow::ensure!( @@ -1282,7 +1283,7 @@ impl GitRepository for RealGitRepository { .current_dir(&working_directory?) .envs(env.iter()) .args(["reset", "--quiet", "--"]) - .args(paths.iter().map(|p| p.as_ref())) + .args(paths.iter().map(|p| p.as_std_path())) .output() .await?; @@ -1311,7 +1312,7 @@ impl GitRepository for RealGitRepository { .args(["stash", "push", "--quiet"]) .arg("--include-untracked"); - cmd.args(paths.iter().map(|p| p.as_ref())); + cmd.args(paths.iter().map(|p| p.as_unix_str())); let output = cmd.output().await?; @@ -1817,7 +1818,7 @@ fn git_status_args(path_prefixes: &[RepoPath]) -> Vec { if path_prefix.is_empty() { Path::new(".").into() } else { - path_prefix.as_os_str().into() + path_prefix.as_std_path().into() } })); args @@ -2073,7 +2074,7 @@ pub struct RepoPath(pub Arc); impl RepoPath { pub fn new + ?Sized>(s: &S) -> Result { - let rel_path = RelPath::new(s)?; + let rel_path = RelPath::unix(s.as_ref())?; Ok(rel_path.into()) } @@ -2083,14 +2084,14 @@ impl RepoPath { } pub fn from_std_path(path: &Path, path_style: PathStyle) -> Result { - let rel_path = RelPath::from_std_path(path, path_style)?; - Ok(rel_path.into()) + let rel_path = RelPath::new(path, path_style)?; + Ok(Self(rel_path.as_ref().into())) } } #[cfg(any(test, feature = "test-support"))] pub fn repo_path + ?Sized>(s: &S) -> RepoPath { - RepoPath(RelPath::new(s).unwrap().into()) + RepoPath(RelPath::unix(s.as_ref()).unwrap().into()) } impl From<&RelPath> for RepoPath { @@ -2099,6 +2100,12 @@ impl From<&RelPath> for RepoPath { } } +impl<'a> From> for RepoPath { + fn from(value: Cow<'a, RelPath>) -> Self { + value.as_ref().into() + } +} + impl From> for RepoPath { fn from(value: Arc) -> Self { RepoPath(value) @@ -2119,11 +2126,11 @@ impl std::ops::Deref for RepoPath { } } -impl AsRef for RepoPath { - fn as_ref(&self) -> &Path { - RelPath::as_ref(&self.0) - } -} +// impl AsRef for RepoPath { +// fn as_ref(&self) -> &Path { +// RelPath::as_ref(&self.0) +// } +// } #[derive(Debug)] pub struct RepoPathDescendants<'a>(pub &'a RepoPath); diff --git a/crates/git/src/status.rs b/crates/git/src/status.rs index 2bcd0809dbb1ac4bf41c8b7e861ed906f086d1ad..c3f28aa2040446822f81990804a63fcb5a53300c 100644 --- a/crates/git/src/status.rs +++ b/crates/git/src/status.rs @@ -448,7 +448,7 @@ impl FromStr for GitStatus { let status = entry.as_bytes()[0..2].try_into().unwrap(); let status = FileStatus::from_bytes(status).log_err()?; // git-status outputs `/`-delimited repo paths, even on Windows. - let path = RepoPath(RelPath::new(path).log_err()?.into()); + let path = RepoPath(RelPath::unix(path).log_err()?.into()); Some((path, status)) }) .collect::>(); diff --git a/crates/git_ui/src/commit_view.rs b/crates/git_ui/src/commit_view.rs index 038a5beaac5fcb7b1d96ff5f1e63d307bce6595c..ac00955b6112f2a8b3f9cd963194d76a8217f9c5 100644 --- a/crates/git_ui/src/commit_view.rs +++ b/crates/git_ui/src/commit_view.rs @@ -128,7 +128,7 @@ impl CommitView { let mut metadata_buffer_id = None; if let Some(worktree_id) = first_worktree_id { let file = Arc::new(CommitMetadataFile { - title: RelPath::new(&format!("commit {}", commit.sha)) + title: RelPath::unix(&format!("commit {}", commit.sha)) .unwrap() .into(), worktree_id, @@ -145,7 +145,7 @@ impl CommitView { }); multibuffer.update(cx, |multibuffer, cx| { multibuffer.set_excerpts_for_path( - PathKey::namespaced(COMMIT_METADATA_NAMESPACE, file.title.as_str().into()), + PathKey::namespaced(COMMIT_METADATA_NAMESPACE, file.title.as_unix_str().into()), buffer.clone(), vec![Point::zero()..buffer.read(cx).max_point()], 0, @@ -193,7 +193,7 @@ impl CommitView { .collect::>(); let path = snapshot.file().unwrap().path().clone(); let _is_newly_added = multibuffer.set_excerpts_for_path( - PathKey::namespaced(FILE_NAMESPACE, path.as_str().into()), + PathKey::namespaced(FILE_NAMESPACE, path.as_unix_str().into()), buffer, diff_hunk_ranges, multibuffer_context_lines(cx), @@ -275,7 +275,7 @@ impl language::File for CommitMetadataFile { } fn full_path(&self, _: &App) -> PathBuf { - PathBuf::from(self.title.as_str().to_owned()) + PathBuf::from(self.title.as_unix_str().to_owned()) } fn file_name<'a>(&'a self, _: &'a App) -> &'a str { diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index a226caab34662c44c20a8bccb02d1149102befc7..0508cd4c2580ec2c49717f29cadade03f31bb1d6 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -243,7 +243,7 @@ impl ProjectDiff { TRACKED_NAMESPACE }; - let path_key = PathKey::namespaced(namespace, entry.repo_path.as_str().into()); + let path_key = PathKey::namespaced(namespace, entry.repo_path.as_unix_str().into()); self.move_to_path(path_key, window, cx) } @@ -397,7 +397,7 @@ impl ProjectDiff { } else { TRACKED_NAMESPACE }; - let path_key = PathKey::namespaced(namespace, entry.repo_path.as_str().into()); + let path_key = PathKey::namespaced(namespace, entry.repo_path.as_unix_str().into()); previous_paths.remove(&path_key); let load_buffer = self diff --git a/crates/language_tools/src/lsp_button.rs b/crates/language_tools/src/lsp_button.rs index 8bf40ccc1a7f05ffd3c8ff971638d84ae4b7150c..614eaa4f05a0c4cac2572b9d014a04a8de5c4554 100644 --- a/crates/language_tools/src/lsp_button.rs +++ b/crates/language_tools/src/lsp_button.rs @@ -162,7 +162,7 @@ impl LanguageServerState { let relative_path = abs_path.strip_prefix(&worktree.abs_path()).ok()?; let relative_path = - RelPath::from_std_path(relative_path, path_style) + RelPath::new(relative_path, path_style) .log_err()?; let entry = worktree.entry_for_path(&relative_path)?; let project_path = diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index 512653eab7dca97fd1c9ce3fbd790466ca62abd4..e59a3693753965995eec27c8a8d06b988e47bc21 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -55,8 +55,8 @@ impl ContextProvider for JsonTaskProvider { let Some(file) = project::File::from_dyn(file.as_ref()).cloned() else { return Task::ready(None); }; - let is_package_json = file.path.ends_with(RelPath::new("package.json").unwrap()); - let is_composer_json = file.path.ends_with(RelPath::new("composer.json").unwrap()); + let is_package_json = file.path.ends_with(RelPath::unix("package.json").unwrap()); + let is_composer_json = file.path.ends_with(RelPath::unix("composer.json").unwrap()); if !is_package_json && !is_composer_json { return Task::ready(None); } diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index 8b6abc9c7205a769d0630a3792e37589c0e844c5..b7c37d19bd1d7caf9d81b4590be678cdfd69832a 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -55,7 +55,7 @@ impl ManifestProvider for PyprojectTomlManifestProvider { }: ManifestQuery, ) -> Option> { for path in path.ancestors().take(depth) { - let p = path.join(RelPath::new("pyproject.toml").unwrap()); + let p = path.join(RelPath::unix("pyproject.toml").unwrap()); if delegate.exists(&p, Some(false)) { return Some(path.into()); } @@ -1030,7 +1030,7 @@ impl ToolchainLister for PythonToolchainProvider { config.workspace_directories = Some( subroot_relative_path .ancestors() - .map(|ancestor| worktree_root.join(ancestor)) + .map(|ancestor| worktree_root.join(ancestor.as_std_path())) .collect(), ); for locator in locators.iter() { diff --git a/crates/languages/src/rust.rs b/crates/languages/src/rust.rs index b8f5c78dcef829cf97dcdb5f1698e3fa429c25fa..04a1eba03381069ac9485cec8f9a84e07a1f4bd4 100644 --- a/crates/languages/src/rust.rs +++ b/crates/languages/src/rust.rs @@ -92,7 +92,7 @@ impl ManifestProvider for CargoManifestProvider { ) -> Option> { let mut outermost_cargo_toml = None; for path in path.ancestors().take(depth) { - let p = path.join(RelPath::new("Cargo.toml").unwrap()); + let p = path.join(RelPath::unix("Cargo.toml").unwrap()); if delegate.exists(&p, Some(false)) { outermost_cargo_toml = Some(Arc::from(path)); } diff --git a/crates/languages/src/typescript.rs b/crates/languages/src/typescript.rs index 6e3661fa6f2807689a0e12580813ed7c7e56c0de..4d1282e28a2bf32fb6fd4925fa6c76056a59c6a9 100644 --- a/crates/languages/src/typescript.rs +++ b/crates/languages/src/typescript.rs @@ -269,7 +269,7 @@ impl TypeScriptContextProvider { ) -> Task> { let new_json_data = file_relative_path .ancestors() - .map(|path| worktree_root.join(path)) + .map(|path| worktree_root.join(path.as_std_path())) .map(|parent_path| { self.package_json_data(&parent_path, self.last_package_json.clone(), fs.clone(), cx) }) @@ -533,7 +533,7 @@ impl TypeScriptLspAdapter { } async fn tsdk_path(&self, adapter: &Arc) -> Option<&'static str> { let is_yarn = adapter - .read_text_file(RelPath::new(".yarn/sdks/typescript/lib/typescript.js").unwrap()) + .read_text_file(RelPath::unix(".yarn/sdks/typescript/lib/typescript.js").unwrap()) .await .is_ok(); diff --git a/crates/languages/src/vtsls.rs b/crates/languages/src/vtsls.rs index 053d15775b2f3ea6328b8dca269ed8144b0628b3..9124a64227f91aa256063f012c960e92afbd8b9e 100644 --- a/crates/languages/src/vtsls.rs +++ b/crates/languages/src/vtsls.rs @@ -36,7 +36,7 @@ impl VtslsLspAdapter { async fn tsdk_path(&self, adapter: &Arc) -> Option<&'static str> { let is_yarn = adapter - .read_text_file(RelPath::new(".yarn/sdks/typescript/lib/typescript.js").unwrap()) + .read_text_file(RelPath::unix(".yarn/sdks/typescript/lib/typescript.js").unwrap()) .await .is_ok(); diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 4ba636921844404590e06ea7c5402fffd9de41f7..a2c404af805db03076c112792445a04833cbbf1d 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -6660,7 +6660,7 @@ outline: struct OutlineEntryExcerpt .read(cx) .root_name() .join(&directory.entry.path) - .as_str() + .as_unix_str() .to_string() } else { directory diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs index b860cc1b02207d3d489624028f35d796bfc688fc..ac68cf863149dfd9c00615574bd5e51bd4592ff6 100644 --- a/crates/paths/src/paths.rs +++ b/crates/paths/src/paths.rs @@ -31,12 +31,12 @@ static CONFIG_DIR: OnceLock = OnceLock::new(); /// Returns the relative path to the zed_server directory on the ssh host. pub fn remote_server_dir_relative() -> &'static RelPath { - RelPath::new(".zed_server").unwrap() + RelPath::unix(".zed_server").unwrap() } /// Returns the relative path to the zed_wsl_server directory on the wsl host. pub fn remote_wsl_server_dir_relative() -> &'static RelPath { - RelPath::new(".zed_wsl_server").unwrap() + RelPath::unix(".zed_wsl_server").unwrap() } /// Sets a custom directory for all user data, overriding the default data directory. @@ -410,17 +410,17 @@ pub fn local_vscode_folder_name() -> &'static str { /// Returns the relative path to a `settings.json` file within a project. pub fn local_settings_file_relative_path() -> &'static RelPath { - RelPath::new(".zed/settings.json").unwrap() + RelPath::unix(".zed/settings.json").unwrap() } /// Returns the relative path to a `tasks.json` file within a project. pub fn local_tasks_file_relative_path() -> &'static RelPath { - RelPath::new(".zed/tasks.json").unwrap() + RelPath::unix(".zed/tasks.json").unwrap() } /// Returns the relative path to a `.vscode/tasks.json` file within a project. pub fn local_vscode_tasks_file_relative_path() -> &'static RelPath { - RelPath::new(".vscode/tasks.json").unwrap() + RelPath::unix(".vscode/tasks.json").unwrap() } pub fn debug_task_file_name() -> &'static str { @@ -434,12 +434,12 @@ pub fn task_file_name() -> &'static str { /// Returns the relative path to a `debug.json` file within a project. /// .zed/debug.json pub fn local_debug_file_relative_path() -> &'static RelPath { - RelPath::new(".zed/debug.json").unwrap() + RelPath::unix(".zed/debug.json").unwrap() } /// Returns the relative path to a `.vscode/launch.json` file within a project. pub fn local_vscode_launch_file_relative_path() -> &'static RelPath { - RelPath::new(".vscode/launch.json").unwrap() + RelPath::unix(".vscode/launch.json").unwrap() } pub fn user_ssh_config_file() -> PathBuf { diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index 168549d4eb7ae11b28bcf944f9dfe2bb26946748..1a6f966b89c990e28653395815f7e292c5b89294 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -989,7 +989,7 @@ impl GitStore { parse_git_remote_url(provider_registry, &origin_url) .context("parsing Git remote URL")?; - let path = repo_path.as_str(); + let path = repo_path.as_unix_str(); Ok(provider.build_permalink( remote, @@ -1315,7 +1315,7 @@ impl GitStore { }); if let Some((repo, path)) = self.repository_and_path_for_buffer_id(buffer_id, cx) { let recv = repo.update(cx, |repo, cx| { - log::debug!("hunks changed for {}", path.as_str()); + log::debug!("hunks changed for {}", path.as_unix_str()); repo.spawn_set_index_text_job( path, new_index_text.as_ref().map(|rope| rope.to_string()), @@ -3118,7 +3118,7 @@ impl Repository { let repo_path = this.abs_path_to_repo_path(&abs_path)?; log::debug!( "start reload diff bases for repo path {}", - repo_path.as_str() + repo_path.as_unix_str() ); diff_state.update(cx, |diff_state, _| { let has_unstaged_diff = diff_state @@ -4162,7 +4162,10 @@ impl Repository { Some(GitJobKey::WriteIndex(path.clone())), None, move |git_repo, mut cx| async move { - log::debug!("start updating index text for buffer {}", path.as_str()); + log::debug!( + "start updating index text for buffer {}", + path.as_unix_str() + ); match git_repo { RepositoryState::Local { backend, @@ -4184,7 +4187,10 @@ impl Repository { .await?; } } - log::debug!("finish updating index text for buffer {}", path.as_str()); + log::debug!( + "finish updating index text for buffer {}", + path.as_unix_str() + ); if let Some(hunk_staging_operation_count) = hunk_staging_operation_count { let project_path = this diff --git a/crates/project/src/git_store/git_traversal.rs b/crates/project/src/git_store/git_traversal.rs index 3da56b0246a84927202179a8b440c5b2e8116d29..ca4a22b14d3682790282744b4834980d669b8d93 100644 --- a/crates/project/src/git_store/git_traversal.rs +++ b/crates/project/src/git_store/git_traversal.rs @@ -332,7 +332,7 @@ mod tests { let traversal = GitTraversal::new( &repo_snapshots, - worktree_snapshot.traverse_from_path(true, false, true, RelPath::new("x").unwrap()), + worktree_snapshot.traverse_from_path(true, false, true, RelPath::unix("x").unwrap()), ); let entries = traversal .map(|entry| (entry.path.clone(), entry.git_summary)) diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 77ec10d01ea5400194d5a9288f5d1b0a4e874648..ce1b52999a795dd7e6eae7618735c63995ee5b69 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -1850,7 +1850,7 @@ impl LocalLspStore { if !extra_buffers.is_empty() { extra_buffers.push_str(", "); } - extra_buffers.push_str(path.path.as_str()); + extra_buffers.push_str(path.path.as_unix_str()); } }) .ok(); @@ -3284,7 +3284,7 @@ impl LocalLspStore { let literal_prefix = glob_literal_prefix(relative); Some(( worktree.clone(), - RelPath::from_std_path(&literal_prefix, path_style).ok()?, + RelPath::new(&literal_prefix, path_style).ok()?.into_arc(), relative.to_string_lossy().to_string(), )) } @@ -3300,7 +3300,7 @@ impl LocalLspStore { literal_prefix.push(glob_literal_prefix(Path::new(&rp.pattern))); Some(( worktree.clone(), - RelPath::from_std_path(&literal_prefix, path_style).ok()?, + RelPath::new(&literal_prefix, path_style).ok()?.into_arc(), rp.pattern.clone(), )) } @@ -7936,11 +7936,8 @@ impl LspStore { let relative_path = if let Some(known_path) = known_relative_path { known_path } else { - RelPath::from_std_path( - abs_path.strip_prefix(worktree_root)?, - PathStyle::local(), - ) - .context("failed to create relative path")? + RelPath::new(abs_path.strip_prefix(worktree_root)?, PathStyle::local())? + .into_arc() }; (worktree, relative_path) }; diff --git a/crates/project/src/manifest_tree/path_trie.rs b/crates/project/src/manifest_tree/path_trie.rs index 2dd301fb13a89a61086d61a55c0f53568d1f3dd0..9710bb46d022382819d1edf7e84b85b5f325cdb7 100644 --- a/crates/project/src/manifest_tree/path_trie.rs +++ b/crates/project/src/manifest_tree/path_trie.rs @@ -61,7 +61,7 @@ impl RootPathTrie