|
16 | 16 | use std::{iter, mem};
|
17 | 17 |
|
18 | 18 | use hir::{db::DefDatabase, ChangeWithProcMacros, ProcMacros, ProcMacrosBuilder};
|
| 19 | +use ide::CrateId; |
19 | 20 | use ide_db::{
|
20 |
| - base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, Version}, |
| 21 | + base_db::{salsa::Durability, CrateGraph, CrateWorkspaceData, ProcMacroPaths}, |
21 | 22 | FxHashMap,
|
22 | 23 | };
|
23 | 24 | use itertools::Itertools;
|
@@ -692,7 +693,7 @@ impl GlobalState {
|
692 | 693 | })
|
693 | 694 | .collect();
|
694 | 695 |
|
695 |
| - let (crate_graph, proc_macro_paths, layouts, toolchains) = { |
| 696 | + let (crate_graph, proc_macro_paths, ws_data) = { |
696 | 697 | // Create crate graph from all the workspaces
|
697 | 698 | let vfs = &mut self.vfs.write().0;
|
698 | 699 |
|
@@ -721,9 +722,7 @@ impl GlobalState {
|
721 | 722 | .collect(),
|
722 | 723 | );
|
723 | 724 | }
|
724 |
| - change.set_crate_graph(crate_graph); |
725 |
| - change.set_target_data_layouts(layouts); |
726 |
| - change.set_toolchains(toolchains); |
| 725 | + change.set_crate_graph(crate_graph, ws_data); |
727 | 726 | self.analysis_host.apply_change(change);
|
728 | 727 | self.report_progress(
|
729 | 728 | "Building CrateGraph",
|
@@ -863,42 +862,27 @@ pub fn ws_to_crate_graph(
|
863 | 862 | workspaces: &[ProjectWorkspace],
|
864 | 863 | extra_env: &FxHashMap<String, String>,
|
865 | 864 | mut load: impl FnMut(&AbsPath) -> Option<vfs::FileId>,
|
866 |
| -) -> (CrateGraph, Vec<ProcMacroPaths>, Vec<Result<Arc<str>, Arc<str>>>, Vec<Option<Version>>) { |
| 865 | +) -> (CrateGraph, Vec<ProcMacroPaths>, FxHashMap<CrateId, Arc<CrateWorkspaceData>>) { |
867 | 866 | let mut crate_graph = CrateGraph::default();
|
868 | 867 | let mut proc_macro_paths = Vec::default();
|
869 |
| - let mut layouts = Vec::default(); |
870 |
| - let mut toolchains = Vec::default(); |
871 |
| - let e = Err(Arc::from("missing layout")); |
| 868 | + let mut ws_data = FxHashMap::default(); |
872 | 869 | for ws in workspaces {
|
873 | 870 | let (other, mut crate_proc_macros) = ws.to_crate_graph(&mut load, extra_env);
|
874 |
| - let num_layouts = layouts.len(); |
875 |
| - let num_toolchains = toolchains.len(); |
876 | 871 | let ProjectWorkspace { toolchain, target_layout, .. } = ws;
|
877 | 872 |
|
878 | 873 | let mapping = crate_graph.extend(other, &mut crate_proc_macros);
|
879 | 874 | // Populate the side tables for the newly merged crates
|
880 |
| - mapping.values().for_each(|val| { |
881 |
| - let idx = val.into_raw().into_u32() as usize; |
882 |
| - // we only need to consider crates that were not merged and remapped, as the |
883 |
| - // ones that were remapped already have the correct layout and toolchain |
884 |
| - if idx >= num_layouts { |
885 |
| - if layouts.len() <= idx { |
886 |
| - layouts.resize(idx + 1, e.clone()); |
887 |
| - } |
888 |
| - layouts[idx].clone_from(target_layout); |
889 |
| - } |
890 |
| - if idx >= num_toolchains { |
891 |
| - if toolchains.len() <= idx { |
892 |
| - toolchains.resize(idx + 1, None); |
893 |
| - } |
894 |
| - toolchains[idx].clone_from(toolchain); |
895 |
| - } |
896 |
| - }); |
| 875 | + ws_data.extend(mapping.values().copied().zip(iter::repeat(Arc::new(CrateWorkspaceData { |
| 876 | + toolchain: toolchain.clone(), |
| 877 | + data_layout: target_layout.clone(), |
| 878 | + proc_macro_cwd: Some(ws.workspace_root().to_owned()), |
| 879 | + })))); |
897 | 880 | proc_macro_paths.push(crate_proc_macros);
|
898 | 881 | }
|
| 882 | + |
899 | 883 | crate_graph.shrink_to_fit();
|
900 | 884 | proc_macro_paths.shrink_to_fit();
|
901 |
| - (crate_graph, proc_macro_paths, layouts, toolchains) |
| 885 | + (crate_graph, proc_macro_paths, ws_data) |
902 | 886 | }
|
903 | 887 |
|
904 | 888 | pub(crate) fn should_refresh_for_change(
|
|
0 commit comments