about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-01-10 00:56:00 +0200
committerChayim Refael Friedman <chayimfr@gmail.com>2025-01-10 00:56:00 +0200
commitc9f75a0b2fec6dc615bb260ad01c39eaef7d1cdc (patch)
treee633b53195ee059ebf30400c346e57e73215ba96 /src/tools/rust-analyzer
parentd1b9176f2404d769d7ac7411d990045792dd62e3 (diff)
downloadrust-c9f75a0b2fec6dc615bb260ad01c39eaef7d1cdc.tar.gz
rust-c9f75a0b2fec6dc615bb260ad01c39eaef7d1cdc.zip
Do not compute `prettify_macro_expansion()` unless the "Inline macro" assist has actually been invoked
And not just called to be listed.

This was a major performance hang when repeatedly switching back-and-forth between a large `include!`d file (but there are others)..
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_macro.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_macro.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_macro.rs
index d558ec3bec7..df56f8904b2 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_macro.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_macro.rs
@@ -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())
+        },
     )
 }