mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Auto merge of #12314 - jonas-schievink:proc-macro-load, r=jonas-schievink
minor: simplify
This commit is contained in:
commit
eba26af9f1
4 changed files with 11 additions and 15 deletions
|
@ -88,7 +88,7 @@ fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
|
|||
}
|
||||
|
||||
fn to_crate_graph(project_workspace: ProjectWorkspace) -> CrateGraph {
|
||||
project_workspace.to_crate_graph(&Default::default(), &mut |_, _| Vec::new(), &mut {
|
||||
project_workspace.to_crate_graph(&mut |_, _| Vec::new(), &mut {
|
||||
let mut counter = 0;
|
||||
move |_path| {
|
||||
counter += 1;
|
||||
|
|
|
@ -389,14 +389,10 @@ impl ProjectWorkspace {
|
|||
|
||||
pub fn to_crate_graph(
|
||||
&self,
|
||||
dummy_replace: &FxHashMap<Box<str>, Box<[Box<str>]>>,
|
||||
load_proc_macro: &mut dyn FnMut(&AbsPath, &[Box<str>]) -> Vec<ProcMacro>,
|
||||
load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> Vec<ProcMacro>,
|
||||
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
||||
) -> CrateGraph {
|
||||
let _p = profile::span("ProjectWorkspace::to_crate_graph");
|
||||
let load_proc_macro = &mut |crate_name: &_, path: &_| {
|
||||
load_proc_macro(path, dummy_replace.get(crate_name).map(|it| &**it).unwrap_or_default())
|
||||
};
|
||||
|
||||
let mut crate_graph = match self {
|
||||
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => project_json_to_crate_graph(
|
||||
|
|
|
@ -66,8 +66,7 @@ pub fn load_workspace(
|
|||
};
|
||||
|
||||
let crate_graph = ws.to_crate_graph(
|
||||
&Default::default(),
|
||||
&mut |path: &AbsPath, _| load_proc_macro(proc_macro_client.as_ref(), path, &[]),
|
||||
&mut |_, path: &AbsPath| load_proc_macro(proc_macro_client.as_ref(), path, &[]),
|
||||
&mut |path: &AbsPath| {
|
||||
let contents = loader.load_sync(path);
|
||||
let path = vfs::VfsPath::from(path.to_path_buf());
|
||||
|
|
|
@ -319,8 +319,13 @@ impl GlobalState {
|
|||
// Create crate graph from all the workspaces
|
||||
let crate_graph = {
|
||||
let proc_macro_client = self.proc_macro_client.as_ref();
|
||||
let mut load_proc_macro = move |path: &AbsPath, dummy_replace: &_| {
|
||||
load_proc_macro(proc_macro_client, path, dummy_replace)
|
||||
let dummy_replacements = self.config.dummy_replacements();
|
||||
let mut load_proc_macro = move |crate_name: &str, path: &AbsPath| {
|
||||
load_proc_macro(
|
||||
proc_macro_client,
|
||||
path,
|
||||
dummy_replacements.get(crate_name).map(|v| &**v).unwrap_or_default(),
|
||||
)
|
||||
};
|
||||
|
||||
let vfs = &mut self.vfs.write().0;
|
||||
|
@ -342,11 +347,7 @@ impl GlobalState {
|
|||
|
||||
let mut crate_graph = CrateGraph::default();
|
||||
for ws in self.workspaces.iter() {
|
||||
crate_graph.extend(ws.to_crate_graph(
|
||||
self.config.dummy_replacements(),
|
||||
&mut load_proc_macro,
|
||||
&mut load,
|
||||
));
|
||||
crate_graph.extend(ws.to_crate_graph(&mut load_proc_macro, &mut load));
|
||||
}
|
||||
crate_graph
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue