aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_batch/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_batch/src/lib.rs')
-rw-r--r--crates/ra_batch/src/lib.rs26
1 files changed, 18 insertions, 8 deletions
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 @@
1mod vfs_filter;
2
3use std::{collections::HashSet, error::Error, path::Path}; 1use std::{collections::HashSet, error::Error, path::Path};
4 2
5use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
6 4
7use ra_db::{CrateGraph, FileId, SourceRootId}; 5use ra_db::{CrateGraph, FileId, SourceRootId};
8use ra_ide_api::{AnalysisChange, AnalysisHost}; 6use ra_ide_api::{AnalysisChange, AnalysisHost};
9use ra_project_model::{ProjectRoot, ProjectWorkspace}; 7use ra_project_model::{PackageRoot, ProjectWorkspace};
10use ra_vfs::{Vfs, VfsChange}; 8use ra_vfs::{RootEntry, Vfs, VfsChange};
11use vfs_filter::IncludeRustFiles; 9use ra_vfs_glob::RustPackageFilterBuilder;
12 10
13type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; 11type 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
22pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, ProjectRoot>)> { 20pub 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
50pub fn load( 60pub 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 {