aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/project_model
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-08 11:49:43 +0000
committerAleksey Kladov <[email protected]>2019-02-08 11:49:43 +0000
commit12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch)
tree71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_lsp_server/src/project_model
parent5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff)
reformat the world
Diffstat (limited to 'crates/ra_lsp_server/src/project_model')
-rw-r--r--crates/ra_lsp_server/src/project_model/cargo_workspace.rs17
-rw-r--r--crates/ra_lsp_server/src/project_model/sysroot.rs9
2 files changed, 7 insertions, 19 deletions
diff --git a/crates/ra_lsp_server/src/project_model/cargo_workspace.rs b/crates/ra_lsp_server/src/project_model/cargo_workspace.rs
index 8cf99d586..3b76389d2 100644
--- a/crates/ra_lsp_server/src/project_model/cargo_workspace.rs
+++ b/crates/ra_lsp_server/src/project_model/cargo_workspace.rs
@@ -118,14 +118,11 @@ impl Target {
118impl CargoWorkspace { 118impl CargoWorkspace {
119 pub fn from_cargo_metadata(cargo_toml: &Path) -> Result<CargoWorkspace> { 119 pub fn from_cargo_metadata(cargo_toml: &Path) -> Result<CargoWorkspace> {
120 let mut meta = MetadataCommand::new(); 120 let mut meta = MetadataCommand::new();
121 meta.manifest_path(cargo_toml) 121 meta.manifest_path(cargo_toml).features(CargoOpt::AllFeatures);
122 .features(CargoOpt::AllFeatures);
123 if let Some(parent) = cargo_toml.parent() { 122 if let Some(parent) = cargo_toml.parent() {
124 meta.current_dir(parent); 123 meta.current_dir(parent);
125 } 124 }
126 let meta = meta 125 let meta = meta.exec().map_err(|e| format_err!("cargo metadata failed: {}", e))?;
127 .exec()
128 .map_err(|e| format_err!("cargo metadata failed: {}", e))?;
129 let mut pkg_by_id = FxHashMap::default(); 126 let mut pkg_by_id = FxHashMap::default();
130 let mut packages = Arena::default(); 127 let mut packages = Arena::default();
131 let mut targets = Arena::default(); 128 let mut targets = Arena::default();
@@ -157,10 +154,8 @@ impl CargoWorkspace {
157 for node in resolve.nodes { 154 for node in resolve.nodes {
158 let source = pkg_by_id[&node.id]; 155 let source = pkg_by_id[&node.id];
159 for dep_node in node.deps { 156 for dep_node in node.deps {
160 let dep = PackageDependency { 157 let dep =
161 name: dep_node.name.into(), 158 PackageDependency { name: dep_node.name.into(), pkg: pkg_by_id[&dep_node.pkg] };
162 pkg: pkg_by_id[&dep_node.pkg],
163 };
164 packages[source].dependencies.push(dep); 159 packages[source].dependencies.push(dep);
165 } 160 }
166 } 161 }
@@ -171,8 +166,6 @@ impl CargoWorkspace {
171 self.packages.iter().map(|(id, _pkg)| id) 166 self.packages.iter().map(|(id, _pkg)| id)
172 } 167 }
173 pub fn target_by_root(&self, root: &Path) -> Option<Target> { 168 pub fn target_by_root(&self, root: &Path) -> Option<Target> {
174 self.packages() 169 self.packages().filter_map(|pkg| pkg.targets(self).find(|it| it.root(self) == root)).next()
175 .filter_map(|pkg| pkg.targets(self).find(|it| it.root(self) == root))
176 .next()
177 } 170 }
178} 171}
diff --git a/crates/ra_lsp_server/src/project_model/sysroot.rs b/crates/ra_lsp_server/src/project_model/sysroot.rs
index fb4685671..49210ac7a 100644
--- a/crates/ra_lsp_server/src/project_model/sysroot.rs
+++ b/crates/ra_lsp_server/src/project_model/sysroot.rs
@@ -53,9 +53,7 @@ impl Sysroot {
53 ); 53 );
54 } 54 }
55 55
56 let mut sysroot = Sysroot { 56 let mut sysroot = Sysroot { crates: Arena::default() };
57 crates: Arena::default(),
58 };
59 for name in SYSROOT_CRATES.trim().lines() { 57 for name in SYSROOT_CRATES.trim().lines() {
60 let root = src.join(format!("lib{}", name)).join("lib.rs"); 58 let root = src.join(format!("lib{}", name)).join("lib.rs");
61 if root.exists() { 59 if root.exists() {
@@ -77,10 +75,7 @@ impl Sysroot {
77 } 75 }
78 76
79 fn by_name(&self, name: &str) -> Option<SysrootCrate> { 77 fn by_name(&self, name: &str) -> Option<SysrootCrate> {
80 self.crates 78 self.crates.iter().find(|(_id, data)| data.name == name).map(|(id, _data)| id)
81 .iter()
82 .find(|(_id, data)| data.name == name)
83 .map(|(id, _data)| id)
84 } 79 }
85} 80}
86 81