aboutsummaryrefslogtreecommitdiff
path: root/helix-loader/src/grammar.rs
diff options
context:
space:
mode:
authorMichael Davis2023-06-12 15:32:36 +0000
committerGitHub2023-06-12 15:32:36 +0000
commit25ad534d6404e2aa39536df818371dcbbc928b52 (patch)
tree9ae565d7f4fbfc1f842d156a4c128ed33eedc457 /helix-loader/src/grammar.rs
parent18e07addfd464844fc18833cfb1d1cd38c683c11 (diff)
Check for 'git' before fetching/building grammars (#7320)
Previously the error message for this potential failure-case was confusing: "no such file or directory". `hx -g fetch`, `hx -g build` and the helix-term builder should bail early if the git binary is not available.
Diffstat (limited to 'helix-loader/src/grammar.rs')
-rw-r--r--helix-loader/src/grammar.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/helix-loader/src/grammar.rs b/helix-loader/src/grammar.rs
index 16955187..66111aeb 100644
--- a/helix-loader/src/grammar.rs
+++ b/helix-loader/src/grammar.rs
@@ -85,7 +85,16 @@ pub fn get_language(name: &str) -> Result<Language> {
Ok(language)
}
+fn ensure_git_is_available() -> Result<()> {
+ match which::which("git") {
+ Ok(_cmd) => Ok(()),
+ Err(err) => Err(anyhow::anyhow!("'git' could not be found ({err})")),
+ }
+}
+
pub fn fetch_grammars() -> Result<()> {
+ ensure_git_is_available()?;
+
// We do not need to fetch local grammars.
let mut grammars = get_grammar_configs()?;
grammars.retain(|grammar| !matches!(grammar.source, GrammarSource::Local { .. }));
@@ -145,6 +154,8 @@ pub fn fetch_grammars() -> Result<()> {
}
pub fn build_grammars(target: Option<String>) -> Result<()> {
+ ensure_git_is_available()?;
+
let grammars = get_grammar_configs()?;
println!("Building {} grammars", grammars.len());
let results = run_parallel(grammars, move |grammar| {