Skip to content

Commit

Permalink
Check for 'git' before fetching/building grammars (helix-editor#7320)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis authored and Triton171 committed Jun 18, 2023
1 parent 6bd3aca commit 9e294dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions helix-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ etcetera = "0.8"
tree-sitter = "0.20"
once_cell = "1.18"
log = "0.4"
which = "4.4"

# TODO: these two should be on !wasm32 only

Expand Down
11 changes: 11 additions & 0 deletions helix-loader/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { .. }));
Expand Down Expand Up @@ -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| {
Expand Down

0 comments on commit 9e294dc

Please sign in to comment.