Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r--xtask/src/main.rs73
1 files changed, 37 insertions, 36 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 7bb7e8c9..c7440fcc 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -8,7 +8,6 @@ type DynError = Box<dyn Error>;
pub mod tasks {
use crate::DynError;
- use std::collections::HashSet;
pub fn docgen() -> Result<(), DynError> {
use crate::docgen::*;
@@ -18,26 +17,37 @@ pub mod tasks {
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;
+ pub fn querycheck() -> 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());
+ }
+ }
+ }
}
- 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)?;
}
println!("Query check succeeded");
@@ -45,11 +55,9 @@ pub mod tasks {
Ok(())
}
- pub fn themecheck(themes: impl Iterator<Item = String>) -> Result<(), DynError> {
+ pub fn themecheck() -> 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()),
@@ -59,10 +67,6 @@ pub mod tasks {
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() {
@@ -89,25 +93,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.
+ query-check: Check that tree-sitter queries are valid.
+ theme-check: Check that theme files in runtime/themes 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)?,
+ "query-check" => tasks::querycheck()?,
+ "theme-check" => tasks::themecheck()?,
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
},
};