From 614dd3c34721a4f97e8c4f1eb89aed4362338ebb Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 7 Mar 2019 00:39:50 +0100 Subject: Rename and change `add_roots` to return a `Vec`. --- crates/ra_batch/src/lib.rs | 2 +- crates/ra_lsp_server/src/server_world.rs | 2 +- crates/ra_project_model/src/lib.rs | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index 2db038063..c6d10107d 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs @@ -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); diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 4625a26a7..7163568b9 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -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(); diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index ded222446..c566ec0fb 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -50,20 +50,25 @@ impl ProjectWorkspace { } } - pub fn add_roots(&self, roots: &mut Vec) { + pub fn to_roots(&self) -> Vec { 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 } } } -- cgit v1.2.3