{"record":{"id":"b1f58f04007a849f","repo":"rust-lang/rust-analyzer","slug":"we-never-provide-code-actions-for-excluded-files","errorCode":null,"errorMessage":"we never provide code actions for excluded files","messagePattern":"we never provide code actions for excluded files","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rust-analyzer/src/handlers/request.rs","lineNumber":1595,"sourceCode":"        if intersect_fix_range {\n            res.push(fix.action.clone());\n        }\n    }\n\n    Ok(Some(res))\n}\n\npub(crate) fn handle_code_action_resolve(\n    snap: GlobalStateSnapshot,\n    mut code_action: lsp_ext::CodeAction,\n) -> anyhow::Result<lsp_ext::CodeAction> {\n    let _p = tracing::info_span!(\"handle_code_action_resolve\").entered();\n    let Some(params) = code_action.data.take() else {\n        return Ok(code_action);\n    };\n\n    let file_id = from_proto::file_id(&snap, &params.code_action_params.text_document.uri)?\n        .expect(\"we never provide code actions for excluded files\");\n    if snap.file_version(file_id) != params.version {\n        return Err(invalid_params_error(\"stale code action\".to_owned()).into());\n    }\n    let line_index = snap.file_line_index(file_id)?;\n    let range = from_proto::text_range(&line_index, params.code_action_params.range)?;\n    let frange = FileRange { file_id, range };\n    let source_root = snap.analysis.source_root_id(file_id)?;\n\n    let mut assists_config = snap.config.assist(Some(source_root));\n    assists_config.allowed = params\n        .code_action_params\n        .context\n        .only\n        .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect());\n\n    let (assist_index, assist_resolve) = match parse_action_id(&params.id) {\n        Ok(parsed_data) => parsed_data,\n        Err(e) => {","sourceCodeStart":1577,"sourceCodeEnd":1613,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/rust-analyzer/src/handlers/request.rs#L1577-L1613","documentation":"handle_code_action_resolve resolves the FileId recorded in the code action's data. Since rust-analyzer never produces code actions for excluded files, failing to map the URI to a FileId breaks the invariant and panics via expect. It guards the code-action resolve-data contract between server and client.","triggerScenarios":"A client resolves a code action whose embedded textDocument.uri no longer maps to a tracked file — the file was closed, excluded from the workspace, is an untitled/virtual document, or the URI scheme is not convertible by from_proto::file_id.","commonSituations":"Keeping code actions around after closing or excluding a file, editors that persist quick-fixes across workspace reloads, files filtered out by client-side glob exclusions, multi-root workspaces where the file moved to an unregistered root.","solutions":["Re-run the code action request on the currently open file so fresh data with a valid FileId is produced.","Check that the target file is not excluded by settings like files.exclude or rust-analyzer's workspace discovery config.","Reopen/re-add the file to the workspace (didOpen) before resolving old code actions.","Update rust-analyzer and the client extension; discard cached code actions from before a reload."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// client: verify the action's embedded document is still open and not excluded before resolving\nconst uri = action.data?.codeActionParams?.textDocument?.uri;\nif (!uri || isExcluded(uri) || !workspace.textDocuments.some(d => d.uri.toString() === uri)) {\n  return action; // cannot resolve safely\n}","typeGuard":"function isResolvableCodeAction(a: unknown): a is { data: { codeActionParams: { textDocument: { uri: string }; range: unknown }; version: number } } {\n  return typeof a === 'object' && a !== null && 'data' in a &&\n    typeof (a as any)?.data?.codeActionParams?.textDocument?.uri === 'string';\n}","tryCatchPattern":"try {\n  return await client.sendRequest('codeAction/resolve', action);\n} catch (e) {\n  console.warn('code action resolve failed; returning unmodified action', e);\n  return action;\n}","preventionTips":["Discard cached code actions when their source file is closed or excluded.","Re-request code actions after workspace reloads instead of reusing old ones.","Check for stale-version ('stale code action') errors as a signal to refresh actions.","Keep quick-fix storage scoped to the lifetime of the document."],"tags":["lsp","code-actions","panic","file-id"],"backgroundTag":"stale-code-action-resolve-data","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"}