diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 30 |
2 files changed, 28 insertions, 3 deletions
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index 34d33531e..cf4adf35c 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml | |||
@@ -7,6 +7,7 @@ authors = ["rust-analyzer developers"] | |||
7 | [dependencies] | 7 | [dependencies] |
8 | log = "0.4.5" | 8 | log = "0.4.5" |
9 | rustc-hash = "1.0" | 9 | rustc-hash = "1.0" |
10 | relative-path = "0.4.0" | ||
10 | 11 | ||
11 | failure = "0.1.4" | 12 | failure = "0.1.4" |
12 | 13 | ||
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index b27cb55ef..6f46a2d43 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -15,6 +15,8 @@ use ra_db::{CrateGraph, FileId, Edition}; | |||
15 | 15 | ||
16 | use serde_json::from_reader; | 16 | use serde_json::from_reader; |
17 | 17 | ||
18 | use relative_path::RelativePath; | ||
19 | |||
18 | pub use crate::{ | 20 | pub use crate::{ |
19 | cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, | 21 | cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, |
20 | json_project::JsonProject, | 22 | json_project::JsonProject, |
@@ -43,17 +45,39 @@ pub struct ProjectRoot { | |||
43 | } | 45 | } |
44 | 46 | ||
45 | impl ProjectRoot { | 47 | impl ProjectRoot { |
46 | fn new(path: PathBuf, is_member: bool) -> ProjectRoot { | 48 | pub fn new(path: PathBuf, is_member: bool) -> ProjectRoot { |
47 | ProjectRoot { path, is_member } | 49 | ProjectRoot { path, is_member } |
48 | } | 50 | } |
49 | 51 | ||
50 | pub fn into_path(self) -> PathBuf { | 52 | pub fn path(&self) -> &PathBuf { |
51 | self.path | 53 | &self.path |
52 | } | 54 | } |
53 | 55 | ||
54 | pub fn is_member(&self) -> bool { | 56 | pub fn is_member(&self) -> bool { |
55 | self.is_member | 57 | self.is_member |
56 | } | 58 | } |
59 | |||
60 | pub fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
61 | const COMMON_IGNORED_DIRS: &[&str] = &["node_modules", "target", ".git"]; | ||
62 | const EXTERNAL_IGNORED_DIRS: &[&str] = &["examples", "tests", "benches"]; | ||
63 | |||
64 | let is_ignored = if self.is_member { | ||
65 | dir_path.components().any(|c| COMMON_IGNORED_DIRS.contains(&c.as_str())) | ||
66 | } else { | ||
67 | dir_path.components().any(|c| { | ||
68 | let path = c.as_str(); | ||
69 | COMMON_IGNORED_DIRS.contains(&path) || EXTERNAL_IGNORED_DIRS.contains(&path) | ||
70 | }) | ||
71 | }; | ||
72 | |||
73 | let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); | ||
74 | |||
75 | !is_ignored && !hidden | ||
76 | } | ||
77 | |||
78 | pub fn include_file(&self, file_path: &RelativePath) -> bool { | ||
79 | file_path.extension() == Some("rs") | ||
80 | } | ||
57 | } | 81 | } |
58 | 82 | ||
59 | impl ProjectWorkspace { | 83 | impl ProjectWorkspace { |