aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-03-21 08:43:47 +0000
committerVille Penttinen <[email protected]>2019-03-21 08:43:47 +0000
commitc6d6e6c6259709ec30eadb79a1908dca707a6499 (patch)
tree998713639b3c09e8650e34c7c86c40e0d11e3f35 /crates/ra_project_model
parente32462c6d56592acd22f1aab64f627636a476d6c (diff)
Move actual include logic to ProjectRoot
This way the two IncludeRustFiles implementations can simply call the ProjectRoots' methods, so that the include logic is in one place.
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/Cargo.toml1
-rw-r--r--crates/ra_project_model/src/lib.rs30
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]
8log = "0.4.5" 8log = "0.4.5"
9rustc-hash = "1.0" 9rustc-hash = "1.0"
10relative-path = "0.4.0"
10 11
11failure = "0.1.4" 12failure = "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
16use serde_json::from_reader; 16use serde_json::from_reader;
17 17
18use relative_path::RelativePath;
19
18pub use crate::{ 20pub 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
45impl ProjectRoot { 47impl 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
59impl ProjectWorkspace { 83impl ProjectWorkspace {