Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

produce error when grammar build fails #6795

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 22 additions & 37 deletions helix-loader/src/grammar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, bail, Context, Result};
use serde::{Deserialize, Serialize};
use std::fs;
use std::time::SystemTime;
Expand Down Expand Up @@ -98,15 +98,12 @@ pub fn fetch_grammars() -> Result<()> {
let mut git_up_to_date = 0;
let mut non_git = Vec::new();

for res in results {
for (grammar_id, res) in results {
match res {
Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1,
Ok(FetchStatus::GitUpdated {
grammar_id,
revision,
}) => git_updated.push((grammar_id, revision)),
Ok(FetchStatus::NonGit { grammar_id }) => non_git.push(grammar_id),
Err(e) => errors.push(e),
Ok(FetchStatus::GitUpdated { revision }) => git_updated.push((grammar_id, revision)),
Ok(FetchStatus::NonGit) => non_git.push(grammar_id),
Err(e) => errors.push((grammar_id, e)),
}
}

Expand Down Expand Up @@ -138,10 +135,10 @@ pub fn fetch_grammars() -> Result<()> {

if !errors.is_empty() {
let len = errors.len();
println!("{} grammars failed to fetch", len);
for (i, error) in errors.into_iter().enumerate() {
println!("\tFailure {}/{}: {}", i + 1, len, error);
for (i, (grammar, error)) in errors.into_iter().enumerate() {
println!("Failure {}/{len}: {grammar} {error}", i + 1);
}
bail!("{len} grammars failed to fetch");
}

Ok(())
Expand All @@ -158,11 +155,11 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
let mut already_built = 0;
let mut built = Vec::new();

for res in results {
for (grammar_id, res) in results {
match res {
Ok(BuildStatus::AlreadyBuilt) => already_built += 1,
Ok(BuildStatus::Built { grammar_id }) => built.push(grammar_id),
Err(e) => errors.push(e),
Ok(BuildStatus::Built) => built.push(grammar_id),
Err(e) => errors.push((grammar_id, e)),
}
}

Expand All @@ -179,10 +176,10 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {

if !errors.is_empty() {
let len = errors.len();
println!("{} grammars failed to build", len);
for (i, error) in errors.into_iter().enumerate() {
println!("\tFailure {}/{}: {}", i, len, error);
for (i, (grammar_id, error)) in errors.into_iter().enumerate() {
println!("Failure {}/{len}: {grammar_id} {error}", i + 1);
}
bail!("{len} grammars failed to build");
}

Ok(())
Expand Down Expand Up @@ -214,7 +211,7 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
Ok(grammars)
}

fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<Result<Res>>
fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<(String, Result<Res>)>
where
F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
Res: Send + 'static,
Expand All @@ -229,7 +226,7 @@ where
pool.execute(move || {
// Ignore any SendErrors, if any job in another thread has encountered an
// error the Receiver will be closed causing this send to fail.
let _ = tx.send(job(grammar));
let _ = tx.send((grammar.grammar_id.clone(), job(grammar)));
});
}

Expand All @@ -240,13 +237,8 @@ where

enum FetchStatus {
GitUpToDate,
GitUpdated {
grammar_id: String,
revision: String,
},
NonGit {
grammar_id: String,
},
GitUpdated { revision: String },
NonGit,
}

fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
Expand Down Expand Up @@ -287,17 +279,12 @@ fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
)?;
git(&grammar_dir, ["checkout", &revision])?;

Ok(FetchStatus::GitUpdated {
grammar_id: grammar.grammar_id,
revision,
})
Ok(FetchStatus::GitUpdated { revision })
} else {
Ok(FetchStatus::GitUpToDate)
}
} else {
Ok(FetchStatus::NonGit {
grammar_id: grammar.grammar_id,
})
Ok(FetchStatus::NonGit)
}
}

Expand Down Expand Up @@ -347,7 +334,7 @@ where

enum BuildStatus {
AlreadyBuilt,
Built { grammar_id: String },
Built,
}

fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {
Expand Down Expand Up @@ -533,9 +520,7 @@ fn build_tree_sitter_library(
));
}

Ok(BuildStatus::Built {
grammar_id: grammar.grammar_id,
})
Ok(BuildStatus::Built)
}

fn needs_recompile(
Expand Down