diff options
author | Aleksey Kladov <[email protected]> | 2020-11-17 11:17:24 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-11-17 14:25:57 +0000 |
commit | 0d19ee1d70cff2605cecd51c45945371c9cd1f58 (patch) | |
tree | a8ab05dc4424e4d222ca239426e8d897a1c65635 | |
parent | 66bcdcbb3615b0d1d47ca7c4abf2c3dd5ab0b73d (diff) |
Simplify
-rw-r--r-- | crates/project_model/src/workspace.rs | 26 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 6 |
2 files changed, 15 insertions, 17 deletions
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index dbf1dc5bf..886b586a3 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs | |||
@@ -200,23 +200,19 @@ impl ProjectWorkspace { | |||
200 | let mut crate_graph = CrateGraph::default(); | 200 | let mut crate_graph = CrateGraph::default(); |
201 | match self { | 201 | match self { |
202 | ProjectWorkspace::Json { project, sysroot } => { | 202 | ProjectWorkspace::Json { project, sysroot } => { |
203 | let sysroot_dps = sysroot | 203 | let sysroot_deps = sysroot |
204 | .as_ref() | 204 | .as_ref() |
205 | .map(|sysroot| sysroot_to_crate_graph(&mut crate_graph, sysroot, target, load)); | 205 | .map(|sysroot| sysroot_to_crate_graph(&mut crate_graph, sysroot, target, load)); |
206 | 206 | ||
207 | let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default(); | 207 | let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default(); |
208 | let crates: FxHashMap<_, _> = project | 208 | let crates: FxHashMap<CrateId, CrateId> = project |
209 | .crates() | 209 | .crates() |
210 | .filter_map(|(crate_id, krate)| { | 210 | .filter_map(|(crate_id, krate)| { |
211 | let file_path = &krate.root_module; | 211 | let file_path = &krate.root_module; |
212 | let file_id = match load(&file_path) { | 212 | let file_id = load(&file_path)?; |
213 | Some(id) => id, | 213 | Some((crate_id, krate, file_id)) |
214 | None => { | 214 | }) |
215 | log::error!("failed to load crate root {}", file_path.display()); | 215 | .map(|(crate_id, krate, file_id)| { |
216 | return None; | ||
217 | } | ||
218 | }; | ||
219 | |||
220 | let env = krate.env.clone().into_iter().collect(); | 216 | let env = krate.env.clone().into_iter().collect(); |
221 | let proc_macro = krate | 217 | let proc_macro = krate |
222 | .proc_macro_dylib_path | 218 | .proc_macro_dylib_path |
@@ -230,8 +226,7 @@ impl ProjectWorkspace { | |||
230 | 226 | ||
231 | let mut cfg_options = CfgOptions::default(); | 227 | let mut cfg_options = CfgOptions::default(); |
232 | cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned()); | 228 | cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned()); |
233 | 229 | ( | |
234 | Some(( | ||
235 | crate_id, | 230 | crate_id, |
236 | crate_graph.add_crate_root( | 231 | crate_graph.add_crate_root( |
237 | file_id, | 232 | file_id, |
@@ -241,21 +236,20 @@ impl ProjectWorkspace { | |||
241 | env, | 236 | env, |
242 | proc_macro.unwrap_or_default(), | 237 | proc_macro.unwrap_or_default(), |
243 | ), | 238 | ), |
244 | )) | 239 | ) |
245 | }) | 240 | }) |
246 | .collect(); | 241 | .collect(); |
247 | 242 | ||
248 | for (from, krate) in project.crates() { | 243 | for (from, krate) in project.crates() { |
249 | if let Some(&from) = crates.get(&from) { | 244 | if let Some(&from) = crates.get(&from) { |
250 | if let Some((public_deps, _proc_macro)) = &sysroot_dps { | 245 | if let Some((public_deps, _proc_macro)) = &sysroot_deps { |
251 | for (name, to) in public_deps.iter() { | 246 | for (name, to) in public_deps.iter() { |
252 | add_dep(&mut crate_graph, from, name.clone(), *to) | 247 | add_dep(&mut crate_graph, from, name.clone(), *to) |
253 | } | 248 | } |
254 | } | 249 | } |
255 | 250 | ||
256 | for dep in &krate.deps { | 251 | for dep in &krate.deps { |
257 | let to_crate_id = dep.crate_id; | 252 | if let Some(&to) = crates.get(&dep.crate_id) { |
258 | if let Some(&to) = crates.get(&to_crate_id) { | ||
259 | add_dep(&mut crate_graph, from, dep.name.clone(), to) | 253 | add_dep(&mut crate_graph, from, dep.name.clone(), to) |
260 | } | 254 | } |
261 | } | 255 | } |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index fa6e09f42..001bf5949 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -203,7 +203,11 @@ impl GlobalState { | |||
203 | let contents = loader.handle.load_sync(path); | 203 | let contents = loader.handle.load_sync(path); |
204 | vfs.set_file_contents(vfs_path.clone(), contents); | 204 | vfs.set_file_contents(vfs_path.clone(), contents); |
205 | } | 205 | } |
206 | vfs.file_id(&vfs_path) | 206 | let res = vfs.file_id(&vfs_path); |
207 | if res.is_none() { | ||
208 | log::error!("failed to load {}", path.display()) | ||
209 | } | ||
210 | res | ||
207 | }; | 211 | }; |
208 | for ws in workspaces.iter() { | 212 | for ws in workspaces.iter() { |
209 | crate_graph.extend(ws.to_crate_graph( | 213 | crate_graph.extend(ws.to_crate_graph( |