diff options
author | Michael Davis | 2022-02-15 05:23:01 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-03-10 08:31:57 +0000 |
commit | 08ee949dcb904dc27aa41a62ad686c14c0a406bb (patch) | |
tree | 60c897b886751612b51de60705112b4a0c929b76 /helix-term/src | |
parent | db3470d973ed97445d180c18035c2858e4749782 (diff) |
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.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/grammars.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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<GrammarConfiguration> { 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<()> { |