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.rs42
1 files changed, 25 insertions, 17 deletions
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs
index fa244e86c..43d3fb7e3 100644
--- a/crates/ra_batch/src/lib.rs
+++ b/crates/ra_batch/src/lib.rs
@@ -8,7 +8,7 @@ use ra_db::{
8 CrateGraph, FileId, SourceRootId, 8 CrateGraph, FileId, SourceRootId,
9}; 9};
10use ra_ide_api::{AnalysisHost, AnalysisChange}; 10use ra_ide_api::{AnalysisHost, AnalysisChange};
11use ra_project_model::ProjectWorkspace; 11use ra_project_model::{ProjectWorkspace, ProjectRoot};
12use ra_vfs::{Vfs, VfsChange}; 12use ra_vfs::{Vfs, VfsChange};
13use vfs_filter::IncludeRustFiles; 13use vfs_filter::IncludeRustFiles;
14 14
@@ -21,13 +21,11 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
21 SourceRootId(r.0) 21 SourceRootId(r.0)
22} 22}
23 23
24pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, Vec<SourceRootId>)> { 24pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, ProjectRoot>)> {
25 let root = std::env::current_dir()?.join(root); 25 let root = std::env::current_dir()?.join(root);
26 let ws = ProjectWorkspace::discover(root.as_ref())?; 26 let ws = ProjectWorkspace::discover(root.as_ref())?;
27 let mut roots = Vec::new(); 27 let project_roots = ws.to_roots();
28 roots.push(IncludeRustFiles::member(root.clone())); 28 let (mut vfs, roots) = Vfs::new(IncludeRustFiles::from_roots(project_roots.clone()).collect());
29 roots.extend(IncludeRustFiles::from_roots(ws.to_roots()));
30 let (mut vfs, roots) = Vfs::new(roots);
31 let crate_graph = ws.to_crate_graph(&mut |path: &Path| { 29 let crate_graph = ws.to_crate_graph(&mut |path: &Path| {
32 let vfs_file = vfs.load(path); 30 let vfs_file = vfs.load(path);
33 log::debug!("vfs file {:?} -> {:?}", path, vfs_file); 31 log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
@@ -35,17 +33,27 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, Vec<SourceRootId>)> {
35 }); 33 });
36 log::debug!("crate graph: {:?}", crate_graph); 34 log::debug!("crate graph: {:?}", crate_graph);
37 35
38 let local_roots = roots 36 let source_roots = roots
39 .into_iter() 37 .iter()
40 .filter(|r| vfs.root2path(*r).starts_with(&root)) 38 .map(|&vfs_root| {
41 .map(vfs_root_to_id) 39 let source_root_id = vfs_root_to_id(vfs_root);
42 .collect(); 40 let project_root = project_roots
43 41 .iter()
44 let host = load(root.as_path(), crate_graph, &mut vfs); 42 .find(|it| it.path() == &vfs.root2path(vfs_root))
45 Ok((host, local_roots)) 43 .unwrap()
44 .clone();
45 (source_root_id, project_root)
46 })
47 .collect::<FxHashMap<_, _>>();
48 let host = load(&source_roots, crate_graph, &mut vfs);
49 Ok((host, source_roots))
46} 50}
47 51
48pub fn load(project_root: &Path, crate_graph: CrateGraph, vfs: &mut Vfs) -> AnalysisHost { 52pub fn load(
53 source_roots: &FxHashMap<SourceRootId, ProjectRoot>,
54 crate_graph: CrateGraph,
55 vfs: &mut Vfs,
56) -> AnalysisHost {
49 let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok()); 57 let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok());
50 let mut host = AnalysisHost::new(lru_cap); 58 let mut host = AnalysisHost::new(lru_cap);
51 let mut analysis_change = AnalysisChange::new(); 59 let mut analysis_change = AnalysisChange::new();
@@ -60,8 +68,8 @@ pub fn load(project_root: &Path, crate_graph: CrateGraph, vfs: &mut Vfs) -> Anal
60 for change in vfs.commit_changes() { 68 for change in vfs.commit_changes() {
61 match change { 69 match change {
62 VfsChange::AddRoot { root, files } => { 70 VfsChange::AddRoot { root, files } => {
63 let is_local = vfs.root2path(root).starts_with(&project_root);
64 let source_root_id = vfs_root_to_id(root); 71 let source_root_id = vfs_root_to_id(root);
72 let is_local = source_roots[&source_root_id].is_member();
65 log::debug!( 73 log::debug!(
66 "loaded source root {:?} with path {:?}", 74 "loaded source root {:?} with path {:?}",
67 source_root_id, 75 source_root_id,
@@ -106,7 +114,7 @@ mod tests {
106 let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); 114 let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
107 let (host, roots) = load_cargo(path).unwrap(); 115 let (host, roots) = load_cargo(path).unwrap();
108 let mut n_crates = 0; 116 let mut n_crates = 0;
109 for root in roots { 117 for (root, _) in roots {
110 for _krate in Crate::source_root_crates(host.raw_database(), root) { 118 for _krate in Crate::source_root_crates(host.raw_database(), root) {
111 n_crates += 1; 119 n_crates += 1;
112 } 120 }