use crate::channel::Sender;
use crate::project::AbsolutePath;
use crate::project::ProjectFields;
use crate::scan;
use crate::scan::BackgroundMsg;
use crate::scan::FetchContext;
pub(crate) fn enrich(entry: &dyn ProjectFields, tx: &Sender<BackgroundMsg>, ctx: &FetchContext) {
let path: AbsolutePath = entry.path().clone();
scan::emit_git_info(tx, &path);
emit_disk(&path, tx);
spawn_language_scan(path.clone(), tx.clone());
spawn_test_count_scan(path.clone(), tx.clone());
if let Some(name) = entry.crates_io_name() {
emit_crates_io(name, &path, tx, ctx);
}
}
fn emit_disk(path: &AbsolutePath, tx: &Sender<BackgroundMsg>) {
let bytes = scan::dir_size(path.as_path());
let _ = tx.send(BackgroundMsg::DiskUsage {
path: path.clone(),
bytes,
});
}
pub(crate) fn spawn_language_scan(path: AbsolutePath, tx: Sender<BackgroundMsg>) {
rayon::spawn(move || {
let stats = scan::collect_language_stats_single(path.as_path());
if !stats.entries.is_empty() {
let _ = tx.send(BackgroundMsg::LanguageStatsBatch {
entries: vec![(path, stats)],
});
}
});
}
pub(crate) fn spawn_test_count_scan(path: AbsolutePath, tx: Sender<BackgroundMsg>) {
rayon::spawn(move || {
let counts = scan::collect_test_counts_single(path.as_path());
let _ = tx.send(BackgroundMsg::TestCountsBatch {
entries: vec![(path, counts)],
});
});
}
fn emit_crates_io(name: &str, path: &AbsolutePath, tx: &Sender<BackgroundMsg>, ctx: &FetchContext) {
let _ = tx.send(BackgroundMsg::CratesIoFetchQueued {
name: name.to_string(),
});
let (info, signal) = ctx.client.fetch_crates_io_info(name);
scan::emit_service_signal(tx, signal);
if let Some(info) = info {
let _ = tx.send(BackgroundMsg::CratesIoVersion {
path: path.clone(),
version: info.version,
prerelease: info.prerelease,
downloads: info.downloads,
});
}
let _ = tx.send(BackgroundMsg::CratesIoFetchComplete {
name: name.to_string(),
});
}