From 0e4a542cfb366898a4d53701c50ae4d1732d7c53 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 10:50:32 +0200 Subject: rename --- crates/ra_batch/src/lib.rs | 6 +++--- crates/ra_batch/src/vfs_filter.rs | 18 +++++++++--------- crates/ra_lsp_server/src/vfs_filter.rs | 18 +++++++++--------- crates/ra_project_model/src/lib.rs | 20 ++++++++++---------- 4 files changed, 31 insertions(+), 31 deletions(-) (limited to 'crates') diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index c25737aaa..c01574fbc 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs @@ -6,7 +6,7 @@ use rustc_hash::FxHashMap; use ra_db::{CrateGraph, FileId, SourceRootId}; use ra_ide_api::{AnalysisChange, AnalysisHost}; -use ra_project_model::{ProjectRoot, ProjectWorkspace}; +use ra_project_model::{PackageRoot, ProjectWorkspace}; use ra_vfs::{Vfs, VfsChange}; use vfs_filter::IncludeRustFiles; @@ -19,7 +19,7 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { SourceRootId(r.0) } -pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap)> { +pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap)> { let root = std::env::current_dir()?.join(root); let ws = ProjectWorkspace::discover(root.as_ref())?; let project_roots = ws.to_roots(); @@ -48,7 +48,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap, + source_roots: &FxHashMap, crate_graph: CrateGraph, vfs: &mut Vfs, ) -> AnalysisHost { diff --git a/crates/ra_batch/src/vfs_filter.rs b/crates/ra_batch/src/vfs_filter.rs index 2f0d8cb8b..63bf77704 100644 --- a/crates/ra_batch/src/vfs_filter.rs +++ b/crates/ra_batch/src/vfs_filter.rs @@ -1,32 +1,32 @@ -use ra_project_model::ProjectRoot; +use ra_project_model::PackageRoot; use ra_vfs::{Filter, RelativePath, RootEntry}; use std::path::PathBuf; /// `IncludeRustFiles` is used to convert -/// from `ProjectRoot` to `RootEntry` for VFS +/// from `PackageRoot` to `RootEntry` for VFS pub struct IncludeRustFiles { - root: ProjectRoot, + root: PackageRoot, } impl IncludeRustFiles { pub fn from_roots(roots: R) -> impl Iterator where - R: IntoIterator, + R: IntoIterator, { roots.into_iter().map(IncludeRustFiles::from_root) } - pub fn from_root(root: ProjectRoot) -> RootEntry { + pub fn from_root(root: PackageRoot) -> RootEntry { IncludeRustFiles::from(root).into() } #[allow(unused)] pub fn external(path: PathBuf) -> RootEntry { - IncludeRustFiles::from_root(ProjectRoot::new(path, false)) + IncludeRustFiles::from_root(PackageRoot::new(path, false)) } pub fn member(path: PathBuf) -> RootEntry { - IncludeRustFiles::from_root(ProjectRoot::new(path, true)) + IncludeRustFiles::from_root(PackageRoot::new(path, true)) } } @@ -40,8 +40,8 @@ impl Filter for IncludeRustFiles { } } -impl From for IncludeRustFiles { - fn from(v: ProjectRoot) -> IncludeRustFiles { +impl From for IncludeRustFiles { + fn from(v: PackageRoot) -> IncludeRustFiles { IncludeRustFiles { root: v } } } diff --git a/crates/ra_lsp_server/src/vfs_filter.rs b/crates/ra_lsp_server/src/vfs_filter.rs index e16a57da5..abdc8dbad 100644 --- a/crates/ra_lsp_server/src/vfs_filter.rs +++ b/crates/ra_lsp_server/src/vfs_filter.rs @@ -1,32 +1,32 @@ -use ra_project_model::ProjectRoot; +use ra_project_model::PackageRoot; use ra_vfs::{Filter, RelativePath, RootEntry}; use std::path::PathBuf; /// `IncludeRustFiles` is used to convert -/// from `ProjectRoot` to `RootEntry` for VFS +/// from `PackageRoot` to `RootEntry` for VFS pub struct IncludeRustFiles { - root: ProjectRoot, + root: PackageRoot, } impl IncludeRustFiles { pub fn from_roots(roots: R) -> impl Iterator where - R: IntoIterator, + R: IntoIterator, { roots.into_iter().map(IncludeRustFiles::from_root) } - pub fn from_root(root: ProjectRoot) -> RootEntry { + pub fn from_root(root: PackageRoot) -> RootEntry { IncludeRustFiles::from(root).into() } #[allow(unused)] pub fn external(path: PathBuf) -> RootEntry { - IncludeRustFiles::from_root(ProjectRoot::new(path, false)) + IncludeRustFiles::from_root(PackageRoot::new(path, false)) } pub fn member(path: PathBuf) -> RootEntry { - IncludeRustFiles::from_root(ProjectRoot::new(path, true)) + IncludeRustFiles::from_root(PackageRoot::new(path, true)) } } @@ -40,8 +40,8 @@ impl Filter for IncludeRustFiles { } } -impl std::convert::From for IncludeRustFiles { - fn from(v: ProjectRoot) -> IncludeRustFiles { +impl std::convert::From for IncludeRustFiles { + fn from(v: PackageRoot) -> IncludeRustFiles { IncludeRustFiles { root: v } } } diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 08e5c1c32..647a1f365 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -34,20 +34,20 @@ pub enum ProjectWorkspace { Json { project: JsonProject }, } -/// `ProjectRoot` describes a workspace root folder. +/// `PackageRoot` describes a package root folder. /// Which may be an external dependency, or a member of /// the current workspace. #[derive(Clone)] -pub struct ProjectRoot { +pub struct PackageRoot { /// Path to the root folder path: PathBuf, /// Is a member of the current workspace is_member: bool, } -impl ProjectRoot { - pub fn new(path: PathBuf, is_member: bool) -> ProjectRoot { - ProjectRoot { path, is_member } +impl PackageRoot { + pub fn new(path: PathBuf, is_member: bool) -> PackageRoot { + PackageRoot { path, is_member } } pub fn path(&self) -> &PathBuf { @@ -99,15 +99,15 @@ impl ProjectWorkspace { } } - /// Returns the roots for the current ProjectWorkspace + /// Returns the roots for the current `ProjectWorkspace` /// The return type contains the path and whether or not /// the root is a member of the current workspace - pub fn to_roots(&self) -> 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(ProjectRoot::new(root.path.clone(), true)); + roots.push(PackageRoot::new(root.path.clone(), true)); } roots } @@ -117,10 +117,10 @@ impl ProjectWorkspace { for pkg in cargo.packages() { let root = pkg.root(&cargo).to_path_buf(); let member = pkg.is_member(&cargo); - roots.push(ProjectRoot::new(root, member)); + roots.push(PackageRoot::new(root, member)); } for krate in sysroot.crates() { - roots.push(ProjectRoot::new(krate.root_dir(&sysroot).to_path_buf(), false)) + roots.push(PackageRoot::new(krate.root_dir(&sysroot).to_path_buf(), false)) } roots } -- cgit v1.2.3 From d751bd08bfa36bd8abdcbb4fa466022720094b7d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 10:54:51 +0200 Subject: cleanup --- crates/ra_arena/src/lib.rs | 2 +- crates/ra_lsp_server/src/main_loop.rs | 2 +- crates/ra_lsp_server/src/world.rs | 2 +- crates/ra_project_model/src/cargo_workspace.rs | 2 +- crates/ra_project_model/src/lib.rs | 9 +++++---- crates/ra_project_model/src/sysroot.rs | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 3b7cb77b1..3ec8d3b60 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs @@ -79,7 +79,7 @@ impl Arena { self.data.push(value); ID::from_raw(id) } - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator + ExactSizeIterator { self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) } } diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 8e830c8b8..9a38d43d2 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -269,7 +269,7 @@ fn main_loop_inner( && pending_libraries.is_empty() && in_flight_libraries == 0 { - let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum(); + let n_packages: usize = state.workspaces.iter().map(|it| it.n_packages()).sum(); if state.options.show_workspace_loaded { let msg = format!("workspace loaded, {} rust packages", n_packages); show_message(req::MessageType::Info, msg, msg_sender); diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 1d7755910..b57cdf925 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -211,7 +211,7 @@ impl WorldSnapshot { } else { res.push_str("workspaces:\n"); for w in self.workspaces.iter() { - res += &format!("{} packages loaded\n", w.count()); + res += &format!("{} packages loaded\n", w.n_packages()); } } res.push_str("\nanalysis:\n"); diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 2b06e9e37..712d8818f 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -167,7 +167,7 @@ impl CargoWorkspace { Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root }) } - pub fn packages<'a>(&'a self) -> impl Iterator + 'a { + pub fn packages<'a>(&'a self) -> impl Iterator + ExactSizeIterator + 'a { self.packages.iter().map(|(id, _pkg)| id) } diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 647a1f365..8e81396d4 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -112,8 +112,7 @@ impl ProjectWorkspace { roots } ProjectWorkspace::Cargo { cargo, sysroot } => { - let mut roots = - Vec::with_capacity(cargo.packages().count() + sysroot.crates().count()); + let mut roots = Vec::with_capacity(cargo.packages().len() + sysroot.crates().len()); for pkg in cargo.packages() { let root = pkg.root(&cargo).to_path_buf(); let member = pkg.is_member(&cargo); @@ -127,10 +126,12 @@ impl ProjectWorkspace { } } - pub fn count(&self) -> usize { + pub fn n_packages(&self) -> usize { match self { ProjectWorkspace::Json { project } => project.crates.len(), - ProjectWorkspace::Cargo { cargo, .. } => cargo.packages().count(), + ProjectWorkspace::Cargo { cargo, sysroot } => { + cargo.packages().len() + sysroot.crates().len() + } } } diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 4f6e880dd..3f34d51cc 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -28,7 +28,7 @@ impl Sysroot { self.by_name("std") } - pub fn crates<'a>(&'a self) -> impl Iterator + 'a { + pub fn crates<'a>(&'a self) -> impl Iterator + ExactSizeIterator + 'a { self.crates.iter().map(|(id, _data)| id) } -- cgit v1.2.3 From 6cf56b66156c2e321d44a51df726cd4061334ba3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 10:55:59 +0200 Subject: cleanup imports --- crates/ra_project_model/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 8e81396d4..c7167046b 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -9,13 +9,10 @@ use std::{ path::{Path, PathBuf}, }; -use rustc_hash::FxHashMap; - use ra_db::{CrateGraph, Edition, FileId}; - -use serde_json::from_reader; - use relative_path::RelativePath; +use rustc_hash::FxHashMap; +use serde_json::from_reader; pub use crate::{ cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, -- cgit v1.2.3