xtask: Inline query and theme checks into main module

This reverts cosmetic changes from <https://redirect.github.com/helix-editor/helix/pull/3234>:
that PR split the tasks into separate modules but the query and theme
check tasks are small enough that splitting them into separate files (or
modules) adds unnecessary friction.

This change also adds `theme-check` to the help message for the xtask
crate.
This commit is contained in:
Michael Davis 2025-02-24 10:46:35 -05:00
parent e1c26ebfc7
commit 6182bdc860
No known key found for this signature in database
3 changed files with 66 additions and 82 deletions

View file

@ -1,23 +1,16 @@
mod docgen; mod docgen;
mod helpers; mod helpers;
mod path; mod path;
mod querycheck;
mod theme_check;
use std::{env, error::Error}; use std::{env, error::Error};
type DynError = Box<dyn Error>; type DynError = Box<dyn Error>;
pub mod tasks { pub mod tasks {
use crate::docgen::{lang_features, static_commands, typable_commands, write};
use crate::docgen::{
LANG_SUPPORT_MD_OUTPUT, STATIC_COMMANDS_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT,
};
use crate::querycheck::query_check;
use crate::theme_check::theme_check;
use crate::DynError; use crate::DynError;
pub fn docgen() -> Result<(), DynError> { pub fn docgen() -> Result<(), DynError> {
use crate::docgen::*;
write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?); write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?);
write(STATIC_COMMANDS_MD_OUTPUT, &static_commands()?); write(STATIC_COMMANDS_MD_OUTPUT, &static_commands()?);
write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?); write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?);
@ -25,11 +18,73 @@ pub mod tasks {
} }
pub fn querycheck() -> Result<(), DynError> { pub fn querycheck() -> Result<(), DynError> {
query_check() use crate::helpers::lang_config;
use helix_core::{syntax::read_query, tree_sitter::Query};
use helix_loader::grammar::get_language;
let query_files = [
"highlights.scm",
"locals.scm",
"injections.scm",
"textobjects.scm",
"indents.scm",
];
for language in lang_config().language {
let language_name = &language.language_id;
let grammar_name = language.grammar.as_ref().unwrap_or(language_name);
for query_file in query_files {
let language = get_language(grammar_name);
let query_text = read_query(language_name, query_file);
if let Ok(lang) = language {
if !query_text.is_empty() {
if let Err(reason) = Query::new(&lang, &query_text) {
return Err(format!(
"Failed to parse {} queries for {}: {}",
query_file, language_name, reason
)
.into());
}
}
}
}
}
println!("Query check succeeded");
Ok(())
} }
pub fn themecheck() -> Result<(), DynError> { pub fn themecheck() -> Result<(), DynError> {
theme_check() use helix_view::theme::Loader;
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 {
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 print_help() { pub fn print_help() {
@ -40,6 +95,7 @@ Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
Tasks: Tasks:
docgen: Generate files to be included in the mdbook output. docgen: Generate files to be included in the mdbook output.
query-check: Check that tree-sitter queries are valid. query-check: Check that tree-sitter queries are valid.
theme-check: Check that theme files in runtime/themes are valid.
" "
); );
} }

View file

@ -1,39 +0,0 @@
use crate::DynError;
pub fn query_check() -> Result<(), DynError> {
use crate::helpers::lang_config;
use helix_core::{syntax::read_query, tree_sitter::Query};
use helix_loader::grammar::get_language;
let query_files = [
"highlights.scm",
"locals.scm",
"injections.scm",
"textobjects.scm",
"indents.scm",
];
for language in lang_config().language {
let language_name = &language.language_id;
let grammar_name = language.grammar.as_ref().unwrap_or(language_name);
for query_file in query_files {
let language = get_language(grammar_name);
let query_text = read_query(language_name, query_file);
if let Ok(lang) = language {
if !query_text.is_empty() {
if let Err(reason) = Query::new(&lang, &query_text) {
return Err(format!(
"Failed to parse {} queries for {}: {}",
query_file, language_name, reason
)
.into());
}
}
}
}
}
println!("Query check succeeded");
Ok(())
}

View file

@ -1,33 +0,0 @@
use helix_view::theme::Loader;
use crate::{path, DynError};
pub fn theme_check() -> Result<(), DynError> {
let theme_names = [
vec!["default".to_string(), "base16_default".to_string()],
Loader::read_names(&path::themes()),
]
.concat();
let loader = Loader::new(&[path::runtime()]);
let mut errors_present = false;
for name in theme_names {
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(())
}
}
}