aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r--crates/ra_project_model/src/lib.rs30
1 files changed, 27 insertions, 3 deletions
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 {