rust-lang/rust-analyzer · error · anyhow::Error

Please set `rust-analyzer.profiling.memoryProfile` to the pa

Error message

Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile.

What it means

Even in a `dhat`-enabled build, `handle_memory_usage` needs the `rust-analyzer.profiling.memoryProfile` config value to know where to write the dhat profile file. If the setting is unset/empty, it returns this error asking the user to configure the output path.

Source

Thrown at crates/rust-analyzer/src/handlers/request.rs:153

            "Memory profiling is not enabled for this build of rust-analyzer.\n\n\
            To build rust-analyzer with profiling support, pass `--features dhat --profile dev-rel` to `cargo build`
            when building from source, or pass `--enable-profiling` to `cargo xtask`."
        ))
    }
    #[cfg(feature = "dhat")]
    {
        if let Some(dhat_output_file) = _state.config.dhat_output_file() {
            let mut profiler = crate::DHAT_PROFILER.lock().unwrap();
            let old_profiler = profiler.take();
            // Need to drop the old profiler before creating a new one.
            drop(old_profiler);
            *profiler = Some(dhat::Profiler::builder().file_name(&dhat_output_file).build());
            Ok(format!(
                "Memory profile was saved successfully to {dhat_output_file}.\n\n\
                See https://docs.rs/dhat/latest/dhat/#viewing for how to inspect the profile."
            ))
        } else {
            Err(anyhow::anyhow!(
                "Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile."
            ))
        }
    }
}

pub(crate) fn handle_view_syntax_tree(
    snap: GlobalStateSnapshot,
    params: lsp_ext::ViewSyntaxTreeParams,
) -> anyhow::Result<String> {
    let _p = tracing::info_span!("handle_view_syntax_tree").entered();
    let id = try_default!(from_proto::file_id(&snap, &params.text_document.uri)?);
    let res = snap.analysis.view_syntax_tree(id)?;
    Ok(res)
}

pub(crate) fn handle_view_hir(
    snap: GlobalStateSnapshot,

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Set `"rust-analyzer.profiling.memoryProfile": "/tmp/mem-profile.json"` (an absolute path) in the client settings.
  2. Restart/reload the LSP server so the config change applies.
  3. Re-run the memory usage request; the profile will be written to that path.

Example fix

// before (settings.json)
{}

// after (settings.json)
{ "rust-analyzer.profiling.memoryProfile": "/tmp/ra-memory-profile.json" }
Defensive patterns

Strategy: validation

Validate before calling

// verify the setting exists before issuing the request
const settings = workspace.getConfiguration("rust-analyzer");
const profilePath = settings.get<string>("profiling.memoryProfile");
if (!profilePath) throw new Error("Set rust-analyzer.profiling.memoryProfile before requesting a memory profile");

Type guard

function hasMemoryProfilePath(s: unknown): s is { profiling: { memoryProfile: string } } {
  return typeof (s as any)?.profiling?.memoryProfile === "string" && (s as any).profiling.memoryProfile.length > 0;
}

Try / catch

try {
  await client.sendRequest("rust-analyzer/memoryUsage");
} catch (e) {
  if (String(e.message).includes("profiling.memoryProfile")) {
    window.showErrorMessage("Configure rust-analyzer.profiling.memoryProfile to a file path first.");
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling `rust-analyzer/memoryUsage` with the `dhat` feature enabled but no `profiling.memoryProfile` path configured in the client settings (e.g. missing from VS Code settings.json).

Common situations: Profiling workflow where the user enabled the feature build but forgot the settings entry; using a fresh machine where settings weren't synced.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/55afad7cb48c4608. Report an issue: GitHub.