diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-06 09:59:53 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-06 09:59:53 +0100 |
commit | cf5d478b674e49906b129d7ed706ec5fb367ddc8 (patch) | |
tree | a0715e48cd7330aeebd9c7520dbeedb54a49f0c8 /crates | |
parent | e01c6b4e1bdd52744c278d423e32dbaf82cd6c56 (diff) | |
parent | 6cf56b66156c2e321d44a51df726cd4061334ba3 (diff) |
Merge #1655
1655: cleanup imports r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_arena/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_batch/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ra_batch/src/vfs_filter.rs | 18 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/vfs_filter.rs | 18 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 2 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 2 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 36 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 2 |
9 files changed, 43 insertions, 45 deletions
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<ID: ArenaId, T> Arena<ID, T> { | |||
79 | self.data.push(value); | 79 | self.data.push(value); |
80 | ID::from_raw(id) | 80 | ID::from_raw(id) |
81 | } | 81 | } |
82 | pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> { | 82 | pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> + ExactSizeIterator { |
83 | self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) | 83 | self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) |
84 | } | 84 | } |
85 | } | 85 | } |
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; | |||
6 | 6 | ||
7 | use ra_db::{CrateGraph, FileId, SourceRootId}; | 7 | use ra_db::{CrateGraph, FileId, SourceRootId}; |
8 | use ra_ide_api::{AnalysisChange, AnalysisHost}; | 8 | use ra_ide_api::{AnalysisChange, AnalysisHost}; |
9 | use ra_project_model::{ProjectRoot, ProjectWorkspace}; | 9 | use ra_project_model::{PackageRoot, ProjectWorkspace}; |
10 | use ra_vfs::{Vfs, VfsChange}; | 10 | use ra_vfs::{Vfs, VfsChange}; |
11 | use vfs_filter::IncludeRustFiles; | 11 | use vfs_filter::IncludeRustFiles; |
12 | 12 | ||
@@ -19,7 +19,7 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { | |||
19 | SourceRootId(r.0) | 19 | SourceRootId(r.0) |
20 | } | 20 | } |
21 | 21 | ||
22 | pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, ProjectRoot>)> { | 22 | pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> { |
23 | let root = std::env::current_dir()?.join(root); | 23 | let root = std::env::current_dir()?.join(root); |
24 | let ws = ProjectWorkspace::discover(root.as_ref())?; | 24 | let ws = ProjectWorkspace::discover(root.as_ref())?; |
25 | let project_roots = ws.to_roots(); | 25 | let project_roots = ws.to_roots(); |
@@ -48,7 +48,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, | |||
48 | } | 48 | } |
49 | 49 | ||
50 | pub fn load( | 50 | pub fn load( |
51 | source_roots: &FxHashMap<SourceRootId, ProjectRoot>, | 51 | source_roots: &FxHashMap<SourceRootId, PackageRoot>, |
52 | crate_graph: CrateGraph, | 52 | crate_graph: CrateGraph, |
53 | vfs: &mut Vfs, | 53 | vfs: &mut Vfs, |
54 | ) -> AnalysisHost { | 54 | ) -> 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 @@ | |||
1 | use ra_project_model::ProjectRoot; | 1 | use ra_project_model::PackageRoot; |
2 | use ra_vfs::{Filter, RelativePath, RootEntry}; | 2 | use ra_vfs::{Filter, RelativePath, RootEntry}; |
3 | use std::path::PathBuf; | 3 | use std::path::PathBuf; |
4 | 4 | ||
5 | /// `IncludeRustFiles` is used to convert | 5 | /// `IncludeRustFiles` is used to convert |
6 | /// from `ProjectRoot` to `RootEntry` for VFS | 6 | /// from `PackageRoot` to `RootEntry` for VFS |
7 | pub struct IncludeRustFiles { | 7 | pub struct IncludeRustFiles { |
8 | root: ProjectRoot, | 8 | root: PackageRoot, |
9 | } | 9 | } |
10 | 10 | ||
11 | impl IncludeRustFiles { | 11 | impl IncludeRustFiles { |
12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | 12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> |
13 | where | 13 | where |
14 | R: IntoIterator<Item = ProjectRoot>, | 14 | R: IntoIterator<Item = PackageRoot>, |
15 | { | 15 | { |
16 | roots.into_iter().map(IncludeRustFiles::from_root) | 16 | roots.into_iter().map(IncludeRustFiles::from_root) |
17 | } | 17 | } |
18 | 18 | ||
19 | pub fn from_root(root: ProjectRoot) -> RootEntry { | 19 | pub fn from_root(root: PackageRoot) -> RootEntry { |
20 | IncludeRustFiles::from(root).into() | 20 | IncludeRustFiles::from(root).into() |
21 | } | 21 | } |
22 | 22 | ||
23 | #[allow(unused)] | 23 | #[allow(unused)] |
24 | pub fn external(path: PathBuf) -> RootEntry { | 24 | pub fn external(path: PathBuf) -> RootEntry { |
25 | IncludeRustFiles::from_root(ProjectRoot::new(path, false)) | 25 | IncludeRustFiles::from_root(PackageRoot::new(path, false)) |
26 | } | 26 | } |
27 | 27 | ||
28 | pub fn member(path: PathBuf) -> RootEntry { | 28 | pub fn member(path: PathBuf) -> RootEntry { |
29 | IncludeRustFiles::from_root(ProjectRoot::new(path, true)) | 29 | IncludeRustFiles::from_root(PackageRoot::new(path, true)) |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
@@ -40,8 +40,8 @@ impl Filter for IncludeRustFiles { | |||
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | impl From<ProjectRoot> for IncludeRustFiles { | 43 | impl From<PackageRoot> for IncludeRustFiles { |
44 | fn from(v: ProjectRoot) -> IncludeRustFiles { | 44 | fn from(v: PackageRoot) -> IncludeRustFiles { |
45 | IncludeRustFiles { root: v } | 45 | IncludeRustFiles { root: v } |
46 | } | 46 | } |
47 | } | 47 | } |
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( | |||
269 | && pending_libraries.is_empty() | 269 | && pending_libraries.is_empty() |
270 | && in_flight_libraries == 0 | 270 | && in_flight_libraries == 0 |
271 | { | 271 | { |
272 | let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum(); | 272 | let n_packages: usize = state.workspaces.iter().map(|it| it.n_packages()).sum(); |
273 | if state.options.show_workspace_loaded { | 273 | if state.options.show_workspace_loaded { |
274 | let msg = format!("workspace loaded, {} rust packages", n_packages); | 274 | let msg = format!("workspace loaded, {} rust packages", n_packages); |
275 | show_message(req::MessageType::Info, msg, msg_sender); | 275 | show_message(req::MessageType::Info, msg, msg_sender); |
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 @@ | |||
1 | use ra_project_model::ProjectRoot; | 1 | use ra_project_model::PackageRoot; |
2 | use ra_vfs::{Filter, RelativePath, RootEntry}; | 2 | use ra_vfs::{Filter, RelativePath, RootEntry}; |
3 | use std::path::PathBuf; | 3 | use std::path::PathBuf; |
4 | 4 | ||
5 | /// `IncludeRustFiles` is used to convert | 5 | /// `IncludeRustFiles` is used to convert |
6 | /// from `ProjectRoot` to `RootEntry` for VFS | 6 | /// from `PackageRoot` to `RootEntry` for VFS |
7 | pub struct IncludeRustFiles { | 7 | pub struct IncludeRustFiles { |
8 | root: ProjectRoot, | 8 | root: PackageRoot, |
9 | } | 9 | } |
10 | 10 | ||
11 | impl IncludeRustFiles { | 11 | impl IncludeRustFiles { |
12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | 12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> |
13 | where | 13 | where |
14 | R: IntoIterator<Item = ProjectRoot>, | 14 | R: IntoIterator<Item = PackageRoot>, |
15 | { | 15 | { |
16 | roots.into_iter().map(IncludeRustFiles::from_root) | 16 | roots.into_iter().map(IncludeRustFiles::from_root) |
17 | } | 17 | } |
18 | 18 | ||
19 | pub fn from_root(root: ProjectRoot) -> RootEntry { | 19 | pub fn from_root(root: PackageRoot) -> RootEntry { |
20 | IncludeRustFiles::from(root).into() | 20 | IncludeRustFiles::from(root).into() |
21 | } | 21 | } |
22 | 22 | ||
23 | #[allow(unused)] | 23 | #[allow(unused)] |
24 | pub fn external(path: PathBuf) -> RootEntry { | 24 | pub fn external(path: PathBuf) -> RootEntry { |
25 | IncludeRustFiles::from_root(ProjectRoot::new(path, false)) | 25 | IncludeRustFiles::from_root(PackageRoot::new(path, false)) |
26 | } | 26 | } |
27 | 27 | ||
28 | pub fn member(path: PathBuf) -> RootEntry { | 28 | pub fn member(path: PathBuf) -> RootEntry { |
29 | IncludeRustFiles::from_root(ProjectRoot::new(path, true)) | 29 | IncludeRustFiles::from_root(PackageRoot::new(path, true)) |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
@@ -40,8 +40,8 @@ impl Filter for IncludeRustFiles { | |||
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | impl std::convert::From<ProjectRoot> for IncludeRustFiles { | 43 | impl std::convert::From<PackageRoot> for IncludeRustFiles { |
44 | fn from(v: ProjectRoot) -> IncludeRustFiles { | 44 | fn from(v: PackageRoot) -> IncludeRustFiles { |
45 | IncludeRustFiles { root: v } | 45 | IncludeRustFiles { root: v } |
46 | } | 46 | } |
47 | } | 47 | } |
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 { | |||
211 | } else { | 211 | } else { |
212 | res.push_str("workspaces:\n"); | 212 | res.push_str("workspaces:\n"); |
213 | for w in self.workspaces.iter() { | 213 | for w in self.workspaces.iter() { |
214 | res += &format!("{} packages loaded\n", w.count()); | 214 | res += &format!("{} packages loaded\n", w.n_packages()); |
215 | } | 215 | } |
216 | } | 216 | } |
217 | res.push_str("\nanalysis:\n"); | 217 | 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 { | |||
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 | ||
12 | use rustc_hash::FxHashMap; | ||
13 | |||
14 | use ra_db::{CrateGraph, Edition, FileId}; | 12 | use ra_db::{CrateGraph, Edition, FileId}; |
15 | |||
16 | use serde_json::from_reader; | ||
17 | |||
18 | use relative_path::RelativePath; | 13 | use relative_path::RelativePath; |
14 | use rustc_hash::FxHashMap; | ||
15 | use serde_json::from_reader; | ||
19 | 16 | ||
20 | pub use crate::{ | 17 | pub 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)] |
41 | pub struct ProjectRoot { | 38 | pub 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 | ||
48 | impl ProjectRoot { | 45 | impl 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 | ||