Skip to content

Commit 16a7250

Browse files
authored
Merge pull request #19523 from davidbarsky/davidbarsky/fix-salsafied-crate-graph-with-lazy-project-discovery
internal: ensure a Salsa-ified crate graph works with project discovery
2 parents 2261e4e + 9aa99ee commit 16a7250

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

crates/hir-expand/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ impl ExpandErrorKind {
208208
},
209209
None => RenderedExpandError {
210210
message: format!(
211-
"internal error: proc-macro map is missing error entry for crate {def_crate:?}"
211+
"internal error: proc-macro map is missing error entry for crate {:?}",
212+
def_crate
212213
),
213214
error: true,
214215
kind: RenderedExpandError::GENERAL_KIND,

crates/rust-analyzer/src/reload.rs

+21-30
Original file line numberDiff line numberDiff line change
@@ -413,35 +413,26 @@ impl GlobalState {
413413
.map(|res| res.as_ref().map_err(|e| e.to_string()))
414414
.chain(iter::repeat_with(|| Err("proc-macro-srv is not running".into())));
415415
for (client, paths) in proc_macro_clients.zip(paths) {
416-
paths
417-
.into_iter()
418-
.map(move |(crate_id, res)| {
419-
(
420-
crate_id,
421-
res.map_or_else(
422-
|e| Err((e, true)),
423-
|(crate_name, path)| {
424-
progress(path.to_string());
425-
client.as_ref().map_err(|it| (it.clone(), true)).and_then(
426-
|client| {
427-
load_proc_macro(
428-
client,
429-
&path,
430-
ignored_proc_macros
431-
.iter()
432-
.find_map(|(name, macros)| {
433-
eq_ignore_underscore(name, &crate_name)
434-
.then_some(&**macros)
435-
})
436-
.unwrap_or_default(),
437-
)
438-
},
439-
)
440-
},
441-
),
442-
)
443-
})
444-
.for_each(|(krate, res)| builder.insert(krate, res));
416+
for (crate_id, res) in paths.iter() {
417+
let expansion_res = match client {
418+
Ok(client) => match res {
419+
Ok((crate_name, path)) => {
420+
progress(path.to_string());
421+
let ignored_proc_macros = ignored_proc_macros
422+
.iter()
423+
.find_map(|(name, macros)| {
424+
eq_ignore_underscore(name, crate_name).then_some(&**macros)
425+
})
426+
.unwrap_or_default();
427+
428+
load_proc_macro(client, path, ignored_proc_macros)
429+
}
430+
Err(e) => Err((e.clone(), true)),
431+
},
432+
Err(ref e) => Err((e.clone(), true)),
433+
};
434+
builder.insert(*crate_id, expansion_res)
435+
}
445436
}
446437

447438
change.set_proc_macros(builder);
@@ -645,7 +636,7 @@ impl GlobalState {
645636
Config::user_config_dir_path().as_deref(),
646637
);
647638

648-
if (self.proc_macro_clients.is_empty() || !same_workspaces)
639+
if (self.proc_macro_clients.len() < self.workspaces.len() || !same_workspaces)
649640
&& self.config.expand_proc_macros()
650641
{
651642
info!("Spawning proc-macro servers");

0 commit comments

Comments
 (0)