{"record":{"id":"55afad7cb48c4608","repo":"rust-lang/rust-analyzer","slug":"please-set-rust-analyzer-profiling-memoryprofile","errorCode":null,"errorMessage":"Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile.","messagePattern":"Please set `rust-analyzer\\.profiling\\.memoryProfile` to the path where you want to save the profile\\.","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/rust-analyzer/src/handlers/request.rs","lineNumber":153,"sourceCode":"            \"Memory profiling is not enabled for this build of rust-analyzer.\\n\\n\\\n            To build rust-analyzer with profiling support, pass `--features dhat --profile dev-rel` to `cargo build`\n            when building from source, or pass `--enable-profiling` to `cargo xtask`.\"\n        ))\n    }\n    #[cfg(feature = \"dhat\")]\n    {\n        if let Some(dhat_output_file) = _state.config.dhat_output_file() {\n            let mut profiler = crate::DHAT_PROFILER.lock().unwrap();\n            let old_profiler = profiler.take();\n            // Need to drop the old profiler before creating a new one.\n            drop(old_profiler);\n            *profiler = Some(dhat::Profiler::builder().file_name(&dhat_output_file).build());\n            Ok(format!(\n                \"Memory profile was saved successfully to {dhat_output_file}.\\n\\n\\\n                See https://docs.rs/dhat/latest/dhat/#viewing for how to inspect the profile.\"\n            ))\n        } else {\n            Err(anyhow::anyhow!(\n                \"Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile.\"\n            ))\n        }\n    }\n}\n\npub(crate) fn handle_view_syntax_tree(\n    snap: GlobalStateSnapshot,\n    params: lsp_ext::ViewSyntaxTreeParams,\n) -> anyhow::Result<String> {\n    let _p = tracing::info_span!(\"handle_view_syntax_tree\").entered();\n    let id = try_default!(from_proto::file_id(&snap, &params.text_document.uri)?);\n    let res = snap.analysis.view_syntax_tree(id)?;\n    Ok(res)\n}\n\npub(crate) fn handle_view_hir(\n    snap: GlobalStateSnapshot,","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/rust-analyzer/src/handlers/request.rs#L135-L171","documentation":"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.","triggerScenarios":"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).","commonSituations":"Profiling workflow where the user enabled the feature build but forgot the settings entry; using a fresh machine where settings weren't synced.","solutions":["Set `\"rust-analyzer.profiling.memoryProfile\": \"/tmp/mem-profile.json\"` (an absolute path) in the client settings.","Restart/reload the LSP server so the config change applies.","Re-run the memory usage request; the profile will be written to that path."],"exampleFix":"// before (settings.json)\n{}\n\n// after (settings.json)\n{ \"rust-analyzer.profiling.memoryProfile\": \"/tmp/ra-memory-profile.json\" }","handlingStrategy":"validation","validationCode":"// verify the setting exists before issuing the request\nconst settings = workspace.getConfiguration(\"rust-analyzer\");\nconst profilePath = settings.get<string>(\"profiling.memoryProfile\");\nif (!profilePath) throw new Error(\"Set rust-analyzer.profiling.memoryProfile before requesting a memory profile\");","typeGuard":"function hasMemoryProfilePath(s: unknown): s is { profiling: { memoryProfile: string } } {\n  return typeof (s as any)?.profiling?.memoryProfile === \"string\" && (s as any).profiling.memoryProfile.length > 0;\n}","tryCatchPattern":"try {\n  await client.sendRequest(\"rust-analyzer/memoryUsage\");\n} catch (e) {\n  if (String(e.message).includes(\"profiling.memoryProfile\")) {\n    window.showErrorMessage(\"Configure rust-analyzer.profiling.memoryProfile to a file path first.\");\n  } else { throw e; }\n}","preventionTips":["Set profiling.memoryProfile to an absolute writable path whenever using a dhat build.","Document the required setting next to any profiling tooling/commands.","Validate client settings at startup and warn early if the path is missing."],"tags":["rust-analyzer","config","profiling","missing-setting"],"backgroundTag":"missing-config-option","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}