-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`ProjectWorkspace::to_roots` now returns a new `ProjectRoot` which contains information regarding whether or not the given path is part of the current workspace or an external dependency. This information can then be used in `ra_batch` and `ra_lsp_server` to implement more advanced filtering. This allows us to filter some unnecessary folders from external dependencies such as tests, examples and benches.
- Loading branch information
Showing
6 changed files
with
164 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::path::PathBuf; | ||
use ra_project_model::ProjectRoot; | ||
use ra_vfs::{RootEntry, Filter, RelativePath}; | ||
|
||
pub struct IncludeRustFiles { | ||
/// Is a member of the current workspace | ||
is_member: bool, | ||
} | ||
|
||
impl IncludeRustFiles { | ||
pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | ||
where | ||
R: IntoIterator<Item = ProjectRoot>, | ||
{ | ||
roots.into_iter().map(IncludeRustFiles::from_root) | ||
} | ||
|
||
pub fn from_root(root: ProjectRoot) -> RootEntry { | ||
let is_member = root.is_member(); | ||
IncludeRustFiles::into_entry(root.into_path(), is_member) | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn external(path: PathBuf) -> RootEntry { | ||
IncludeRustFiles::into_entry(path, false) | ||
} | ||
|
||
pub fn member(path: PathBuf) -> RootEntry { | ||
IncludeRustFiles::into_entry(path, true) | ||
} | ||
|
||
fn into_entry(path: PathBuf, is_member: bool) -> RootEntry { | ||
RootEntry::new(path, Box::new(Self { is_member })) | ||
} | ||
} | ||
|
||
impl Filter for IncludeRustFiles { | ||
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 | ||
} | ||
|
||
fn include_file(&self, file_path: &RelativePath) -> bool { | ||
file_path.extension() == Some("rs") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::path::PathBuf; | ||
use ra_project_model::ProjectRoot; | ||
use ra_vfs::{RootEntry, Filter, RelativePath}; | ||
|
||
pub struct IncludeRustFiles { | ||
/// Is a member of the current workspace | ||
is_member: bool, | ||
} | ||
|
||
impl IncludeRustFiles { | ||
pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | ||
where | ||
R: IntoIterator<Item = ProjectRoot>, | ||
{ | ||
roots.into_iter().map(IncludeRustFiles::from_root) | ||
} | ||
|
||
pub fn from_root(root: ProjectRoot) -> RootEntry { | ||
let is_member = root.is_member(); | ||
IncludeRustFiles::into_entry(root.into_path(), is_member) | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn external(path: PathBuf) -> RootEntry { | ||
IncludeRustFiles::into_entry(path, false) | ||
} | ||
|
||
pub fn member(path: PathBuf) -> RootEntry { | ||
IncludeRustFiles::into_entry(path, true) | ||
} | ||
|
||
fn into_entry(path: PathBuf, is_member: bool) -> RootEntry { | ||
RootEntry::new(path, Box::new(Self { is_member })) | ||
} | ||
} | ||
|
||
impl Filter for IncludeRustFiles { | ||
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 | ||
} | ||
|
||
fn include_file(&self, file_path: &RelativePath) -> bool { | ||
file_path.extension() == Some("rs") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters