aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-06 09:59:53 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-06 09:59:53 +0100
commitcf5d478b674e49906b129d7ed706ec5fb367ddc8 (patch)
treea0715e48cd7330aeebd9c7520dbeedb54a49f0c8 /crates/ra_project_model
parente01c6b4e1bdd52744c278d423e32dbaf82cd6c56 (diff)
parent6cf56b66156c2e321d44a51df726cd4061334ba3 (diff)
Merge #1655
1655: cleanup imports r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs2
-rw-r--r--crates/ra_project_model/src/lib.rs36
-rw-r--r--crates/ra_project_model/src/sysroot.rs2
3 files changed, 19 insertions, 21 deletions
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 {
167 Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root }) 167 Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root })
168 } 168 }
169 169
170 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a { 170 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + ExactSizeIterator + 'a {
171 self.packages.iter().map(|(id, _pkg)| id) 171 self.packages.iter().map(|(id, _pkg)| id)
172 } 172 }
173 173
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 08e5c1c32..c7167046b 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -9,13 +9,10 @@ use std::{
9 path::{Path, PathBuf}, 9 path::{Path, PathBuf},
10}; 10};
11 11
12use rustc_hash::FxHashMap;
13
14use ra_db::{CrateGraph, Edition, FileId}; 12use ra_db::{CrateGraph, Edition, FileId};
15
16use serde_json::from_reader;
17
18use relative_path::RelativePath; 13use relative_path::RelativePath;
14use rustc_hash::FxHashMap;
15use serde_json::from_reader;
19 16
20pub use crate::{ 17pub use crate::{
21 cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, 18 cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
@@ -34,20 +31,20 @@ pub enum ProjectWorkspace {
34 Json { project: JsonProject }, 31 Json { project: JsonProject },
35} 32}
36 33
37/// `ProjectRoot` describes a workspace root folder. 34/// `PackageRoot` describes a package root folder.
38/// Which may be an external dependency, or a member of 35/// Which may be an external dependency, or a member of
39/// the current workspace. 36/// the current workspace.
40#[derive(Clone)] 37#[derive(Clone)]
41pub struct ProjectRoot { 38pub struct PackageRoot {
42 /// Path to the root folder 39 /// Path to the root folder
43 path: PathBuf, 40 path: PathBuf,
44 /// Is a member of the current workspace 41 /// Is a member of the current workspace
45 is_member: bool, 42 is_member: bool,
46} 43}
47 44
48impl ProjectRoot { 45impl PackageRoot {
49 pub fn new(path: PathBuf, is_member: bool) -> ProjectRoot { 46 pub fn new(path: PathBuf, is_member: bool) -> PackageRoot {
50 ProjectRoot { path, is_member } 47 PackageRoot { path, is_member }
51 } 48 }
52 49
53 pub fn path(&self) -> &PathBuf { 50 pub fn path(&self) -> &PathBuf {
@@ -99,38 +96,39 @@ impl ProjectWorkspace {
99 } 96 }
100 } 97 }
101 98
102 /// Returns the roots for the current ProjectWorkspace 99 /// Returns the roots for the current `ProjectWorkspace`
103 /// The return type contains the path and whether or not 100 /// The return type contains the path and whether or not
104 /// the root is a member of the current workspace 101 /// the root is a member of the current workspace
105 pub fn to_roots(&self) -> Vec<ProjectRoot> { 102 pub fn to_roots(&self) -> Vec<PackageRoot> {
106 match self { 103 match self {
107 ProjectWorkspace::Json { project } => { 104 ProjectWorkspace::Json { project } => {
108 let mut roots = Vec::with_capacity(project.roots.len()); 105 let mut roots = Vec::with_capacity(project.roots.len());
109 for root in &project.roots { 106 for root in &project.roots {
110 roots.push(ProjectRoot::new(root.path.clone(), true)); 107 roots.push(PackageRoot::new(root.path.clone(), true));
111 } 108 }
112 roots 109 roots
113 } 110 }
114 ProjectWorkspace::Cargo { cargo, sysroot } => { 111 ProjectWorkspace::Cargo { cargo, sysroot } => {
115 let mut roots = 112 let mut roots = Vec::with_capacity(cargo.packages().len() + sysroot.crates().len());
116 Vec::with_capacity(cargo.packages().count() + sysroot.crates().count());
117 for pkg in cargo.packages() { 113 for pkg in cargo.packages() {
118 let root = pkg.root(&cargo).to_path_buf(); 114 let root = pkg.root(&cargo).to_path_buf();
119 let member = pkg.is_member(&cargo); 115 let member = pkg.is_member(&cargo);
120 roots.push(ProjectRoot::new(root, member)); 116 roots.push(PackageRoot::new(root, member));
121 } 117 }
122 for krate in sysroot.crates() { 118 for krate in sysroot.crates() {
123 roots.push(ProjectRoot::new(krate.root_dir(&sysroot).to_path_buf(), false)) 119 roots.push(PackageRoot::new(krate.root_dir(&sysroot).to_path_buf(), false))
124 } 120 }
125 roots 121 roots
126 } 122 }
127 } 123 }
128 } 124 }
129 125
130 pub fn count(&self) -> usize { 126 pub fn n_packages(&self) -> usize {
131 match self { 127 match self {
132 ProjectWorkspace::Json { project } => project.crates.len(), 128 ProjectWorkspace::Json { project } => project.crates.len(),
133 ProjectWorkspace::Cargo { cargo, .. } => cargo.packages().count(), 129 ProjectWorkspace::Cargo { cargo, sysroot } => {
130 cargo.packages().len() + sysroot.crates().len()
131 }
134 } 132 }
135 } 133 }
136 134
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 {
28 self.by_name("std") 28 self.by_name("std")
29 } 29 }
30 30
31 pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + 'a { 31 pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a {
32 self.crates.iter().map(|(id, _data)| id) 32 self.crates.iter().map(|(id, _data)| id)
33 } 33 }
34 34