Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/load-cargo/src/lib.rs')
| -rw-r--r-- | crates/load-cargo/src/lib.rs | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index 72ca85c6a2..3e52dbaea6 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -2,25 +2,26 @@ //! for incorporating changes. // Note, don't remove any public api from this. This API is consumed by external tools // to run rust-analyzer as a library. -use std::{collections::hash_map::Entry, iter, mem, path::Path, sync}; +use std::{collections::hash_map::Entry, mem, path::Path, sync}; -use crossbeam_channel::{unbounded, Receiver}; +use crossbeam_channel::{Receiver, unbounded}; use hir_expand::proc_macro::{ ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacroLoadResult, - ProcMacros, + ProcMacrosBuilder, }; use ide_db::{ - base_db::{CrateGraph, CrateWorkspaceData, Env, SourceRoot, SourceRootId}, - prime_caches, ChangeWithProcMacros, FxHashMap, RootDatabase, + ChangeWithProcMacros, FxHashMap, RootDatabase, + base_db::{CrateGraphBuilder, Env, SourceRoot, SourceRootId}, + prime_caches, }; use itertools::Itertools; use proc_macro_api::{MacroDylib, ProcMacroClient}; use project_model::{CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace}; use span::Span; use vfs::{ + AbsPath, AbsPathBuf, VfsPath, file_set::FileSetConfig, loader::{Handle, LoadingProgress}, - AbsPath, AbsPathBuf, VfsPath, }; #[derive(Debug)] @@ -65,7 +66,7 @@ pub fn load_workspace_at( pub fn load_workspace( ws: ProjectWorkspace, - extra_env: &FxHashMap<String, String>, + extra_env: &FxHashMap<String, Option<String>>, load_config: &LoadCargoConfig, ) -> anyhow::Result<(RootDatabase, vfs::Vfs, Option<ProcMacroClient>)> { let (sender, receiver) = unbounded(); @@ -139,7 +140,6 @@ pub fn load_workspace( }); let db = load_crate_graph( - &ws, crate_graph, proc_macros, project_folders.source_root_config, @@ -418,18 +418,15 @@ pub fn load_proc_macro( } fn load_crate_graph( - ws: &ProjectWorkspace, - crate_graph: CrateGraph, - proc_macros: ProcMacros, + crate_graph: CrateGraphBuilder, + proc_macros: ProcMacrosBuilder, source_root_config: SourceRootConfig, vfs: &mut vfs::Vfs, receiver: &Receiver<vfs::loader::Message>, ) -> RootDatabase { - let ProjectWorkspace { toolchain, target_layout, .. } = ws; - let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<u16>().ok()); let mut db = RootDatabase::new(lru_cap); - let mut analysis_change = ChangeWithProcMacros::new(); + let mut analysis_change = ChangeWithProcMacros::default(); db.enable_proc_attr_macros(); @@ -461,14 +458,7 @@ fn load_crate_graph( let source_roots = source_root_config.partition(vfs); analysis_change.set_roots(source_roots); - let ws_data = crate_graph - .iter() - .zip(iter::repeat(From::from(CrateWorkspaceData { - data_layout: target_layout.clone(), - toolchain: toolchain.clone(), - }))) - .collect(); - analysis_change.set_crate_graph(crate_graph, ws_data); + analysis_change.set_crate_graph(crate_graph); analysis_change.set_proc_macros(proc_macros); db.apply_change(analysis_change); @@ -494,7 +484,7 @@ fn expander_to_proc_macro( } } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] struct Expander(proc_macro_api::ProcMacro); impl ProcMacroExpander for Expander { @@ -506,7 +496,7 @@ impl ProcMacroExpander for Expander { def_site: Span, call_site: Span, mixed_site: Span, - current_dir: Option<String>, + current_dir: String, ) -> Result<tt::TopSubtree<Span>, ProcMacroExpansionError> { match self.0.expand( subtree.view(), @@ -522,11 +512,15 @@ impl ProcMacroExpander for Expander { Err(err) => Err(ProcMacroExpansionError::System(err.to_string())), } } + + fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool { + other.as_any().downcast_ref::<Self>().is_some_and(|other| self == other) + } } #[cfg(test)] mod tests { - use ide_db::base_db::SourceDatabase; + use ide_db::base_db::RootQueryDb; use vfs::file_set::FileSetConfigBuilder; use super::*; @@ -543,7 +537,7 @@ mod tests { let (db, _vfs, _proc_macro) = load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {}).unwrap(); - let n_crates = db.crate_graph().iter().count(); + let n_crates = db.all_crates().len(); // RA has quite a few crates, but the exact count doesn't matter assert!(n_crates > 20); } @@ -633,7 +627,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 2, 3] }; let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(2), SourceRootId(1)), (SourceRootId(3), SourceRootId(1))]) } @@ -648,7 +642,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 3] }; let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(3), SourceRootId(1)),]) } @@ -663,7 +657,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 3] }; let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(3), SourceRootId(1)),]) } @@ -679,7 +673,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1] }; let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(1), SourceRootId(0)),]) } @@ -695,7 +689,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1] }; let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(1), SourceRootId(0)),]) } |