mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Remove Vfs from project model
This commit is contained in:
parent
12c70871cc
commit
50fd860471
4 changed files with 8 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1055,7 +1055,6 @@ dependencies = [
|
||||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_arena 0.1.0",
|
"ra_arena 0.1.0",
|
||||||
"ra_db 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)",
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"test_utils 0.1.0",
|
"test_utils 0.1.0",
|
||||||
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -58,8 +58,12 @@ impl ServerWorldState {
|
||||||
|
|
||||||
// Create crate graph from all the workspaces
|
// Create crate graph from all the workspaces
|
||||||
let mut crate_graph = CrateGraph::default();
|
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() {
|
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);
|
change.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ cargo_metadata = "0.7.0"
|
||||||
|
|
||||||
ra_arena = { path = "../ra_arena" }
|
ra_arena = { path = "../ra_arena" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
ra_vfs = { path = "../ra_vfs" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
|
|
@ -7,7 +7,6 @@ use failure::bail;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use ra_db::{CrateGraph, FileId};
|
use ra_db::{CrateGraph, FileId};
|
||||||
use ra_vfs::Vfs;
|
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
|
cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
|
||||||
|
@ -32,12 +31,11 @@ impl ProjectWorkspace {
|
||||||
Ok(res)
|
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 crate_graph = CrateGraph::default();
|
||||||
let mut sysroot_crates = FxHashMap::default();
|
let mut sysroot_crates = FxHashMap::default();
|
||||||
for krate in self.sysroot.crates() {
|
for krate in self.sysroot.crates() {
|
||||||
if let Some(file_id) = vfs.load(krate.root(&self.sysroot)) {
|
if let Some(file_id) = load(krate.root(&self.sysroot)) {
|
||||||
let file_id = FileId(file_id.0.into());
|
|
||||||
sysroot_crates.insert(krate, crate_graph.add_crate_root(file_id));
|
sysroot_crates.insert(krate, crate_graph.add_crate_root(file_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +61,7 @@ impl ProjectWorkspace {
|
||||||
let mut lib_tgt = None;
|
let mut lib_tgt = None;
|
||||||
for tgt in pkg.targets(&self.cargo) {
|
for tgt in pkg.targets(&self.cargo) {
|
||||||
let root = tgt.root(&self.cargo);
|
let root = tgt.root(&self.cargo);
|
||||||
if let Some(file_id) = vfs.load(root) {
|
if let Some(file_id) = load(root) {
|
||||||
let file_id = FileId(file_id.0.into());
|
|
||||||
let crate_id = crate_graph.add_crate_root(file_id);
|
let crate_id = crate_graph.add_crate_root(file_id);
|
||||||
if tgt.kind(&self.cargo) == TargetKind::Lib {
|
if tgt.kind(&self.cargo) == TargetKind::Lib {
|
||||||
lib_tgt = Some(crate_id);
|
lib_tgt = Some(crate_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue