From d7be1da8df45027ce18b8af9da68ed98b9a454cc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 17:31:09 +0100 Subject: Inline ra_batch --- crates/ra_batch/Cargo.toml | 20 ------ crates/ra_batch/src/lib.rs | 152 --------------------------------------------- 2 files changed, 172 deletions(-) delete mode 100644 crates/ra_batch/Cargo.toml delete mode 100644 crates/ra_batch/src/lib.rs (limited to 'crates/ra_batch') diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml deleted file mode 100644 index 3bf351fe3..000000000 --- a/crates/ra_batch/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -edition = "2018" -name = "ra_batch" -version = "0.1.0" -authors = ["rust-analyzer developers"] - -[lib] -doctest = false - -[dependencies] -log = "0.4.5" -rustc-hash = "1.0" -crossbeam-channel = "0.4.0" - -ra_vfs = "0.5.0" -ra_vfs_glob = { path = "../ra_vfs_glob" } -ra_db = { path = "../ra_db" } -ra_ide = { path = "../ra_ide" } -ra_hir = { path = "../ra_hir" } -ra_project_model = { path = "../ra_project_model" } diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs deleted file mode 100644 index 7744ba85a..000000000 --- a/crates/ra_batch/src/lib.rs +++ /dev/null @@ -1,152 +0,0 @@ -//! FIXME: write short doc here - -use std::{collections::HashSet, error::Error, path::Path}; - -use rustc_hash::FxHashMap; - -use crossbeam_channel::{unbounded, Receiver}; -use ra_db::{CrateGraph, FileId, SourceRootId}; -use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; -use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; -use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; -use ra_vfs_glob::RustPackageFilterBuilder; - -type Result = std::result::Result>; - -fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { - FileId(f.0) -} -fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { - SourceRootId(r.0) -} - -pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap)> { - let root = std::env::current_dir()?.join(root); - let ws = ProjectWorkspace::discover(root.as_ref(), &Default::default())?; - let project_roots = ws.to_roots(); - let (sender, receiver) = unbounded(); - let sender = Box::new(move |t| sender.send(t).unwrap()); - let (mut vfs, roots) = Vfs::new( - project_roots - .iter() - .map(|pkg_root| { - RootEntry::new( - pkg_root.path().clone(), - RustPackageFilterBuilder::default() - .set_member(pkg_root.is_member()) - .into_vfs_filter(), - ) - }) - .collect(), - sender, - Watch(false), - ); - - // FIXME: cfg options? - let default_cfg_options = { - let mut opts = get_rustc_cfg_options(); - opts.insert_atom("test".into()); - opts.insert_atom("debug_assertion".into()); - opts - }; - - let (crate_graph, _crate_names) = - ws.to_crate_graph(&default_cfg_options, &mut |path: &Path| { - let vfs_file = vfs.load(path); - log::debug!("vfs file {:?} -> {:?}", path, vfs_file); - vfs_file.map(vfs_file_to_id) - }); - log::debug!("crate graph: {:?}", crate_graph); - - let source_roots = roots - .iter() - .map(|&vfs_root| { - let source_root_id = vfs_root_to_id(vfs_root); - let project_root = project_roots - .iter() - .find(|it| it.path() == &vfs.root2path(vfs_root)) - .unwrap() - .clone(); - (source_root_id, project_root) - }) - .collect::>(); - let host = load(&source_roots, crate_graph, &mut vfs, receiver); - Ok((host, source_roots)) -} - -pub fn load( - source_roots: &FxHashMap, - crate_graph: CrateGraph, - vfs: &mut Vfs, - receiver: Receiver, -) -> AnalysisHost { - let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::().ok()); - let mut host = AnalysisHost::new(lru_cap, FeatureFlags::default()); - let mut analysis_change = AnalysisChange::new(); - analysis_change.set_crate_graph(crate_graph); - - // wait until Vfs has loaded all roots - let mut roots_loaded = HashSet::new(); - for task in receiver { - vfs.handle_task(task); - let mut done = false; - for change in vfs.commit_changes() { - match change { - VfsChange::AddRoot { root, files } => { - let source_root_id = vfs_root_to_id(root); - let is_local = source_roots[&source_root_id].is_member(); - log::debug!( - "loaded source root {:?} with path {:?}", - source_root_id, - vfs.root2path(root) - ); - analysis_change.add_root(source_root_id, is_local); - analysis_change.set_debug_root_path( - source_root_id, - source_roots[&source_root_id].path().display().to_string(), - ); - - let mut file_map = FxHashMap::default(); - for (vfs_file, path, text) in files { - let file_id = vfs_file_to_id(vfs_file); - analysis_change.add_file(source_root_id, file_id, path.clone(), text); - file_map.insert(path, file_id); - } - roots_loaded.insert(source_root_id); - if roots_loaded.len() == vfs.n_roots() { - done = true; - } - } - VfsChange::AddFile { root, file, path, text } => { - let source_root_id = vfs_root_to_id(root); - let file_id = vfs_file_to_id(file); - analysis_change.add_file(source_root_id, file_id, path, text); - } - VfsChange::RemoveFile { .. } | VfsChange::ChangeFile { .. } => { - // We just need the first scan, so just ignore these - } - } - } - if done { - break; - } - } - - host.apply_change(analysis_change); - host -} - -#[cfg(test)] -mod tests { - use super::*; - use ra_hir::Crate; - - #[test] - fn test_loading_rust_analyzer() { - let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); - let (host, _roots) = load_cargo(path).unwrap(); - let n_crates = Crate::all(host.raw_database()).len(); - // RA has quite a few crates, but the exact count doesn't matter - assert!(n_crates > 20); - } -} -- cgit v1.2.3