Skip to content

Commit

Permalink
Merge pull request #18900 from ChayimFriedman2/stupid-hang
Browse files Browse the repository at this point in the history
fix: Do not compute `prettify_macro_expansion()` unless the "Inline macro" assist has actually been invoked
  • Loading branch information
Veykril authored Jan 10, 2025
2 parents 6f04f37 + 52794d5 commit 1b52a66
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions crates/ide-assists/src/handlers/inline_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
let macro_call = ctx.sema.to_def(&unexpanded)?;
let expanded = ctx.sema.parse_or_expand(macro_call.as_file());
let span_map = ctx.sema.db.expansion_span_map(macro_call.as_macro_file());
let expanded = prettify_macro_expansion(
ctx.db(),
expanded,
&span_map,
ctx.sema.file_to_module_def(ctx.file_id())?.krate().into(),
);
let target_crate_id = ctx.sema.file_to_module_def(ctx.file_id())?.krate().into();
let text_range = unexpanded.syntax().text_range();

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

Expand Down

0 comments on commit 1b52a66

Please sign in to comment.