diff options
Diffstat (limited to 'crates/ra_batch')
-rw-r--r-- | crates/ra_batch/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_batch/src/lib.rs | 26 | ||||
-rw-r--r-- | crates/ra_batch/src/vfs_filter.rs | 54 |
3 files changed, 19 insertions, 62 deletions
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml index 0ee94c445..8e23826a4 100644 --- a/crates/ra_batch/Cargo.toml +++ b/crates/ra_batch/Cargo.toml | |||
@@ -9,6 +9,7 @@ log = "0.4.5" | |||
9 | rustc-hash = "1.0" | 9 | rustc-hash = "1.0" |
10 | 10 | ||
11 | ra_vfs = "0.2.0" | 11 | ra_vfs = "0.2.0" |
12 | ra_vfs_glob = { path = "../ra_vfs_glob" } | ||
12 | ra_db = { path = "../ra_db" } | 13 | ra_db = { path = "../ra_db" } |
13 | ra_ide_api = { path = "../ra_ide_api" } | 14 | ra_ide_api = { path = "../ra_ide_api" } |
14 | ra_hir = { path = "../ra_hir" } | 15 | ra_hir = { path = "../ra_hir" } |
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index c25737aaa..0db751465 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -1,14 +1,12 @@ | |||
1 | mod vfs_filter; | ||
2 | |||
3 | use std::{collections::HashSet, error::Error, path::Path}; | 1 | use std::{collections::HashSet, error::Error, path::Path}; |
4 | 2 | ||
5 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
6 | 4 | ||
7 | use ra_db::{CrateGraph, FileId, SourceRootId}; | 5 | use ra_db::{CrateGraph, FileId, SourceRootId}; |
8 | use ra_ide_api::{AnalysisChange, AnalysisHost}; | 6 | use ra_ide_api::{AnalysisChange, AnalysisHost}; |
9 | use ra_project_model::{ProjectRoot, ProjectWorkspace}; | 7 | use ra_project_model::{PackageRoot, ProjectWorkspace}; |
10 | use ra_vfs::{Vfs, VfsChange}; | 8 | use ra_vfs::{RootEntry, Vfs, VfsChange}; |
11 | use vfs_filter::IncludeRustFiles; | 9 | use ra_vfs_glob::RustPackageFilterBuilder; |
12 | 10 | ||
13 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; | 11 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; |
14 | 12 | ||
@@ -19,11 +17,23 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { | |||
19 | SourceRootId(r.0) | 17 | SourceRootId(r.0) |
20 | } | 18 | } |
21 | 19 | ||
22 | pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, ProjectRoot>)> { | 20 | pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> { |
23 | let root = std::env::current_dir()?.join(root); | 21 | let root = std::env::current_dir()?.join(root); |
24 | let ws = ProjectWorkspace::discover(root.as_ref())?; | 22 | let ws = ProjectWorkspace::discover(root.as_ref())?; |
25 | let project_roots = ws.to_roots(); | 23 | let project_roots = ws.to_roots(); |
26 | let (mut vfs, roots) = Vfs::new(IncludeRustFiles::from_roots(project_roots.clone()).collect()); | 24 | let (mut vfs, roots) = Vfs::new( |
25 | project_roots | ||
26 | .iter() | ||
27 | .map(|pkg_root| { | ||
28 | RootEntry::new( | ||
29 | pkg_root.path().clone(), | ||
30 | RustPackageFilterBuilder::default() | ||
31 | .set_member(pkg_root.is_member()) | ||
32 | .into_vfs_filter(), | ||
33 | ) | ||
34 | }) | ||
35 | .collect(), | ||
36 | ); | ||
27 | let crate_graph = ws.to_crate_graph(&mut |path: &Path| { | 37 | let crate_graph = ws.to_crate_graph(&mut |path: &Path| { |
28 | let vfs_file = vfs.load(path); | 38 | let vfs_file = vfs.load(path); |
29 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); | 39 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); |
@@ -48,7 +58,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, | |||
48 | } | 58 | } |
49 | 59 | ||
50 | pub fn load( | 60 | pub fn load( |
51 | source_roots: &FxHashMap<SourceRootId, ProjectRoot>, | 61 | source_roots: &FxHashMap<SourceRootId, PackageRoot>, |
52 | crate_graph: CrateGraph, | 62 | crate_graph: CrateGraph, |
53 | vfs: &mut Vfs, | 63 | vfs: &mut Vfs, |
54 | ) -> AnalysisHost { | 64 | ) -> AnalysisHost { |
diff --git a/crates/ra_batch/src/vfs_filter.rs b/crates/ra_batch/src/vfs_filter.rs deleted file mode 100644 index 2f0d8cb8b..000000000 --- a/crates/ra_batch/src/vfs_filter.rs +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | use ra_project_model::ProjectRoot; | ||
2 | use ra_vfs::{Filter, RelativePath, RootEntry}; | ||
3 | use std::path::PathBuf; | ||
4 | |||
5 | /// `IncludeRustFiles` is used to convert | ||
6 | /// from `ProjectRoot` to `RootEntry` for VFS | ||
7 | pub struct IncludeRustFiles { | ||
8 | root: ProjectRoot, | ||
9 | } | ||
10 | |||
11 | impl IncludeRustFiles { | ||
12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | ||
13 | where | ||
14 | R: IntoIterator<Item = ProjectRoot>, | ||
15 | { | ||
16 | roots.into_iter().map(IncludeRustFiles::from_root) | ||
17 | } | ||
18 | |||
19 | pub fn from_root(root: ProjectRoot) -> RootEntry { | ||
20 | IncludeRustFiles::from(root).into() | ||
21 | } | ||
22 | |||
23 | #[allow(unused)] | ||
24 | pub fn external(path: PathBuf) -> RootEntry { | ||
25 | IncludeRustFiles::from_root(ProjectRoot::new(path, false)) | ||
26 | } | ||
27 | |||
28 | pub fn member(path: PathBuf) -> RootEntry { | ||
29 | IncludeRustFiles::from_root(ProjectRoot::new(path, true)) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | impl Filter for IncludeRustFiles { | ||
34 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
35 | self.root.include_dir(dir_path) | ||
36 | } | ||
37 | |||
38 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
39 | self.root.include_file(file_path) | ||
40 | } | ||
41 | } | ||
42 | |||
43 | impl From<ProjectRoot> for IncludeRustFiles { | ||
44 | fn from(v: ProjectRoot) -> IncludeRustFiles { | ||
45 | IncludeRustFiles { root: v } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | impl From<IncludeRustFiles> for RootEntry { | ||
50 | fn from(v: IncludeRustFiles) -> RootEntry { | ||
51 | let path = v.root.path().clone(); | ||
52 | RootEntry::new(path, Box::new(v)) | ||
53 | } | ||
54 | } | ||