zed-industries/zed · error

missing config for language {:?}

Error message

missing config for language {:?}

What it means

The grammars crate embeds each language's config.toml at compile time via a directory embed and looks it up by name in load_config(name). If no embedded file matches "<name>/config.toml", it panics with 'missing config for language'. The function returns LanguageConfig directly (not a Result), so a missing file is treated as a programmer error: every language name reaching this API must have shipped a config.

Source

Thrown at crates/grammars/src/grammars.rs:49

        ("json", tree_sitter_json::LANGUAGE.into()),
        ("jsonc", tree_sitter_json::LANGUAGE.into()),
        ("markdown", tree_sitter_md::LANGUAGE.into()),
        ("markdown-inline", tree_sitter_md::INLINE_LANGUAGE.into()),
        ("python", tree_sitter_python::LANGUAGE.into()),
        ("regex", tree_sitter_regex::LANGUAGE.into()),
        ("rust", tree_sitter_rust::LANGUAGE.into()),
        ("tsx", tree_sitter_typescript::LANGUAGE_TSX.into()),
        (
            "typescript",
            tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
        ),
        ("yaml", tree_sitter_yaml::LANGUAGE.into()),
        ("gitcommit", tree_sitter_gitcommit::LANGUAGE.into()),
    ]
}

/// Load and parse the `config.toml` for a given language name.
pub fn load_config(name: &str) -> LanguageConfig {
    let config_toml = String::from_utf8(
        GrammarDir::get(&format!("{}/config.toml", name))
            .unwrap_or_else(|| panic!("missing config for language {:?}", name))
            .data
            .to_vec(),
    )
    .unwrap();

    let config = LanguageConfig::from_toml(&config_toml)
        .with_context(|| format!("failed to load config.toml for language {name:?}"))
        .unwrap();

    config
}

/// Load and parse the `config.toml` for a given language name, stripping fields
/// that require grammar support when grammars are not loaded.
pub fn load_config_for_feature(name: &str, grammars_loaded: bool) -> LanguageConfig {

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Create the missing config.toml in the grammars crate's embedded languages directory using the path pattern <languages-root>/<name>/config.toml
  2. Check exact name spelling and casing against the registered grammar ids (lowercase names like 'typescript', 'gitcommit')
  3. cargo clean (or touch the grammars crate) so the embedded-directory macro re-scans and includes the new file
  4. If the name comes from user input, validate it against the known built-in language list before calling load_config

Example fix

// before: panics for any unknown name
let config = grammars::load_config(&language_name);

// after: check the embedded tree first and fail softly
let config = match GrammarDir::get(&format!("{}/config.toml", language_name)) {
    Some(file) => toml::from_str(std::str::from_utf8(&file.data)?)?,
    None => return Err(anyhow!("no built-in grammar config for {language_name}")),
};
Defensive patterns

Strategy: validation

Validate before calling

// check the embedded tree before calling load_config
pub fn has_config(name: &str) -> bool {
    GrammarDir::get(&format!("{}/config.toml", name)).is_some()
}

let config = if has_config(name) {
    Some(grammars::load_config(name))
} else {
    None // or fall back to a default LanguageConfig
};

Prevention

When it happens

Trigger: Calling grammars::load_config(name) where name has no embedded config.toml: a newly added tree-sitter grammar whose config file was never created, a renamed language, or a caller passing an unvalidated string ('Rust' instead of 'rust', a grammar id that is not a built-in language).

Common situations: Contributors adding a grammar but forgetting the embedded config.toml; a stale build cache where the embed macro did not pick up newly added files until a clean rebuild; feeding arbitrary language identifiers from settings or LSP into load_config.

Related errors


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/eea5ef03c2b7598e. Report an issue: GitHub.