diff --git a/zee-grammar/src/builder.rs b/zee-grammar/src/builder.rs index c1dcfa7..8b9636a 100644 --- a/zee-grammar/src/builder.rs +++ b/zee-grammar/src/builder.rs @@ -74,7 +74,19 @@ pub fn fetch_and_build_tree_sitter_parsers( mode_configs.into_par_iter().try_for_each(|config| { if let Some(ref grammar) = config.grammar { let fetched = fetch_grammar(grammar)?; - let built = build_grammar(grammar, defaults)?; + let built = build_grammar( + grammar, + defaults, + match &config.grammar { + Some(cfg) => match &cfg.source { + GrammarSource::Git { + scheme_dir: scm, .. + } => scm, + _ => &None, + }, + None => &None, + }, + )?; log::info!( "{:>12} {} grammar {}", if fetched || built { @@ -142,7 +154,11 @@ fn fetch_grammar(grammar: &GrammarConfig) -> Result { Ok(revision_changed) } -fn build_grammar(grammar: &GrammarConfig, defaults: &Dir) -> Result { +fn build_grammar( + grammar: &GrammarConfig, + defaults: &Dir, + scheme_dir: &Option, +) -> Result { let (grammar_dir, subpath) = match grammar.source { GrammarSource::Local { ref path } => (path.clone(), None), GrammarSource::Git { @@ -169,7 +185,7 @@ fn build_grammar(grammar: &GrammarConfig, defaults: &Dir) -> Result { bail!("Directory {grammar_dir:?} is empty.",); }; - copy_tree_sitter_queries(&grammar.grammar_id, &grammar_dir, defaults)?; + copy_tree_sitter_queries(&grammar.grammar_id, &grammar_dir, defaults, scheme_dir)?; // Build the tree sitter library let paths = TreeSitterPaths::new(grammar_dir.clone(), subpath); @@ -347,7 +363,12 @@ fn tree_sitter_library_path(grammar_id: &str) -> Result { Ok(library_path) } -fn copy_tree_sitter_queries(grammar_id: &str, source: &Path, defaults: &Dir) -> Result<()> { +fn copy_tree_sitter_queries( + grammar_id: &str, + source: &Path, + defaults: &Dir, + scheme_dir: &Option, +) -> Result<()> { let query_dir_dest = tree_sitter_query_dir(grammar_id)?; std::fs::create_dir_all(&query_dir_dest).with_context(|| { format!( @@ -396,7 +417,12 @@ fn copy_tree_sitter_queries(grammar_id: &str, source: &Path, defaults: &Dir) -> } // Otherwise, copy it from the git repo, if available - let query_src = source.join(QUERY_DIR).join(query_filename); + let query_src = source + .join(match scheme_dir { + Some(dir) => dir, + None => QUERY_DIR, + }) + .join(query_filename); if query_src.exists() { log_on_error( grammar_id, diff --git a/zee-grammar/src/config.rs b/zee-grammar/src/config.rs index 78c9dbe..5730ab3 100644 --- a/zee-grammar/src/config.rs +++ b/zee-grammar/src/config.rs @@ -125,6 +125,8 @@ pub enum GrammarSource { remote: String, #[serde(rename = "rev")] revision: String, + #[serde(default, rename = "scm")] + scheme_dir: Option, path: Option, }, } diff --git a/zee/config/config.ron b/zee/config/config.ron index 926d4f8..565d61c 100644 --- a/zee/config/config.ron +++ b/zee/config/config.ron @@ -225,6 +225,32 @@ ), ), + // Just Build System + Mode( + name: "Just Build System", + scope: "source.justfile", + injection_regex: "just(file)?", + patterns: [ + Name(".justfile"), + Name("justfile"), + ], + comment: Some(Comment(token: "# ")), + indentation: Indentation( + width: 4, + unit: Space, + ), + grammar: Some( + Grammar( + id: "just", + source: Git( + git: "https://github.com/IndianBoy42/tree-sitter-just", + rev: "8af0aab79854aaf25b620a52c39485849922f766", + scm: Some("queries/just"), + ), + ) + ), + ), + // Markdown Mode( name: "Markdown",