Skip to content

fix(rust-lsp): keep proc-macro expansion on in Reduced Memory mode (#2598) - #2657

Open
sinelaw wants to merge 1 commit into
masterfrom
claude/compassionate-newton-dgy212
Open

fix(rust-lsp): keep proc-macro expansion on in Reduced Memory mode (#2598)#2657
sinelaw wants to merge 1 commit into
masterfrom
claude/compassionate-newton-dgy212

Conversation

@sinelaw

@sinelaw sinelaw commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Fixes #2598.

Problem

Switching rust-analyzer to Reduced Memory mode ("Rust LSP: Configure Mode" → Reduced Memory) silently killed hover (Alt+K) and Go to Definition (F12) for:

  • the macro name itself (println!), and
  • any symbol inside a macro invocation's arguments — e.g. a plain function called inside println!(...), or a method call inside format!(...).

F12 worked on a bare call but returned No definition found on the identical call one line up that happened to sit inside a println!, so the feature looked randomly broken. Positions inside println!/format!/assert! args are among the most common cursor positions in real Rust code.

Root cause

Reduced Memory mode restarted rust-analyzer with procMacro.enable: false. rust-analyzer resolves identifiers inside a macro invocation's arguments (and the macro name itself) through macro expansion, so disabling proc-macro expansion takes navigation there down with it — including the built-in println!/format!/assert! macros, whose name doesn't obviously imply a proc-macro dependency. The mode's own status even claimed it only disabled checkOnSave, procMacro, cachePriming, none of which explains losing built-in-macro navigation to a user.

I isolated this by driving rust-analyzer directly over LSP against a minimal crate and toggling one option at a time. procMacro.enable: false is the sole cause; everything else in the reduced-mode options is fine.

Fix

Keep procMacro enabled in Reduced Memory mode. Its expansion cost is small next to checkOnSave/cachePriming, and the 50% RAM / 90% CPU process limits still apply, so the mode keeps its memory character while navigation stays intact.

Changes:

  • crates/fresh-editor/plugins/rust-lsp.ts: procMacro.enable: true in REDUCED_MEMORY_INIT_OPTIONS; comment explains why it must stay on; status message updated (no longer claims procMacro is disabled).
  • crates/fresh-editor/config.example.json: mirror the same change in the sample reduced-memory config.
  • docs/features/lsp.md: fix the palette command name (the doc said "Switch Rust Analyzer Mode"; the real command is Rust LSP: Configure Mode — a discrepancy also noted in the issue) and describe what Reduced Memory mode disables.
  • CHANGELOG.md: bug-fix entry.

Validation

Drove rust-analyzer 1.95.0 over LSP against a minimal crate:

fn main() {
    println!("{}", describe());   // in-macro arg
    let s = describe();           // bare call
}
fn describe() -> String { "x".to_string() }
Reduced-mode config def inside println! arg def on println name def on bare call
shipped (procMacro on) ✅ resolves ✅ resolves ✅ resolves
pre-fix (procMacro off) ❌ empty ❌ empty ✅ resolves

The pre-fix column reproduces exactly the bug from the report; the shipped column shows it fixed. Plugin type-check (check-types.sh) passes.

Notes / out of scope

The issue's secondary observation — a ~30–60 s window after a Reduced-mode restart where all requests return empty while the status reads ready — stems from cachePriming.enable: false (no background priming) and is an inherent, documented trade-off of the mode, not part of this navigation bug. Left as-is.

🤖 Generated with Claude Code

https://claude.ai/code/session_014bSc9dVgYMs4C1cbm1p3bx


Generated by Claude Code

…2598)

Reduced Memory mode restarted rust-analyzer with `procMacro.enable: false`.
rust-analyzer resolves identifiers *inside* a macro invocation's arguments
(and the macro name itself) through macro expansion, so disabling proc-macro
expansion silently killed hover and Go to Definition for the macro name and
everything inside its args — including built-in macros like
println!/format!/assert!, which are among the most common cursor positions in
real Rust code. This made navigation look randomly broken: F12 worked on a
bare call but returned "No definition found" on the identical call one line up
inside a println!.

Keep procMacro enabled in Reduced mode. Its expansion cost is small next to
checkOnSave/cachePriming, and the process limits still cap RAM/CPU. Update the
status message and comment to match, mirror the change in the example config,
and fix docs/features/lsp.md which referenced a non-existent palette command
name ("Switch Rust Analyzer Mode" -> "Rust LSP: Configure Mode").

Verified by driving rust-analyzer over LSP: with the shipped options,
Go to Definition inside println! args, on the macro name, and on bare calls
all resolve; with procMacro disabled, only the in-macro position comes back
empty — pinning the root cause.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014bSc9dVgYMs4C1cbm1p3bx
@sinelaw
sinelaw force-pushed the claude/compassionate-newton-dgy212 branch from d1f102f to e12b3e3 Compare July 17, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust LSP Reduced Memory mode: hover and Go to Definition silently fail on macro names and anywhere inside macro invocations (println!/format! args)

2 participants