Rename and change add_roots to return a Vec.

This commit is contained in:
David Wood 2019-03-07 00:39:50 +01:00
parent 00d927a188
commit 614dd3c347
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
3 changed files with 8 additions and 3 deletions

View file

@ -99,7 +99,7 @@ impl BatchDatabase {
let ws = ProjectWorkspace::discover(root.as_ref())?;
let mut roots = Vec::new();
roots.push(root.clone());
ws.add_roots(&mut roots);
roots.extend(ws.to_roots());
let (mut vfs, roots) = Vfs::new(roots);
let mut load = |path: &Path| {
let vfs_file = vfs.load(path);

View file

@ -40,7 +40,7 @@ impl ServerWorldState {
let mut roots = Vec::new();
roots.push(root.clone());
for ws in workspaces.iter() {
ws.add_roots(&mut roots);
roots.extend(ws.to_roots());
}
let (mut vfs, roots) = Vfs::new(roots);
let roots_to_scan = roots.len();

View file

@ -50,20 +50,25 @@ impl ProjectWorkspace {
}
}
pub fn add_roots(&self, roots: &mut Vec<PathBuf>) {
pub fn to_roots(&self) -> Vec<PathBuf> {
match self {
ProjectWorkspace::Json { project } => {
let mut roots = Vec::with_capacity(project.roots.len());
for root in &project.roots {
roots.push(root.path.clone());
}
roots
}
ProjectWorkspace::Cargo { cargo, sysroot } => {
let mut roots =
Vec::with_capacity(cargo.packages().count() + sysroot.crates().count());
for pkg in cargo.packages() {
roots.push(pkg.root(&cargo).to_path_buf());
}
for krate in sysroot.crates() {
roots.push(krate.root_dir(&sysroot).to_path_buf())
}
roots
}
}
}