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.
This commit is contained in:
@@ -15,6 +15,8 @@ use ra_db::{CrateGraph, FileId, Edition};
|
||||
|
||||
use serde_json::from_reader;
|
||||
|
||||
use relative_path::RelativePath;
|
||||
|
||||
pub use crate::{
|
||||
cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
|
||||
json_project::JsonProject,
|
||||
@@ -43,17 +45,39 @@ pub struct ProjectRoot {
|
||||
}
|
||||
|
||||
impl ProjectRoot {
|
||||
fn new(path: PathBuf, is_member: bool) -> ProjectRoot {
|
||||
pub fn new(path: PathBuf, is_member: bool) -> ProjectRoot {
|
||||
ProjectRoot { path, is_member }
|
||||
}
|
||||
|
||||
pub fn into_path(self) -> PathBuf {
|
||||
self.path
|
||||
pub fn path(&self) -> &PathBuf {
|
||||
&self.path
|
||||
}
|
||||
|
||||
pub fn is_member(&self) -> bool {
|
||||
self.is_member
|
||||
}
|
||||
|
||||
pub fn include_dir(&self, dir_path: &RelativePath) -> bool {
|
||||
const COMMON_IGNORED_DIRS: &[&str] = &["node_modules", "target", ".git"];
|
||||
const EXTERNAL_IGNORED_DIRS: &[&str] = &["examples", "tests", "benches"];
|
||||
|
||||
let is_ignored = if self.is_member {
|
||||
dir_path.components().any(|c| COMMON_IGNORED_DIRS.contains(&c.as_str()))
|
||||
} else {
|
||||
dir_path.components().any(|c| {
|
||||
let path = c.as_str();
|
||||
COMMON_IGNORED_DIRS.contains(&path) || EXTERNAL_IGNORED_DIRS.contains(&path)
|
||||
})
|
||||
};
|
||||
|
||||
let hidden = dir_path.components().any(|c| c.as_str().starts_with("."));
|
||||
|
||||
!is_ignored && !hidden
|
||||
}
|
||||
|
||||
pub fn include_file(&self, file_path: &RelativePath) -> bool {
|
||||
file_path.extension() == Some("rs")
|
||||
}
|
||||
}
|
||||
|
||||
impl ProjectWorkspace {
|
||||
|
||||
Reference in New Issue
Block a user