diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 3dd05197e..f07657db6 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -44,6 +44,8 @@ impl_arena_id!(VfsRoot); | |||
44 | /// returns `true` iff path belongs to the source root | 44 | /// returns `true` iff path belongs to the source root |
45 | pub(crate) struct RootConfig { | 45 | pub(crate) struct RootConfig { |
46 | root: PathBuf, | 46 | root: PathBuf, |
47 | // result of `root.canonicalize()` if that differs from `root`; `None` otherwise. | ||
48 | canonical_root: Option<PathBuf>, | ||
47 | excluded_dirs: Vec<PathBuf>, | 49 | excluded_dirs: Vec<PathBuf>, |
48 | } | 50 | } |
49 | 51 | ||
@@ -60,7 +62,11 @@ impl std::ops::Deref for Roots { | |||
60 | 62 | ||
61 | impl RootConfig { | 63 | impl RootConfig { |
62 | fn new(root: PathBuf, excluded_dirs: Vec<PathBuf>) -> RootConfig { | 64 | fn new(root: PathBuf, excluded_dirs: Vec<PathBuf>) -> RootConfig { |
63 | RootConfig { root, excluded_dirs } | 65 | let mut canonical_root = root.canonicalize().ok(); |
66 | if Some(&root) == canonical_root.as_ref() { | ||
67 | canonical_root = None; | ||
68 | } | ||
69 | RootConfig { root, canonical_root, excluded_dirs } | ||
64 | } | 70 | } |
65 | /// Checks if root contains a path and returns a root-relative path. | 71 | /// Checks if root contains a path and returns a root-relative path. |
66 | pub(crate) fn contains(&self, path: &Path) -> Option<RelativePathBuf> { | 72 | pub(crate) fn contains(&self, path: &Path) -> Option<RelativePathBuf> { |
@@ -68,7 +74,14 @@ impl RootConfig { | |||
68 | if self.excluded_dirs.iter().any(|it| path.starts_with(it)) { | 74 | if self.excluded_dirs.iter().any(|it| path.starts_with(it)) { |
69 | return None; | 75 | return None; |
70 | } | 76 | } |
71 | let rel_path = path.strip_prefix(&self.root).ok()?; | 77 | let rel_path = path |
78 | .strip_prefix(&self.root) | ||
79 | .or_else(|err_payload| { | ||
80 | self.canonical_root | ||
81 | .as_ref() | ||
82 | .map_or(Err(err_payload), |canonical_root| path.strip_prefix(canonical_root)) | ||
83 | }) | ||
84 | .ok()?; | ||
72 | let rel_path = RelativePathBuf::from_path(rel_path).ok()?; | 85 | let rel_path = RelativePathBuf::from_path(rel_path).ok()?; |
73 | 86 | ||
74 | // Ignore some common directories. | 87 | // Ignore some common directories. |