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.
This commit is contained in:
Michael Davis 2022-02-14 23:23:01 -06:00 committed by Blaž Hrastnik
parent db3470d973
commit 08ee949dcb
4 changed files with 36 additions and 4 deletions

View file

@ -81,12 +81,21 @@ where
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Configuration {
#[serde(rename = "use-grammars")]
pub grammar_selection: Option<GrammarSelection>,
pub language: Vec<LanguageConfiguration>,
pub grammar: Vec<GrammarConfiguration>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase", untagged)]
pub enum GrammarSelection {
Only(HashSet<String>),
Except(HashSet<String>),
}
// largely based on tree-sitter/cli/src/loader.rs
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
@ -2110,6 +2119,7 @@ mod test {
let loader = Loader::new(Configuration {
language: vec![],
grammar: vec![],
grammar_selection: None,
});
let language = get_language(&crate::RUNTIME_DIR, "Rust").unwrap();