From c1f90a127b972c8b41b0d24dcacb3bdd480be9c5 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 13 Feb 2022 12:11:44 -0600 Subject: add tree-sitter sources to languages.toml Here we add syntax to the languages.toml languge [[grammar]] name = "" source = { .. } Which can be used to specify a tree-sitter grammar separately of the language that defines it, and we make this distinction for two reasons: * In later commits, we will separate this code from helix-core and bring it to a new helix-loader crate. Using separate schemas for language and grammar configurations allows for a nice divide between the types needed to be declared in helix-loader and in helix-core/syntax * Two different languages may use the same grammar. This is currently the case with llvm-mir-yaml and yaml. We could accomplish a config that works for this with just `[[languages]]`, but it gets a bit dicey with languages depending on one another. If you enable llvm-mir-yaml and disable yaml, does helix still need to fetch and build tree-sitter-yaml? It could be a matter of interpretation. --- helix-core/src/syntax.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'helix-core/src/syntax.rs') diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index c39e0584..53d20da3 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -54,6 +54,7 @@ where #[serde(deny_unknown_fields)] pub struct Configuration { pub language: Vec, + pub grammar: Vec, } // largely based on tree-sitter/cli/src/loader.rs @@ -239,6 +240,29 @@ pub struct IndentQuery { pub outdent: HashSet, } +#[derive(Debug, Serialize, Deserialize)] +pub struct GrammarConfiguration { + #[serde(rename = "name")] + pub grammar_id: String, // c-sharp, rust + pub source: GrammarSource, + pub path: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +#[serde(untagged)] +pub enum GrammarSource { + Local { + path: String, + }, + Git { + #[serde(rename = "git")] + remote: String, + #[serde(rename = "rev")] + revision: String, + }, +} + #[derive(Debug)] pub struct TextObjectQuery { pub query: Query, @@ -2055,7 +2079,10 @@ mod test { .map(String::from) .collect(); - let loader = Loader::new(Configuration { language: vec![] }); + let loader = Loader::new(Configuration { + language: vec![], + grammar: vec![], + }); let language = get_language(&crate::RUNTIME_DIR, "Rust").unwrap(); let config = HighlightConfiguration::new( -- cgit v1.2.3-70-g09d2