helix/xtask/src/main.rs

175 lines
5.2 KiB
Rust
Raw Normal View History

mod codegen;
feat: xtask themelint (#3234) * feat: cargo xtask themelint <theme> * fix: add docs and print json error status * fix: refactor paths -> path * fix: remove unused function * fix: only report one err per scope (ui.statusline is reported if none of ui.statusline.* is recognized) * fix: save work for later * fix: finally decided on a design * fix: ready for discussion * fix: better rules * fix: lint precision * fix: String -> &'static str * fix: allowlist not denylist for file type * fix: add missing and indication of what's needed * fix: copy pasteable errors * fix: use Loader:read_names * Update xtask/src/helpers.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: remove into and clone for str * Update book/src/themes.md Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: better lint output * fix: cleaner logic for lint reporting * style: use explicit imports * Pascal support (#3542) * fix: add difference check for statusline normal,insert,select * fix: fg for whitespace and early exit if and one is ok * chore: cleaning up, no idea how these got here or how this will look * chore: revert from older commit? * refactor: use static fn to equalize api between difference and existance * refactor: querycheck and clippy * refactor: clippy fixes * fix: query-check behaves as before * fix: error with x of y message, not total count * fix: consistent reporting and less mutable state * fix: selection difference ref #3942 ref #1833 Co-authored-by: Ivan Tham <pickfire@riseup.net> Co-authored-by: ath3 <45574139+ath3@users.noreply.github.com>
2022-09-19 21:38:20 +08:00
mod docgen;
mod helpers;
mod path;
use std::{env, error::Error};
type DynError = Box<dyn Error>;
2021-11-17 21:30:11 +08:00
pub mod tasks {
use crate::codegen::code_gen;
use crate::DynError;
use std::collections::HashSet;
2021-11-17 21:30:11 +08:00
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(())
2021-11-17 21:30:11 +08:00
}
pub fn querycheck(languages: impl Iterator<Item = String>) -> Result<(), DynError> {
2025-02-21 09:38:14 +08:00
use helix_core::syntax::LanguageData;
let languages_to_check: HashSet<_> = languages.collect();
let loader = helix_core::config::default_lang_loader();
2025-02-21 09:38:14 +08:00
for (_language, lang_data) in loader.languages() {
if !languages_to_check.is_empty()
&& !languages_to_check.contains(&lang_data.config().language_id)
{
continue;
}
2025-02-21 09:38:14 +08:00
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)?;
}
println!("Query check succeeded");
Ok(())
2022-08-26 06:24:09 +08:00
}
pub fn codegen() {
code_gen()
}
pub fn install_steel() {
std::process::Command::new("cargo")
.args([
"install",
"--git",
"https://github.com/mattwparas/steel.git",
"steel-interpreter",
"steel-language-server",
"cargo-steel-lib",
])
.spawn()
.unwrap()
.wait()
.unwrap();
2025-06-22 02:42:54 +08:00
std::process::Command::new("cargo")
.args([
"install",
"--git",
"https://github.com/mattwparas/steel.git",
"steel-forge",
])
.spawn()
.unwrap()
.wait()
.unwrap();
println!("----------------------------");
println!("=> Finished installing steel");
println!("----------------------------");
println!("Warming up `forge`...");
std::process::Command::new("forge")
.args(["pkg", "refresh"])
.spawn()
.unwrap()
.wait()
.unwrap();
println!("Done.");
println!("----------------------------");
code_gen();
std::process::Command::new("cargo")
.args(["install", "--path", "helix-term", "--locked", "--force"])
.spawn()
.unwrap()
.wait()
.unwrap();
}
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(())
}
}
}
2021-11-17 21:30:11 +08:00
pub fn print_help() {
println!(
"
Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
2021-11-17 21:30:11 +08:00
Tasks:
2025-07-18 12:37:02 +08:00
steel Install steel
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.
2021-11-17 21:30:11 +08:00
"
);
}
}
fn main() -> Result<(), DynError> {
let mut args = env::args().skip(1);
let task = args.next();
2021-11-17 21:30:11 +08:00
match task {
None => tasks::print_help(),
Some(t) => match t.as_str() {
"docgen" => tasks::docgen()?,
"code-gen" => tasks::codegen(),
"steel" => tasks::install_steel(),
"query-check" => tasks::querycheck(args)?,
"theme-check" => tasks::themecheck(args)?,
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
2021-11-17 21:30:11 +08:00
},
};
Ok(())
}