blob: dd20c12031ffb4a076db7db72b4376efc9b363ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
use std::path::PathBuf;
use ra_project_model::ProjectRoot;
use ra_vfs::{RootEntry, Filter, RelativePath};
/// `IncludeRustFiles` is used to convert
/// from `ProjectRoot` to `RootEntry` for VFS
pub struct IncludeRustFiles {
root: ProjectRoot,
}
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 {
IncludeRustFiles::from(root).into()
}
#[allow(unused)]
pub fn external(path: PathBuf) -> RootEntry {
IncludeRustFiles::from_root(ProjectRoot::new(path, false))
}
pub fn member(path: PathBuf) -> RootEntry {
IncludeRustFiles::from_root(ProjectRoot::new(path, true))
}
}
impl Filter for IncludeRustFiles {
fn include_dir(&self, dir_path: &RelativePath) -> bool {
self.root.include_dir(dir_path)
}
fn include_file(&self, file_path: &RelativePath) -> bool {
self.root.include_file(file_path)
}
}
impl std::convert::From<ProjectRoot> for IncludeRustFiles {
fn from(v: ProjectRoot) -> IncludeRustFiles {
IncludeRustFiles { root: v }
}
}
impl std::convert::From<IncludeRustFiles> for RootEntry {
fn from(v: IncludeRustFiles) -> RootEntry {
let path = v.root.path().clone();
RootEntry::new(path, Box::new(v))
}
}
|