2024-02-14 13:00:21 +08:00
|
|
|
mod codegen;
|
2022-09-19 21:38:20 +08:00
|
|
|
mod docgen;
|
|
|
|
mod helpers;
|
|
|
|
mod path;
|
|
|
|
|
2021-11-22 02:55:08 +08:00
|
|
|
use std::{env, error::Error};
|
|
|
|
|
|
|
|
type DynError = Box<dyn Error>;
|
|
|
|
|
2021-11-17 21:30:11 +08:00
|
|
|
pub mod tasks {
|
2024-02-14 13:00:21 +08:00
|
|
|
use crate::codegen::code_gen;
|
2021-11-22 02:55:08 +08:00
|
|
|
use crate::DynError;
|
2021-11-17 21:30:11 +08:00
|
|
|
|
2024-07-06 04:11:02 +08:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2021-11-22 02:55:08 +08:00
|
|
|
pub fn docgen() -> Result<(), DynError> {
|
2025-02-24 23:46:35 +08:00
|
|
|
use crate::docgen::*;
|
2021-11-22 02:55:08 +08:00
|
|
|
write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?);
|
2024-12-06 01:13:00 +08:00
|
|
|
write(STATIC_COMMANDS_MD_OUTPUT, &static_commands()?);
|
2021-11-22 02:55:08 +08:00
|
|
|
write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?);
|
|
|
|
Ok(())
|
2021-11-17 21:30:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-19 21:38:20 +08:00
|
|
|
pub fn querycheck() -> Result<(), DynError> {
|
2025-02-24 23:46:35 +08:00
|
|
|
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(())
|
2022-08-26 06:24:09 +08:00
|
|
|
}
|
|
|
|
|
2024-02-14 13:00:21 +08:00
|
|
|
pub fn codegen() {
|
|
|
|
code_gen()
|
|
|
|
}
|
|
|
|
|
2024-04-06 06:17:41 +08:00
|
|
|
pub fn install_steel() {
|
2024-07-06 04:11:02 +08:00
|
|
|
fn workspace_dir() -> PathBuf {
|
|
|
|
let output = std::process::Command::new(env!("CARGO"))
|
|
|
|
.arg("locate-project")
|
|
|
|
.arg("--workspace")
|
|
|
|
.arg("--message-format=plain")
|
|
|
|
.output()
|
|
|
|
.unwrap()
|
|
|
|
.stdout;
|
|
|
|
let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim());
|
|
|
|
cargo_path.parent().unwrap().to_path_buf()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the steel submodule
|
|
|
|
std::process::Command::new("git")
|
|
|
|
.args(["submodule", "init"])
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
.args(["submodule", "foreach", "git", "pull", "origin", "master"])
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut workspace_dir = workspace_dir();
|
|
|
|
|
|
|
|
workspace_dir.push("steel");
|
|
|
|
|
|
|
|
std::process::Command::new("cargo")
|
|
|
|
.args(["xtask", "install"])
|
|
|
|
.current_dir(workspace_dir)
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("=> Finished installing steel");
|
|
|
|
|
2024-04-06 06:17:41 +08:00
|
|
|
code_gen();
|
2024-07-06 04:11:02 +08:00
|
|
|
|
|
|
|
let helix_scm_path = helix_term::commands::helix_module_file();
|
|
|
|
let steel_init_path = helix_term::commands::steel_init_file();
|
|
|
|
|
|
|
|
if !helix_scm_path.exists() {
|
|
|
|
std::fs::File::create(helix_scm_path).expect("Unable to create new helix.scm file!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !steel_init_path.exists() {
|
|
|
|
std::fs::File::create(steel_init_path).expect("Unable to create new init.scm file!");
|
|
|
|
}
|
|
|
|
|
2024-04-06 06:17:41 +08:00
|
|
|
std::process::Command::new("cargo")
|
|
|
|
.args(["install", "--path", "helix-term", "--locked", "--force"])
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2024-09-28 19:52:09 +08:00
|
|
|
pub fn themecheck() -> Result<(), DynError> {
|
2025-02-24 23:46:35 +08:00
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|
2024-09-28 19:52:09 +08:00
|
|
|
}
|
|
|
|
|
2021-11-17 21:30:11 +08:00
|
|
|
pub fn print_help() {
|
|
|
|
println!(
|
|
|
|
"
|
2021-11-22 02:55:08 +08:00
|
|
|
Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
|
2021-11-17 21:30:11 +08:00
|
|
|
|
|
|
|
Tasks:
|
2021-11-22 02:55:08 +08:00
|
|
|
docgen: Generate files to be included in the mdbook output.
|
2022-08-26 06:24:09 +08:00
|
|
|
query-check: Check that tree-sitter queries are valid.
|
2024-08-13 08:02:14 +08:00
|
|
|
code-gen: Generate files associated with steel
|
|
|
|
steel: Install steel
|
2025-02-24 23:46:35 +08:00
|
|
|
theme-check: Check that theme files in runtime/themes are valid.
|
2021-11-17 21:30:11 +08:00
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-22 02:55:08 +08:00
|
|
|
fn main() -> Result<(), DynError> {
|
2021-11-17 21:30:11 +08:00
|
|
|
let task = env::args().nth(1);
|
|
|
|
match task {
|
|
|
|
None => tasks::print_help(),
|
|
|
|
Some(t) => match t.as_str() {
|
2021-11-22 02:55:08 +08:00
|
|
|
"docgen" => tasks::docgen()?,
|
2022-09-19 21:38:20 +08:00
|
|
|
"query-check" => tasks::querycheck()?,
|
2024-02-14 13:00:21 +08:00
|
|
|
"code-gen" => tasks::codegen(),
|
2024-04-06 06:17:41 +08:00
|
|
|
"steel" => tasks::install_steel(),
|
2024-09-28 19:52:09 +08:00
|
|
|
"theme-check" => tasks::themecheck()?,
|
2021-11-22 02:55:08 +08:00
|
|
|
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
|
2021-11-17 21:30:11 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
Ok(())
|
|
|
|
}
|