From 08ee949dcb904dc27aa41a62ad686c14c0a406bb Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 14 Feb 2022 23:23:01 -0600 Subject: add 'use-grammars' to languages.toml The vision with 'use-grammars' is to allow the long-requested feature of being able to declare your own set of grammars that you would like. A simple schema with only/except grammar names controls the list of grammars that is fetched and built. It does not (yet) control which grammars may be loaded at runtime if they already exist. --- helix-term/src/grammars.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/grammars.rs b/helix-term/src/grammars.rs index 7a7a4c18..2e0be4bc 100644 --- a/helix-term/src/grammars.rs +++ b/helix-term/src/grammars.rs @@ -7,7 +7,7 @@ use std::{ sync::mpsc::channel, }; -use helix_core::syntax::{GrammarConfiguration, GrammarSource, DYLIB_EXTENSION}; +use helix_core::syntax::{GrammarConfiguration, GrammarSelection, GrammarSource, DYLIB_EXTENSION}; const BUILD_TARGET: &str = env!("BUILD_TARGET"); const REMOTE_NAME: &str = "origin"; @@ -163,7 +163,19 @@ fn build_grammar(grammar: GrammarConfiguration) -> Result<()> { fn get_grammar_configs() -> Vec { let config = helix_core::config::user_syntax_loader().expect("Could not parse languages.toml"); - config.grammar + match config.grammar_selection { + Some(GrammarSelection::Only(selections)) => config + .grammar + .into_iter() + .filter(|grammar| selections.contains(&grammar.grammar_id)) + .collect(), + Some(GrammarSelection::Except(rejections)) => config + .grammar + .into_iter() + .filter(|grammar| !rejections.contains(&grammar.grammar_id)) + .collect(), + None => config.grammar, + } } fn build_tree_sitter_library(src_path: &Path, grammar: GrammarConfiguration) -> Result<()> { -- cgit v1.2.3-70-g09d2