{"record":{"id":"eea163463da4239f","repo":"slint-ui/slint","slug":"identifier-is-in-unknown-document","errorCode":null,"errorMessage":"Identifier is in unknown document","messagePattern":"Identifier is in unknown document","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/editor-preview/editing/rename_component.rs","lineNumber":1252,"sourceCode":"}\n\n/// Rename a `DeclaredIdentifier`.\n///\n/// This is a locally defined thing.\n///\n/// Fix up local usages, fix exports and any imports elsewhere if the exports changed\nfn rename_declared_identifier(\n    document_cache: &crate::DocumentCache,\n    query: &DeclarationNodeQuery,\n    declared_identifier: &syntax_nodes::DeclaredIdentifier,\n    new_type: &str,\n) -> crate::Result<lsp_types::WorkspaceEdit> {\n    let ti = &query.token_info;\n\n    let source_file = &declared_identifier.source_file;\n    let document = document_cache\n        .get_document_for_source_file(source_file)\n        .expect(\"Identifier is in unknown document\");\n\n    let Some(document_node) = &document.node else {\n        return Err(\"No document found\".into());\n    };\n\n    let parent = declared_identifier.parent().unwrap();\n\n    let normalized_new_type = i_slint_compiler::parser::normalize_identifier(new_type);\n\n    if parent.kind() != SyntaxKind::Component\n        && document.local_registry.lookup(normalized_new_type.as_str())\n            != i_slint_compiler::langtype::Type::Invalid\n    {\n        return Err(format!(\"{new_type} is already a registered type\").into());\n    }\n    if parent.kind() == SyntaxKind::Component\n        && document.local_registry.lookup_element(normalized_new_type.as_str()).is_ok()\n    {","sourceCodeStart":1234,"sourceCodeEnd":1270,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/editor-preview/editing/rename_component.rs#L1234-L1270","documentation":"`rename_declared_identifier` looks up the document for the source file of the declared identifier via `document_cache.get_document_for_source_file` and asserts it is known. The panic means the cache has no document for a file that should be loaded, i.e. a stale or incomplete document cache.","triggerScenarios":"Calling `rename` on an identifier whose containing file was never loaded into (or was evicted from) the DocumentCache — e.g. rename on an unresolved/open-file dependency not yet parsed.","commonSituations":"Renaming immediately after opening a file before dependency parsing finished; files modified externally invalidating the cache; multi-file .slint projects with a stale cache entry.","solutions":["Ensure all imported .slint files are loaded before triggering rename","Return an error from get_document_for_source_file instead of expect","Reload/save files so the LSP re-parses and repopulates the cache","Restart the Slint LSP server to rebuild the document cache"],"exampleFix":"// before\nlet document = document_cache.get_document_for_source_file(source_file)\n    .expect(\"Identifier is in unknown document\");\n\n// after\nlet Some(document) = document_cache.get_document_for_source_file(source_file) else {\n    return Err(\"Identifier is in unknown document\".into());\n};","handlingStrategy":"validation","validationCode":"if document_cache.get_document_for_source_file(source_file).is_none() {\n    return Err(\"Identifier is in unknown document\".into());\n}","typeGuard":"fn document_known(cache: &DocumentCache, f: &SourceFile) -> bool { cache.get_document_for_source_file(f).is_some() }","tryCatchPattern":"// server-side, fail the rename request gracefully\nmatch rename_declared_identifier(...) {\n    Ok(edit) => Ok(edit),\n    Err(e) => Err(lsp Error::internal_error(format!(\"rename failed: {e}\"))),\n}","preventionTips":["Wait for the LSP to finish parsing before issuing rename (check diagnostics are ready)","Save/reload all project .slint files after external modifications","Restart the Slint LSP if the document cache seems stale"],"tags":["lsp","rename","document-cache","editor-preview","panic"],"backgroundTag":"resource-not-found","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}