Maps filetypes to tree-sitter grammar names and locates highlight queries.
Filetypes (atoms from Minga.Language.Filetype) resolve to tree-sitter grammar names from the registered %Minga.Language{} definitions. The fallback grammar name comes from the language record itself, not a static in-module table. Highlight queries are loaded from priv/queries/{language}/highlights.scm with an optional user override in ~/.config/minga/queries/{language}/highlights.scm.
Summary
Types
A tree-sitter language name.
Functions
Returns the expected path for a dynamically-loaded grammar shared library.
Initializes the dynamic language registry ETS table.
Returns the path to the injection query file for a language.
Returns the tree-sitter language name for a filetype atom.
Returns the path to the highlight query file for a language.
Reads the injection query content for a language.
Reads the highlight query content for a language.
Registers a dynamic filetype-to-grammar mapping.
Returns the full filetype-to-grammar mapping, including dynamic registrations.
Types
@type language() :: String.t()
A tree-sitter language name.
Functions
Returns the expected path for a dynamically-loaded grammar shared library.
Path: ~/.config/minga/grammars/{name}.so (or .dylib on macOS).
@spec init_registry() :: :ok
Initializes the dynamic language registry ETS table.
Called once at application startup. The table stores runtime-registered filetype-to-grammar mappings from extensions. Lookups check this table first, then fall back to the grammar name on the registered %Minga.Language{} definition.
Returns the path to the injection query file for a language.
Checks user config dir first (~/.config/minga/queries/{lang}/injections.scm),
then falls back to priv/queries/{lang}/injections.scm.
Returns nil if no injection query file exists.
Returns the tree-sitter language name for a filetype atom.
Checks the dynamic registry (populated by extensions) first, then falls back to the grammar name on the registered %Minga.Language{} definition.
Examples
iex> Minga.Language.Grammar.language_for_filetype(:elixir)
{:ok, "elixir"}
iex> Minga.Language.Grammar.language_for_filetype(:typescript_react)
{:ok, "tsx"}
iex> Minga.Language.Grammar.language_for_filetype(:text)
:unsupported
Returns the path to the highlight query file for a language.
Checks user config dir first (~/.config/minga/queries/{lang}/highlights.scm),
then falls back to priv/queries/{lang}/highlights.scm.
Returns nil if no query file exists.
@spec read_injection_query(language()) :: {:ok, String.t()} | {:error, :no_query | File.posix()}
Reads the injection query content for a language.
Returns {:ok, query_text} or {:error, reason}.
@spec read_query(language()) :: {:ok, String.t()} | {:error, :no_query | File.posix()}
Reads the highlight query content for a language.
Returns {:ok, query_text} or {:error, reason}.
Registers a dynamic filetype-to-grammar mapping.
Extensions call this to make their grammar available for syntax highlighting. The mapping is checked before the registered-language fallback, so extensions can override bundled grammars.
Examples
Minga.Language.Grammar.register_language(:org, "org")
Minga.Language.Grammar.register_language(:astro, "astro")
Returns the full filetype-to-grammar mapping, including dynamic registrations.