pub mod project;
pub mod stats;
mod parallel;
mod reader;
mod source;
use rayon::prelude::*;
pub use crate::analyzer::project::Project;
pub use crate::analyzer::stats::ProjectStats;
use crate::config::LanguageIndex;
use crate::logger::{logger, Level, Log, Verbosity};
const CHUNK_FILES: usize = 256;
pub fn analyze_project(project: &Project, index: &LanguageIndex, verbose: &u8) -> ProjectStats {
let file_paths = project.file_paths();
let source = project.to_analysis_source();
logger(
Log::new(
Level::Info,
format!("Found {} files", file_paths.len()),
Some(Verbosity::Verbose),
),
Some(Verbosity::from_u8(verbose)),
);
file_paths
.par_chunks(CHUNK_FILES)
.fold(ProjectStats::new, |mut stats, chunk| {
for path in chunk {
if let Some((lang_id, lines, bytes)) = source.analyze_file(path, index, verbose) {
stats.add(lang_id, lines, bytes);
}
}
stats
})
.reduce(ProjectStats::new, |mut a, b| {
a.merge(&b);
a
})
}