Unnamed repository; edit this file 'description' to name the repository.
fix: Don't assert paths being utf8 when filtering them in the watcher
Lukas Wirth 2024-03-22
parent fe28e47 · commit ea44706
-rw-r--r--crates/paths/src/lib.rs16
-rw-r--r--crates/project-model/src/cargo_workspace.rs2
-rw-r--r--crates/vfs-notify/src/lib.rs4
3 files changed, 14 insertions, 8 deletions
diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs
index 3ffe4e11e9..2d3653401d 100644
--- a/crates/paths/src/lib.rs
+++ b/crates/paths/src/lib.rs
@@ -13,7 +13,7 @@ use std::{
pub use camino::*;
/// Wrapper around an absolute [`Utf8PathBuf`].
-#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Ord, PartialOrd, Eq, Hash)]
pub struct AbsPathBuf(Utf8PathBuf);
impl From<AbsPathBuf> for Utf8PathBuf {
@@ -92,9 +92,9 @@ impl TryFrom<&str> for AbsPathBuf {
}
}
-impl PartialEq<AbsPath> for AbsPathBuf {
- fn eq(&self, other: &AbsPath) -> bool {
- self.as_path() == other
+impl<P: AsRef<Path> + ?Sized> PartialEq<P> for AbsPathBuf {
+ fn eq(&self, other: &P) -> bool {
+ self.0.as_std_path() == other.as_ref()
}
}
@@ -144,10 +144,16 @@ impl fmt::Display for AbsPathBuf {
}
/// Wrapper around an absolute [`Utf8Path`].
-#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[derive(Debug, Ord, PartialOrd, Eq, Hash)]
#[repr(transparent)]
pub struct AbsPath(Utf8Path);
+impl<P: AsRef<Path> + ?Sized> PartialEq<P> for AbsPath {
+ fn eq(&self, other: &P) -> bool {
+ self.0.as_std_path() == other.as_ref()
+ }
+}
+
impl AsRef<Utf8Path> for AbsPath {
fn as_ref(&self) -> &Utf8Path {
&self.0
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index 957366b610..51c1b094f7 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -406,7 +406,7 @@ impl CargoWorkspace {
pub fn target_by_root(&self, root: &AbsPath) -> Option<Target> {
self.packages()
.filter(|&pkg| self[pkg].is_member)
- .find_map(|pkg| self[pkg].targets.iter().find(|&&it| &self[it].root == root))
+ .find_map(|pkg| self[pkg].targets.iter().find(|&&it| self[it].root == root))
.copied()
}
diff --git a/crates/vfs-notify/src/lib.rs b/crates/vfs-notify/src/lib.rs
index 1f25b0e534..4cfdec2b5c 100644
--- a/crates/vfs-notify/src/lib.rs
+++ b/crates/vfs-notify/src/lib.rs
@@ -13,7 +13,7 @@ use std::fs;
use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
-use paths::{AbsPath, AbsPathBuf, Utf8Path};
+use paths::{AbsPath, AbsPathBuf};
use vfs::loader;
use walkdir::WalkDir;
@@ -205,7 +205,7 @@ impl NotifyActor {
if !entry.file_type().is_dir() {
return true;
}
- let path = AbsPath::assert(Utf8Path::from_path(entry.path()).unwrap());
+ let path = entry.path();
root == path
|| dirs.exclude.iter().chain(&dirs.include).all(|it| it != path)
});