Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkuiZhang committed Oct 17, 2024
1 parent 21956f6 commit ee3d3f3
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 42 deletions.
4 changes: 2 additions & 2 deletions crates/headless/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}

Expand Down
17 changes: 11 additions & 6 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1841,10 +1843,12 @@ impl Project {

pub fn open_local_buffer(
&mut self,
abs_path: &SanitizedPathBuf,
// abs_path: &SanitizedPathBuf,
abs_path: impl AsRef<Path>,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Buffer>>> {
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")))
Expand Down Expand Up @@ -3125,12 +3129,13 @@ impl Project {

pub fn find_or_create_worktree(
&mut self,
abs_path: &SanitizedPathBuf,
abs_path: impl AsRef<Path>,
visible: bool,
cx: &mut ModelContext<Self>,
) -> Task<Result<(Model<Worktree>, 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)
})
}

Expand Down
1 change: 0 additions & 1 deletion crates/recent_projects/src/dev_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions crates/remote_server/src/headless_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ impl HeadlessProject {
_: TypedEnvelope<proto::OpenServerSettings>,
mut cx: AsyncAppContext,
) -> Result<proto::OpenBufferResponse> {
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?;
Expand All @@ -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,
)
Expand Down
9 changes: 8 additions & 1 deletion crates/util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}

Expand Down
18 changes: 12 additions & 6 deletions crates/worktree/src/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5025,16 +5025,22 @@ impl WorktreeModelHandle for Model<Worktree> {
});

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;

Expand Down
35 changes: 14 additions & 21 deletions crates/worktree/src/worktree_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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| {
Expand Down
4 changes: 2 additions & 2 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ee3d3f3

Please sign in to comment.