From e3c4edae32f6d70bf20655c7c25b3cdf39f3f281 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 25 Mar 2021 15:26:25 +0900 Subject: Add the machinery to load syntax config from TOML. It's embedded into the binary at build time for now, but it's progress. --- helix-term/Cargo.toml | 3 +++ helix-term/src/main.rs | 8 ++++++++ helix-term/src/ui/markdown.rs | 2 ++ 3 files changed, 13 insertions(+) (limited to 'helix-term') diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index eaf8ebd7..2f3aa384 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -41,3 +41,6 @@ ignore = "0.4" dirs-next = "2.0" # markdown doc rendering pulldown-cmark = { version = "0.8", default-features = false } + +# config +toml = "0.5" diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 84b52ea2..dc6f31f4 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -73,6 +73,14 @@ fn main() { setup_logging(verbosity).expect("failed to initialize logging."); + // initialize language registry + use helix_core::syntax::{Loader, LOADER}; + let toml = include_str!("../../languages.toml"); + LOADER.get_or_init(|| { + let config = toml::from_str(&toml).expect("Could not parse languages.toml"); + Loader::new(config) + }); + for _ in 0..num_cpus::get() { std::thread::spawn(move || smol::block_on(EX.run(smol::future::pending::<()>()))); } diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index c4f6039b..55b90ad4 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -80,6 +80,8 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> { let rope = Rope::from(text.as_ref()); let syntax = syntax::LOADER + .get() + .unwrap() .language_config_for_scope(&format!("source.{}", language)) .and_then(|config| config.highlight_config(theme.scopes())) .map(|config| Syntax::new(&rope, config)); -- cgit v1.2.3-70-g09d2