diff --git a/crates/headless/src/headless.rs b/crates/headless/src/headless.rs index f15ce8101120cd..730e41a81ad65f 100644 --- a/crates/headless/src/headless.rs +++ b/crates/headless/src/headless.rs @@ -252,7 +252,7 @@ impl DevServer { })?; for path in &dev_server_project.paths { - let path = PathBuf::from(shellexpand::tilde(path).to_string()).into(); + let path = PathBuf::from(shellexpand::tilde(path).to_string()); let (worktree, _) = project .update(cx, |project, cx| { project.find_or_create_worktree(&path, true, cx) @@ -320,7 +320,7 @@ impl DevServer { } for config in dev_server_project.paths.iter() { - let path = PathBuf::from(shellexpand::tilde(config).to_string()).into(); + let path = PathBuf::from(shellexpand::tilde(config).to_string()); tasks.push(project.find_or_create_worktree(&path, true, cx)); } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index ce60283c775fd7..bdbdb357d15416 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1173,7 +1173,8 @@ impl Project { for path in root_paths { let (tree, _) = project .update(cx, |project, cx| { - project.find_or_create_worktree(path, true, cx) + let path = path.to_path_buf().into(); + project.find_or_create_worktree(&path, true, cx) }) .unwrap() .await @@ -1212,7 +1213,8 @@ impl Project { for path in root_paths { let (tree, _) = project .update(cx, |project, cx| { - project.find_or_create_worktree(path, true, cx) + let path = path.to_path_buf().into(); + project.find_or_create_worktree(&path, true, cx) }) .await .unwrap(); @@ -1841,10 +1843,12 @@ impl Project { pub fn open_local_buffer( &mut self, - abs_path: &SanitizedPathBuf, + // abs_path: &SanitizedPathBuf, + abs_path: impl AsRef, cx: &mut ModelContext, ) -> Task>> { - if let Some((worktree, relative_path)) = self.find_worktree(abs_path, cx) { + let abs_path = abs_path.as_ref().to_path_buf().into(); + if let Some((worktree, relative_path)) = self.find_worktree(&abs_path, cx) { self.open_buffer((worktree.read(cx).id(), relative_path), cx) } else { Task::ready(Err(anyhow!("no such path"))) @@ -3125,12 +3129,13 @@ impl Project { pub fn find_or_create_worktree( &mut self, - abs_path: &SanitizedPathBuf, + abs_path: impl AsRef, visible: bool, cx: &mut ModelContext, ) -> Task, SanitizedPathBuf)>> { + let abs_path = abs_path.as_ref().to_path_buf().into(); self.worktree_store.update(cx, |worktree_store, cx| { - worktree_store.find_or_create_worktree(abs_path, visible, cx) + worktree_store.find_or_create_worktree(&abs_path, visible, cx) }) } diff --git a/crates/recent_projects/src/dev_servers.rs b/crates/recent_projects/src/dev_servers.rs index 15e43d01f2e22a..eec007431e625f 100644 --- a/crates/recent_projects/src/dev_servers.rs +++ b/crates/recent_projects/src/dev_servers.rs @@ -243,7 +243,6 @@ impl ProjectPicker { let tasks = paths .into_iter() - .map(Into::into) .map(|path| { project.update(cx, |project, cx| { project.find_or_create_worktree(&path, true, cx) diff --git a/crates/remote_server/src/headless_project.rs b/crates/remote_server/src/headless_project.rs index 42acbee7792b9b..fc5823c0c7d881 100644 --- a/crates/remote_server/src/headless_project.rs +++ b/crates/remote_server/src/headless_project.rs @@ -368,11 +368,11 @@ impl HeadlessProject { _: TypedEnvelope, mut cx: AsyncAppContext, ) -> Result { - let settings_path = paths::settings_file(); + let settings_path = paths::settings_file().clone().into(); let (worktree, path) = this .update(&mut cx, |this, cx| { this.worktree_store.update(cx, |worktree_store, cx| { - worktree_store.find_or_create_worktree(settings_path, false, cx) + worktree_store.find_or_create_worktree(&settings_path, false, cx) }) })? .await?; @@ -382,7 +382,7 @@ impl HeadlessProject { buffer_store.open_buffer( ProjectPath { worktree_id: worktree.read(cx).id(), - path: path.as_trimmed_path_buf().into(), + path: path.as_trimmed_path_buf().clone().as_path().into(), }, cx, ) diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rs index 7bd39f5c086eba..58ced98a11e2e8 100644 --- a/crates/util/src/paths.rs +++ b/crates/util/src/paths.rs @@ -202,7 +202,14 @@ impl SanitizedPathBuf { } pub fn strip_prefix(&self, prefix: &Self) -> Result<&Path, std::path::StripPrefixError> { - self.trimmed.strip_prefix(prefix.as_trimmed_path_buf()) + #[cfg(target_os = "windows")] + { + self.trimmed.strip_prefix(prefix.as_trimmed_path_buf()) + } + #[cfg(not(target_os = "windows"))] + { + self.raw.strip_prefix(prefix.as_raw_path_buf()) + } } } diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 95a94fb2dcdd9b..bf0abf3153e930 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -5025,16 +5025,22 @@ impl WorktreeModelHandle for Model { }); async move { - fs.create_file(&root_path.join(file_name), Default::default()) - .await - .unwrap(); + fs.create_file( + &root_path.as_raw_path_buf().join(file_name), + Default::default(), + ) + .await + .unwrap(); cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_some()) .await; - fs.remove_file(&root_path.join(file_name), Default::default()) - .await - .unwrap(); + fs.remove_file( + &root_path.as_raw_path_buf().join(file_name), + Default::default(), + ) + .await + .unwrap(); cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_none()) .await; diff --git a/crates/worktree/src/worktree_tests.rs b/crates/worktree/src/worktree_tests.rs index 01b198e0afe4bd..aa031611bfc8e2 100644 --- a/crates/worktree/src/worktree_tests.rs +++ b/crates/worktree/src/worktree_tests.rs @@ -697,8 +697,9 @@ async fn test_rescan_with_gitignore(cx: &mut TestAppContext) { ) .await; + let path = Path::new("/root/tree"); let tree = Worktree::local( - "/root/tree".as_ref(), + path, true, fs.clone(), Default::default(), @@ -778,8 +779,9 @@ async fn test_update_gitignore(cx: &mut TestAppContext) { ) .await; + let path = Path::new("/root"); let tree = Worktree::local( - "/root".as_ref(), + path, true, fs.clone(), Default::default(), @@ -1165,15 +1167,10 @@ async fn test_create_directory_during_initial_scan(cx: &mut TestAppContext) { ) .await; - let tree = Worktree::local( - "/root".as_ref(), - true, - fs, - Default::default(), - &mut cx.to_async(), - ) - .await - .unwrap(); + let path = Path::new("/root"); + let tree = Worktree::local(path, true, fs, Default::default(), &mut cx.to_async()) + .await + .unwrap(); let snapshot1 = tree.update(cx, |tree, cx| { let tree = tree.as_local_mut().unwrap(); @@ -1230,8 +1227,9 @@ async fn test_bump_mtime_of_git_repo_workdir(cx: &mut TestAppContext) { ) .await; + let path = Path::new("/root"); let tree = Worktree::local( - "/root".as_ref(), + path, true, fs.clone(), Default::default(), @@ -1297,15 +1295,10 @@ async fn test_create_dir_all_on_create_entry(cx: &mut TestAppContext) { ) .await; - let tree_fake = Worktree::local( - "/root".as_ref(), - true, - fs_fake, - Default::default(), - &mut cx.to_async(), - ) - .await - .unwrap(); + let path = Path::new("/root"); + let tree_fake = Worktree::local(path, true, fs_fake, Default::default(), &mut cx.to_async()) + .await + .unwrap(); let entry = tree_fake .update(cx, |tree, cx| { diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index f1287af369c8b8..0d4f65bbcdfba8 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -1030,8 +1030,8 @@ fn open_settings_file( let worktree_creation_task = workspace.project().update(cx, |project, cx| { // Set up a dedicated worktree for settings, since otherwise we're dropping and re-starting LSP servers for each file inside on every settings file close/open // TODO: Do note that all other external files (e.g. drag and drop from OS) still have their worktrees released on file close, causing LSP servers' restarts. - let path = paths::config_dir().clone().into(); - project.find_or_create_worktree(&path, false, cx) + let path = paths::config_dir(); + project.find_or_create_worktree(path, false, cx) }); let settings_open_task = create_and_open_local_file(abs_path, cx, default_content); (worktree_creation_task, settings_open_task)