aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_batch/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_batch/src')
-rw-r--r--crates/ra_batch/src/vfs_filter.rs45
1 files changed, 20 insertions, 25 deletions
diff --git a/crates/ra_batch/src/vfs_filter.rs b/crates/ra_batch/src/vfs_filter.rs
index 290aec172..dd20c1203 100644
--- a/crates/ra_batch/src/vfs_filter.rs
+++ b/crates/ra_batch/src/vfs_filter.rs
@@ -2,9 +2,10 @@ use std::path::PathBuf;
2use ra_project_model::ProjectRoot; 2use ra_project_model::ProjectRoot;
3use ra_vfs::{RootEntry, Filter, RelativePath}; 3use ra_vfs::{RootEntry, Filter, RelativePath};
4 4
5/// `IncludeRustFiles` is used to convert
6/// from `ProjectRoot` to `RootEntry` for VFS
5pub struct IncludeRustFiles { 7pub struct IncludeRustFiles {
6 /// Is a member of the current workspace 8 root: ProjectRoot,
7 is_member: bool,
8} 9}
9 10
10impl IncludeRustFiles { 11impl IncludeRustFiles {
@@ -16,44 +17,38 @@ impl IncludeRustFiles {
16 } 17 }
17 18
18 pub fn from_root(root: ProjectRoot) -> RootEntry { 19 pub fn from_root(root: ProjectRoot) -> RootEntry {
19 let is_member = root.is_member(); 20 IncludeRustFiles::from(root).into()
20 IncludeRustFiles::into_entry(root.into_path(), is_member)
21 } 21 }
22 22
23 #[allow(unused)] 23 #[allow(unused)]
24 pub fn external(path: PathBuf) -> RootEntry { 24 pub fn external(path: PathBuf) -> RootEntry {
25 IncludeRustFiles::into_entry(path, false) 25 IncludeRustFiles::from_root(ProjectRoot::new(path, false))
26 } 26 }
27 27
28 pub fn member(path: PathBuf) -> RootEntry { 28 pub fn member(path: PathBuf) -> RootEntry {
29 IncludeRustFiles::into_entry(path, true) 29 IncludeRustFiles::from_root(ProjectRoot::new(path, true))
30 }
31
32 fn into_entry(path: PathBuf, is_member: bool) -> RootEntry {
33 RootEntry::new(path, Box::new(Self { is_member }))
34 } 30 }
35} 31}
36 32
37impl Filter for IncludeRustFiles { 33impl Filter for IncludeRustFiles {
38 fn include_dir(&self, dir_path: &RelativePath) -> bool { 34 fn include_dir(&self, dir_path: &RelativePath) -> bool {
39 const COMMON_IGNORED_DIRS: &[&str] = &["node_modules", "target", ".git"]; 35 self.root.include_dir(dir_path)
40 const EXTERNAL_IGNORED_DIRS: &[&str] = &["examples", "tests", "benches"]; 36 }
41
42 let is_ignored = if self.is_member {
43 dir_path.components().any(|c| COMMON_IGNORED_DIRS.contains(&c.as_str()))
44 } else {
45 dir_path.components().any(|c| {
46 let path = c.as_str();
47 COMMON_IGNORED_DIRS.contains(&path) || EXTERNAL_IGNORED_DIRS.contains(&path)
48 })
49 };
50 37
51 let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); 38 fn include_file(&self, file_path: &RelativePath) -> bool {
39 self.root.include_file(file_path)
40 }
41}
52 42
53 !is_ignored && !hidden 43impl std::convert::From<ProjectRoot> for IncludeRustFiles {
44 fn from(v: ProjectRoot) -> IncludeRustFiles {
45 IncludeRustFiles { root: v }
54 } 46 }
47}
55 48
56 fn include_file(&self, file_path: &RelativePath) -> bool { 49impl std::convert::From<IncludeRustFiles> for RootEntry {
57 file_path.extension() == Some("rs") 50 fn from(v: IncludeRustFiles) -> RootEntry {
51 let path = v.root.path().clone();
52 RootEntry::new(path, Box::new(v))
58 } 53 }
59} 54}