{"record":{"id":"b3b04db6ce1e590f","repo":"rust-lang/rust","slug":"invalid-lsp-resolve-data","errorCode":null,"errorMessage":"Invalid LSP resolve data","messagePattern":"Invalid LSP resolve data","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs","lineNumber":1861,"sourceCode":"pub(crate) fn handle_inlay_hints_resolve(\n    snap: GlobalStateSnapshot,\n    mut original_hint: InlayHint,\n) -> anyhow::Result<InlayHint> {\n    let _p = tracing::info_span!(\"handle_inlay_hints_resolve\").entered();\n\n    let Some(data) = original_hint.data.take() else {\n        return Ok(original_hint);\n    };\n    let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;\n    let file_id = FileId::from_raw(resolve_data.file_id);\n    if resolve_data.version != snap.file_version(file_id) {\n        tracing::warn!(\"Inlay hint resolve data is outdated\");\n        return Ok(original_hint);\n    }\n    let Some(hash) = resolve_data.hash.parse().ok() else {\n        return Ok(original_hint);\n    };\n    anyhow::ensure!(snap.file_exists(file_id), \"Invalid LSP resolve data\");\n\n    let line_index = snap.file_line_index(file_id)?;\n    let range = from_proto::text_range(&line_index, resolve_data.resolve_range)?;\n\n    let mut forced_resolve_inlay_hints_config = snap.config.inlay_hints(snap.minicore());\n    forced_resolve_inlay_hints_config.fields_to_resolve = InlayFieldsToResolve::empty();\n    let resolve_hints = snap.analysis.inlay_hints_resolve(\n        &forced_resolve_inlay_hints_config,\n        file_id,\n        range,\n        hash,\n        |hint| {\n            std::hash::BuildHasher::hash_one(\n                &std::hash::BuildHasherDefault::<ide_db::FxHasher>::default(),\n                hint,\n            )\n        },\n    )?;","sourceCodeStart":1843,"sourceCodeEnd":1879,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs#L1843-L1879","documentation":"Raised by handle_inlay_hints_resolve via ensure! when the file_id carried in the InlayHintResolveData refers to a file the GlobalStateSnapshot no longer knows about (snap.file_exists(file_id) is false). The resolve data was stale and pointed at a deleted/never-loaded file.","triggerScenarios":"A client sends an inlayHint/resolve request whose data field encodes a file_id that the server has since evicted or never loaded — file deleted from disk, workspace reloaded, or the hint originated from a stale version. Unlike version/hash mismatches (which return Ok gracefully), a missing file is treated as a hard error.","commonSituations":"Client retries an old resolve after a workspace reload; the file was deleted between hint computation and resolve; a third-party client cached hints across restarts.","solutions":["On the client side, invalidate cached inlay hints when files change or the workspace is reloaded, and re-request hints rather than resolving stale ones.","If you control the client, treat resolve failures by re-issuing textDocument/inlayHint for the visible range.","Server-side, consider returning Ok(original_hint) instead of erroring for missing files to match the version-mismatch path's resilience."],"exampleFix":"// before: hard error on a missing file\nanyhow::ensure!(snap.file_exists(file_id), \"Invalid LSP resolve data\");\n\n// after: degrade gracefully like the stale-version branch above it\nif !snap.file_exists(file_id) {\n    tracing::warn!(\"Inlay hint resolve references an unknown file_id {file_id}\");\n    return Ok(original_hint);\n}","handlingStrategy":"fallback","validationCode":"// Client-side: invalidate cached inlay hints on file/version changes so you\n// never resolve against a file_id the server has forgotten.\non DidChangeWatchedFiles / workspace reload => clear hintCache.clear();\non visible range refresh => re-request textDocument/inlayHint instead of resolving stale hints.","typeGuard":"null","tryCatchPattern":"// Server-side resilience: treat a missing file like the stale-version case:\nif !snap.file_exists(file_id) {\n    tracing::warn!(\"inlay hint resolve references unknown file {file_id}\");\n    return Ok(original_hint); // graceful degradation instead of an LSP error\n}","preventionTips":["Invalidate cached hints on file delete/rename and workspace reload.","Re-request hints rather than resolving stale data after reloads.","Server-side, prefer Ok(original_hint) over ensure! for transient stale references."],"tags":["rust-analyzer","lsp","inlay-hints","stale-state"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}