Skip to content

Commit 1b52a66

Browse files
authored
Merge pull request #18900 from ChayimFriedman2/stupid-hang
fix: Do not compute `prettify_macro_expansion()` unless the "Inline macro" assist has actually been invoked
2 parents 6f04f37 + 52794d5 commit 1b52a66

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

crates/ide-assists/src/handlers/inline_macro.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
4040
let macro_call = ctx.sema.to_def(&unexpanded)?;
4141
let expanded = ctx.sema.parse_or_expand(macro_call.as_file());
4242
let span_map = ctx.sema.db.expansion_span_map(macro_call.as_macro_file());
43-
let expanded = prettify_macro_expansion(
44-
ctx.db(),
45-
expanded,
46-
&span_map,
47-
ctx.sema.file_to_module_def(ctx.file_id())?.krate().into(),
48-
);
43+
let target_crate_id = ctx.sema.file_to_module_def(ctx.file_id())?.krate().into();
4944
let text_range = unexpanded.syntax().text_range();
5045

5146
acc.add(
5247
AssistId("inline_macro", AssistKind::RefactorInline),
5348
"Inline macro".to_owned(),
5449
text_range,
55-
|builder| builder.replace(text_range, expanded.to_string()),
50+
|builder| {
51+
// Don't call `prettify_macro_expansion()` outside the actual assist action; it does some heavy rowan tree manipulation,
52+
// which can be very costly for big macros when it is done *even without the assist being invoked*.
53+
let expanded = prettify_macro_expansion(ctx.db(), expanded, &span_map, target_crate_id);
54+
builder.replace(text_range, expanded.to_string())
55+
},
5656
)
5757
}
5858

0 commit comments

Comments
 (0)