fix(cli): spawn linting in another thread so diagnostics can be printed immediately

This commit is contained in:
Boshen 2023-09-06 10:21:32 +08:00
parent db95503f09
commit b89e931b33
No known key found for this signature in database
GPG key ID: 234DA6A7079C6801
2 changed files with 9 additions and 1 deletions

View file

@ -47,7 +47,14 @@ impl Runner for LintRunner {
let paths = Walk::new(&paths, &ignore_options).paths();
let number_of_files = paths.len();
lint_service.run(paths, &diagnostic_service.sender().clone());
// Spawn linting in another thread so diagnostics can be printed immediately from diagnostic_service.run.
rayon::spawn({
let tx_error = diagnostic_service.sender().clone();
let lint_service = lint_service.clone();
move || {
lint_service.run(paths, &tx_error);
}
});
diagnostic_service.run();
lint_service.linter().print_execution_times_if_enable();

View file

@ -9,6 +9,7 @@ use oxc_span::SourceType;
use crate::{Fixer, LintContext, LintOptions, Linter, Message};
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
#[derive(Clone)]
pub struct LintService {
linter: Arc<Linter>,
}