"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ra_arena 0.1.0",
"ra_db 0.1.0",
- "ra_vfs 0.1.0",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
// Create crate graph from all the workspaces
let mut crate_graph = CrateGraph::default();
+ let mut load = |path: &std::path::Path| {
+ let vfs_file = vfs.load(path);
+ vfs_file.map(|f| FileId(f.0.into()))
+ };
for ws in workspaces.iter() {
- crate_graph.extend(ws.to_crate_graph(&mut vfs));
+ crate_graph.extend(ws.to_crate_graph(&mut load));
}
change.set_crate_graph(crate_graph);
use rustc_hash::FxHashMap;
use ra_db::{CrateGraph, FileId};
-use ra_vfs::Vfs;
pub use crate::{
cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
Ok(res)
}
- pub fn to_crate_graph(&self, vfs: &mut Vfs) -> CrateGraph {
+ pub fn to_crate_graph(&self, load: &mut dyn FnMut(&Path) -> Option<FileId>) -> CrateGraph {
let mut crate_graph = CrateGraph::default();
let mut sysroot_crates = FxHashMap::default();
for krate in self.sysroot.crates() {
- if let Some(file_id) = vfs.load(krate.root(&self.sysroot)) {
- let file_id = FileId(file_id.0.into());
+ if let Some(file_id) = load(krate.root(&self.sysroot)) {
sysroot_crates.insert(krate, crate_graph.add_crate_root(file_id));
}
}
let mut lib_tgt = None;
for tgt in pkg.targets(&self.cargo) {
let root = tgt.root(&self.cargo);
- if let Some(file_id) = vfs.load(root) {
- let file_id = FileId(file_id.0.into());
+ if let Some(file_id) = load(root) {
let crate_id = crate_graph.add_crate_root(file_id);
if tgt.kind(&self.cargo) == TargetKind::Lib {
lib_tgt = Some(crate_id);