aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/project_model.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
commit1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_lsp_server/src/project_model.rs
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
parent61f3a438d3a729a6be941bca1ff4c6a97a33f221 (diff)
Merge #134
134: Cargo Format run r=kjeremy a=kjeremy I'm not sure how appreciated this is but I figured I would run `cargo fmt` and see what came up. I made sure that `cargo test` still passes. Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/project_model.rs')
-rw-r--r--crates/ra_lsp_server/src/project_model.rs32
1 files changed, 19 insertions, 13 deletions
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs
index c144d9596..d170ceb73 100644
--- a/crates/ra_lsp_server/src/project_model.rs
+++ b/crates/ra_lsp_server/src/project_model.rs
@@ -1,13 +1,12 @@
1use std::{
2 path::{Path, PathBuf},
3};
4use rustc_hash::{FxHashMap, FxHashSet};
5use cargo_metadata::{metadata_run, CargoOpt}; 1use cargo_metadata::{metadata_run, CargoOpt};
6use ra_syntax::SmolStr; 2use ra_syntax::SmolStr;
3use rustc_hash::{FxHashMap, FxHashSet};
4
5use std::path::{Path, PathBuf};
7 6
8use crate::{ 7use crate::{
8 thread_watcher::{ThreadWatcher, Worker},
9 Result, 9 Result,
10 thread_watcher::{Worker, ThreadWatcher},
11}; 10};
12 11
13#[derive(Debug, Clone)] 12#[derive(Debug, Clone)]
@@ -39,7 +38,12 @@ struct TargetData {
39 38
40#[derive(Debug, Clone, Copy, PartialEq, Eq)] 39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum TargetKind { 40pub enum TargetKind {
42 Bin, Lib, Example, Test, Bench, Other, 41 Bin,
42 Lib,
43 Example,
44 Test,
45 Bench,
46 Other,
43} 47}
44 48
45impl Package { 49impl Package {
@@ -49,7 +53,7 @@ impl Package {
49 pub fn root(self, ws: &CargoWorkspace) -> &Path { 53 pub fn root(self, ws: &CargoWorkspace) -> &Path {
50 ws.pkg(self).manifest.parent().unwrap() 54 ws.pkg(self).manifest.parent().unwrap()
51 } 55 }
52 pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item=Target> + 'a { 56 pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a {
53 ws.pkg(self).targets.iter().cloned() 57 ws.pkg(self).targets.iter().cloned()
54 } 58 }
55 pub fn is_member(self, ws: &CargoWorkspace) -> bool { 59 pub fn is_member(self, ws: &CargoWorkspace) -> bool {
@@ -78,13 +82,15 @@ impl CargoWorkspace {
78 let meta = metadata_run( 82 let meta = metadata_run(
79 Some(cargo_toml.as_path()), 83 Some(cargo_toml.as_path()),
80 true, 84 true,
81 Some(CargoOpt::AllFeatures) 85 Some(CargoOpt::AllFeatures),
82 ).map_err(|e| format_err!("cargo metadata failed: {}", e))?; 86 )
87 .map_err(|e| format_err!("cargo metadata failed: {}", e))?;
83 let mut pkg_by_id = FxHashMap::default(); 88 let mut pkg_by_id = FxHashMap::default();
84 let mut packages = Vec::new(); 89 let mut packages = Vec::new();
85 let mut targets = Vec::new(); 90 let mut targets = Vec::new();
86 91
87 let ws_members: FxHashSet<String> = meta.workspace_members 92 let ws_members: FxHashSet<String> = meta
93 .workspace_members
88 .into_iter() 94 .into_iter()
89 .map(|it| it.raw) 95 .map(|it| it.raw)
90 .collect(); 96 .collect();
@@ -114,7 +120,7 @@ impl CargoWorkspace {
114 120
115 Ok(CargoWorkspace { packages, targets }) 121 Ok(CargoWorkspace { packages, targets })
116 } 122 }
117 pub fn packages<'a>(&'a self) -> impl Iterator<Item=Package> + 'a { 123 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a {
118 (0..self.packages.len()).map(Package) 124 (0..self.packages.len()).map(Package)
119 } 125 }
120 pub fn target_by_root(&self, root: &Path) -> Option<Target> { 126 pub fn target_by_root(&self, root: &Path) -> Option<Target> {
@@ -155,7 +161,7 @@ impl TargetKind {
155 "example" => TargetKind::Example, 161 "example" => TargetKind::Example,
156 _ if kind.contains("lib") => TargetKind::Lib, 162 _ if kind.contains("lib") => TargetKind::Lib,
157 _ => continue, 163 _ => continue,
158 } 164 };
159 } 165 }
160 TargetKind::Other 166 TargetKind::Other
161 } 167 }
@@ -170,6 +176,6 @@ pub fn workspace_loader() -> (Worker<PathBuf, Result<CargoWorkspace>>, ThreadWat
170 .into_iter() 176 .into_iter()
171 .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path())) 177 .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path()))
172 .for_each(|it| output_sender.send(it)) 178 .for_each(|it| output_sender.send(it))
173 } 179 },
174 ) 180 )
175} 181}