slint-ui/slint · error

Identifier is in unknown document

Error message

Identifier is in unknown document

What it means

`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.

Solutions

  1. Ensure all imported .slint files are loaded before triggering rename
  2. Return an error from get_document_for_source_file instead of expect
  3. Reload/save files so the LSP re-parses and repopulates the cache
  4. Restart the Slint LSP server to rebuild the document cache

Example fix

// before
let document = document_cache.get_document_for_source_file(source_file)
    .expect("Identifier is in unknown document");

// after
let Some(document) = document_cache.get_document_for_source_file(source_file) else {
    return Err("Identifier is in unknown document".into());
};
Defensive patterns

Strategy: validation

Validate before calling

if document_cache.get_document_for_source_file(source_file).is_none() {
    return Err("Identifier is in unknown document".into());
}

Type guard

fn document_known(cache: &DocumentCache, f: &SourceFile) -> bool { cache.get_document_for_source_file(f).is_some() }

Try / catch

// server-side, fail the rename request gracefully
match rename_declared_identifier(...) {
    Ok(edit) => Ok(edit),
    Err(e) => Err(lsp Error::internal_error(format!("rename failed: {e}"))),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16). Data as JSON: /api/errors/eea163463da4239f. Report an issue: GitHub.

Appendix: source

Thrown at internal/editor-preview/editing/rename_component.rs:1252

}

/// Rename a `DeclaredIdentifier`.
///
/// This is a locally defined thing.
///
/// Fix up local usages, fix exports and any imports elsewhere if the exports changed
fn rename_declared_identifier(
    document_cache: &crate::DocumentCache,
    query: &DeclarationNodeQuery,
    declared_identifier: &syntax_nodes::DeclaredIdentifier,
    new_type: &str,
) -> crate::Result<lsp_types::WorkspaceEdit> {
    let ti = &query.token_info;

    let source_file = &declared_identifier.source_file;
    let document = document_cache
        .get_document_for_source_file(source_file)
        .expect("Identifier is in unknown document");

    let Some(document_node) = &document.node else {
        return Err("No document found".into());
    };

    let parent = declared_identifier.parent().unwrap();

    let normalized_new_type = i_slint_compiler::parser::normalize_identifier(new_type);

    if parent.kind() != SyntaxKind::Component
        && document.local_registry.lookup(normalized_new_type.as_str())
            != i_slint_compiler::langtype::Type::Invalid
    {
        return Err(format!("{new_type} is already a registered type").into());
    }
    if parent.kind() == SyntaxKind::Component
        && document.local_registry.lookup_element(normalized_new_type.as_str()).is_ok()
    {

View on GitHub (pinned to bb937076de)