From 9aa99eec609a9cbc38ea85e9156bb108c98d735e Mon Sep 17 00:00:00 2001 From: David Barsky Date: Tue, 1 Apr 2025 12:30:14 -0400 Subject: [PATCH] internal: fix salsa-ified crate graph working with lazy project discovery --- crates/hir-expand/src/lib.rs | 3 +- crates/rust-analyzer/src/reload.rs | 51 ++++++++++++------------------ 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index d089d4c49e..9dc08dda50 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -208,7 +208,8 @@ impl ExpandErrorKind { }, None => RenderedExpandError { message: format!( - "internal error: proc-macro map is missing error entry for crate {def_crate:?}" + "internal error: proc-macro map is missing error entry for crate {:?}", + def_crate ), error: true, kind: RenderedExpandError::GENERAL_KIND, diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index a80b99573c..b73019b310 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -413,35 +413,26 @@ impl GlobalState { .map(|res| res.as_ref().map_err(|e| e.to_string())) .chain(iter::repeat_with(|| Err("proc-macro-srv is not running".into()))); for (client, paths) in proc_macro_clients.zip(paths) { - paths - .into_iter() - .map(move |(crate_id, res)| { - ( - crate_id, - res.map_or_else( - |e| Err((e, true)), - |(crate_name, path)| { - progress(path.to_string()); - client.as_ref().map_err(|it| (it.clone(), true)).and_then( - |client| { - load_proc_macro( - client, - &path, - ignored_proc_macros - .iter() - .find_map(|(name, macros)| { - eq_ignore_underscore(name, &crate_name) - .then_some(&**macros) - }) - .unwrap_or_default(), - ) - }, - ) - }, - ), - ) - }) - .for_each(|(krate, res)| builder.insert(krate, res)); + for (crate_id, res) in paths.iter() { + let expansion_res = match client { + Ok(client) => match res { + Ok((crate_name, path)) => { + progress(path.to_string()); + let ignored_proc_macros = ignored_proc_macros + .iter() + .find_map(|(name, macros)| { + eq_ignore_underscore(name, crate_name).then_some(&**macros) + }) + .unwrap_or_default(); + + load_proc_macro(client, path, ignored_proc_macros) + } + Err(e) => Err((e.clone(), true)), + }, + Err(ref e) => Err((e.clone(), true)), + }; + builder.insert(*crate_id, expansion_res) + } } change.set_proc_macros(builder); @@ -645,7 +636,7 @@ impl GlobalState { Config::user_config_dir_path().as_deref(), ); - if (self.proc_macro_clients.is_empty() || !same_workspaces) + if (self.proc_macro_clients.len() < self.workspaces.len() || !same_workspaces) && self.config.expand_proc_macros() { info!("Spawning proc-macro servers");