diff options
Diffstat (limited to 'crates/ra_vfs/src/lib.rs')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 1d0af6a09..f4447be43 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -17,16 +17,15 @@ mod io; | |||
17 | 17 | ||
18 | use std::{ | 18 | use std::{ |
19 | cmp::Reverse, | 19 | cmp::Reverse, |
20 | ffi::OsStr, | ||
21 | fmt, fs, mem, | 20 | fmt, fs, mem, |
22 | path::{Component, Path, PathBuf}, | 21 | path::{Path, PathBuf}, |
23 | sync::Arc, | 22 | sync::Arc, |
24 | thread, | 23 | thread, |
25 | }; | 24 | }; |
26 | 25 | ||
27 | use crossbeam_channel::Receiver; | 26 | use crossbeam_channel::Receiver; |
28 | use ra_arena::{impl_arena_id, Arena, RawId}; | 27 | use ra_arena::{impl_arena_id, Arena, RawId}; |
29 | use relative_path::RelativePathBuf; | 28 | use relative_path::{Component, RelativePath, RelativePathBuf}; |
30 | use rustc_hash::{FxHashMap, FxHashSet}; | 29 | use rustc_hash::{FxHashMap, FxHashSet}; |
31 | 30 | ||
32 | pub use crate::io::TaskResult as VfsTask; | 31 | pub use crate::io::TaskResult as VfsTask; |
@@ -36,12 +35,7 @@ use io::{Task, TaskResult, WatcherChange, WatcherChangeData, Worker}; | |||
36 | /// several filters match a file (nested dirs), the most nested one wins. | 35 | /// several filters match a file (nested dirs), the most nested one wins. |
37 | pub(crate) struct RootFilter { | 36 | pub(crate) struct RootFilter { |
38 | root: PathBuf, | 37 | root: PathBuf, |
39 | filter: fn(RootEntry) -> bool, | 38 | filter: fn(&Path, &RelativePath) -> bool, |
40 | } | ||
41 | |||
42 | pub(crate) struct RootEntry<'a, 'b> { | ||
43 | root: &'a Path, | ||
44 | path: &'b Path, | ||
45 | } | 39 | } |
46 | 40 | ||
47 | impl RootFilter { | 41 | impl RootFilter { |
@@ -54,27 +48,20 @@ impl RootFilter { | |||
54 | /// Check if this root can contain `path`. NB: even if this returns | 48 | /// Check if this root can contain `path`. NB: even if this returns |
55 | /// true, the `path` might actually be conained in some nested root. | 49 | /// true, the `path` might actually be conained in some nested root. |
56 | pub(crate) fn can_contain(&self, path: &Path) -> Option<RelativePathBuf> { | 50 | pub(crate) fn can_contain(&self, path: &Path) -> Option<RelativePathBuf> { |
57 | if !(self.filter)(RootEntry { | 51 | let rel_path = path.strip_prefix(&self.root).ok()?; |
58 | root: &self.root, | 52 | let rel_path = RelativePathBuf::from_path(rel_path).ok()?; |
59 | path, | 53 | if !(self.filter)(path, rel_path.as_relative_path()) { |
60 | }) { | ||
61 | return None; | 54 | return None; |
62 | } | 55 | } |
63 | let path = path.strip_prefix(&self.root).ok()?; | 56 | Some(rel_path) |
64 | RelativePathBuf::from_path(path).ok() | ||
65 | } | 57 | } |
66 | } | 58 | } |
67 | 59 | ||
68 | pub(crate) fn default_filter(entry: RootEntry) -> bool { | 60 | pub(crate) fn default_filter(path: &Path, rel_path: &RelativePath) -> bool { |
69 | if entry.path.is_dir() { | 61 | if path.is_dir() { |
70 | // first component relative to root is "target" | 62 | rel_path.components().next() != Some(Component::Normal("target")) |
71 | entry | ||
72 | .path | ||
73 | .strip_prefix(entry.root) | ||
74 | .map(|p| p.components().next() != Some(Component::Normal(OsStr::new("target")))) | ||
75 | .unwrap_or(false) | ||
76 | } else { | 63 | } else { |
77 | entry.path.extension() == Some(OsStr::new("rs")) | 64 | rel_path.extension() == Some("rs") |
78 | } | 65 | } |
79 | } | 66 | } |
80 | 67 | ||