Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'xtask/src/main.rs')
| -rw-r--r-- | xtask/src/main.rs | 90 |
1 files changed, 18 insertions, 72 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7bb7e8c9..1421fd1a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,86 +1,35 @@ mod docgen; mod helpers; mod path; +mod querycheck; +mod themelint; use std::{env, error::Error}; type DynError = Box<dyn Error>; pub mod tasks { + use crate::docgen::{lang_features, typable_commands, write}; + use crate::docgen::{LANG_SUPPORT_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT}; + use crate::querycheck::query_check; + use crate::themelint::{lint, lint_all}; use crate::DynError; - use std::collections::HashSet; pub fn docgen() -> Result<(), DynError> { - use crate::docgen::*; write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?); - write(STATIC_COMMANDS_MD_OUTPUT, &static_commands()?); write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?); Ok(()) } - pub fn querycheck(languages: impl Iterator<Item = String>) -> Result<(), DynError> { - use helix_core::syntax::LanguageData; - - let languages_to_check: HashSet<_> = languages.collect(); - let loader = helix_core::config::default_lang_loader(); - for (_language, lang_data) in loader.languages() { - if !languages_to_check.is_empty() - && !languages_to_check.contains(&lang_data.config().language_id) - { - continue; - } - let config = lang_data.config(); - let Some(syntax_config) = LanguageData::compile_syntax_config(config, &loader)? else { - continue; - }; - let grammar = syntax_config.grammar; - LanguageData::compile_indent_query(grammar, config)?; - LanguageData::compile_textobject_query(grammar, config)?; - LanguageData::compile_tag_query(grammar, config)?; - LanguageData::compile_rainbow_query(grammar, config)?; + pub fn themelint(file: Option<String>) -> Result<(), DynError> { + match file { + Some(file) => lint(file), + None => lint_all(), } - - println!("Query check succeeded"); - - Ok(()) } - pub fn themecheck(themes: impl Iterator<Item = String>) -> Result<(), DynError> { - use helix_view::theme::Loader; - - let themes_to_check: HashSet<_> = themes.collect(); - - let theme_names = [ - vec!["default".to_string(), "base16_default".to_string()], - Loader::read_names(&crate::path::themes()), - ] - .concat(); - let loader = Loader::new(&[crate::path::runtime()]); - let mut errors_present = false; - - for name in theme_names { - if !themes_to_check.is_empty() && !themes_to_check.contains(&name) { - continue; - } - - let (_, warnings) = loader.load_with_warnings(&name).unwrap(); - - if !warnings.is_empty() { - errors_present = true; - println!("Theme '{name}' loaded with errors:"); - for warning in warnings { - println!("\t* {}", warning); - } - } - } - - match errors_present { - true => Err("Errors found when loading bundled themes".into()), - false => { - println!("Theme check successful!"); - Ok(()) - } - } + pub fn querycheck() -> Result<(), DynError> { + query_check() } pub fn print_help() { @@ -89,25 +38,22 @@ pub mod tasks { Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`. Tasks: - docgen Generate files to be included in the mdbook output. - query-check [languages] Check that tree-sitter queries are valid for the given - languages, or all languages if none are specified. - theme-check [themes] Check that the theme files in runtime/themes/ are valid for the - given themes, or all themes if none are specified. + docgen: Generate files to be included in the mdbook output. + themelint <theme>: Report errors for <theme>, or all themes if no theme is specified. + query-check: Check that tree-sitter queries are valid. " ); } } fn main() -> Result<(), DynError> { - let mut args = env::args().skip(1); - let task = args.next(); + let task = env::args().nth(1); match task { None => tasks::print_help(), Some(t) => match t.as_str() { "docgen" => tasks::docgen()?, - "query-check" => tasks::querycheck(args)?, - "theme-check" => tasks::themecheck(args)?, + "themelint" => tasks::themelint(env::args().nth(2))?, + "query-check" => tasks::querycheck()?, invalid => return Err(format!("Invalid task name: {}", invalid).into()), }, }; |