Minga.Language.Filetype (Minga v0.1.0)

Copy Markdown View Source

Detects a file's language from its path and content.

Detection priority follows Neovim-style behavior:

  1. Runtime exact filename overrides from Minga.Language.Filetype.Registry
  2. Source-owned exact filename entries from Minga.Language.Registry
  3. Runtime extension overrides from Minga.Language.Filetype.Registry
  4. Source-owned extension entries from Minga.Language.Registry
  5. .env* / .envrc* pattern when :bash is still registered
  6. Shebang line from the first line of content
  7. Fall back to :text

Built-in language mappings come from registered language definitions in Minga.Language.Registry. Runtime overrides stay separate so config and extensions can temporarily redirect a pattern without owning a full language definition.

Summary

Types

A language identifier atom.

Functions

Detects the language of a file from its path alone.

Detects the language from a file path and the first line of content.

Returns runtime extension overrides. Registered language definitions live in Minga.Language.Registry, so this map is empty in normal builds.

Returns runtime filename overrides. Registered language definitions live in Minga.Language.Registry, so this map is empty in normal builds.

Returns runtime shebang overrides. Registered language definitions live in Minga.Language.Registry, so this map is empty in normal builds.

Types

filetype()

@type filetype() :: atom()

A language identifier atom.

Functions

detect(file_path)

@spec detect(String.t() | nil) :: filetype()

Detects the language of a file from its path alone.

Checks runtime filename overrides, bundled exact filenames, runtime extension overrides, bundled extensions, and .env*/.envrc* patterns in that order. Returns :text if nothing matches.

detect_from_content(file_path, first_line)

@spec detect_from_content(String.t() | nil, String.t() | nil) :: filetype()

Detects the language from a file path and the first line of content.

Tries detect/1 first. If that returns :text, attempts shebang detection from first_line. Returns :text if nothing matches.

extensions()

@spec extensions() :: %{required(String.t()) => filetype()}

Returns runtime extension overrides. Registered language definitions live in Minga.Language.Registry, so this map is empty in normal builds.

filenames()

@spec filenames() :: %{required(String.t()) => filetype()}

Returns runtime filename overrides. Registered language definitions live in Minga.Language.Registry, so this map is empty in normal builds.

shebang_interpreters()

@spec shebang_interpreters() :: %{required(String.t()) => filetype()}

Returns runtime shebang overrides. Registered language definitions live in Minga.Language.Registry, so this map is empty in normal builds.