Skip to main content

resolve_major_mode

Function resolve_major_mode 

Source
pub fn resolve_major_mode(
    registry: &ModeRegistry,
    kind: BufferKind,
    lang: Lang,
    path: Option<&Path>,
) -> ModeId
Expand description

Resolve the major-mode id a buffer should activate based on its kind + (for Document kinds) detected language.

H.2 (2026-05-31): rewritten to consult the ModeRegistry’s kind index (major_mode_id_for_buffer_kind) for non-Document kinds, then lattice_syntax::major_mode_id_for_lang for Document-kind buffers, finally falling back to TextMode when neither layer matches (Document + Lang::Plain, or an unknown / unbound kind).

OM.1 (2026-08-24): a third layer between the two — the registry’s language index (ModeRegistry::find_major_for_lang). It is what lets a plugin-contributed language have a major at all: major_mode_id_for_lang is a hand-written match over the Lang enum and returns None for Lang::Plugin(_) by design, since the host does not know the language exists until a plugin says so. Before this layer a .org file landed in text-mode.

The built-in table is consulted first, so a plugin cannot take rust-mode’s language out from under it. When the built-in majors eventually migrate onto Mode::target_language the table shrinks, the index grows, and the order between them stops mattering.