From ea9830f04b08be8f8f1e649be9925a6b9f5589e9 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 31 Jan 2026 17:27:53 -0700 Subject: [PATCH] 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 --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/highlight.rs | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6907576..b41cf95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index b5b80ea..0332a22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/highlight.rs b/src/highlight.rs index cddbc26..434d685 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -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 = LazyLock::new(|| { ) }); +static TOML_CONFIG: LazyLock = LazyLock::new(|| { + make_config( + tree_sitter_toml_ng::LANGUAGE.into(), + "toml", + tree_sitter_toml_ng::HIGHLIGHTS_QUERY, + "", + ) +}); + static TYPESCRIPT_CONFIG: LazyLock = 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, }