feat(highlight): add TOML syntax highlighting

Use tree-sitter-toml-ng v0.7.0 from tree-sitter-grammars, which is
compatible with tree-sitter 0.26 (unlike the older tree-sitter-toml).

- Add tree-sitter-toml-ng dependency
- Add Toml variant to Language enum
- Add TOML_CONFIG with crate's HIGHLIGHTS_QUERY
This commit is contained in:
Timothy DeHerrera
2026-01-31 17:27:53 -07:00
parent 905897b3c4
commit ea9830f04b
3 changed files with 24 additions and 0 deletions

11
Cargo.lock generated
View File

@@ -1535,6 +1535,7 @@ dependencies = [
"tree-sitter-nix",
"tree-sitter-python",
"tree-sitter-rust",
"tree-sitter-toml-ng",
"tree-sitter-typescript",
"tree-sitter-yaml",
"walkdir",
@@ -1850,6 +1851,16 @@ dependencies = [
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-toml-ng"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9adc2c898ae49730e857d75be403da3f92bb81d8e37a2f918a08dd10de5ebb1"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-typescript"
version = "0.23.2"

View File

@@ -39,6 +39,7 @@ toml = "0.8"
# Diagram rendering
mermaid-rs-renderer = { version = "0.1", default-features = false }
tree-sitter-md = "0.5.2"
tree-sitter-toml-ng = "0.7.0"
# Patch dagre_rust to fix unwrap on None bug
[patch.crates-io]

View File

@@ -91,6 +91,7 @@ pub enum Language {
Nix,
Python,
Rust,
Toml,
TypeScript,
Yaml,
}
@@ -110,6 +111,7 @@ impl Language {
"nix" => Some(Language::Nix),
"python" | "py" => Some(Language::Python),
"rust" | "rs" => Some(Language::Rust),
"toml" => Some(Language::Toml),
"typescript" | "ts" | "tsx" => Some(Language::TypeScript),
"yaml" | "yml" => Some(Language::Yaml),
_ => None,
@@ -231,6 +233,15 @@ static RUST_CONFIG: LazyLock<HighlightConfiguration> = LazyLock::new(|| {
)
});
static TOML_CONFIG: LazyLock<HighlightConfiguration> = LazyLock::new(|| {
make_config(
tree_sitter_toml_ng::LANGUAGE.into(),
"toml",
tree_sitter_toml_ng::HIGHLIGHTS_QUERY,
"",
)
});
static TYPESCRIPT_CONFIG: LazyLock<HighlightConfiguration> = LazyLock::new(|| {
make_config(
tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
@@ -263,6 +274,7 @@ fn get_config(lang: Language) -> &'static HighlightConfiguration {
Language::Nix => &NIX_CONFIG,
Language::Python => &PYTHON_CONFIG,
Language::Rust => &RUST_CONFIG,
Language::Toml => &TOML_CONFIG,
Language::TypeScript => &TYPESCRIPT_CONFIG,
Language::Yaml => &YAML_CONFIG,
}