use crate::project::file_loader;
use crate::semantic::Workspace;
use crate::syntax::SyntaxFile;
use rayon::prelude::*;
use std::path::PathBuf;
pub fn load(stdlib_path: &PathBuf, workspace: &mut Workspace<SyntaxFile>) -> Result<(), String> {
if !stdlib_path.exists() || !stdlib_path.is_dir() {
return Ok(());
}
let file_paths = file_loader::collect_file_paths(stdlib_path)?;
let results: Vec<_> = file_paths
.par_iter()
.map(|path| (path, parse_file(path)))
.collect();
for (_path, result) in results {
if let Ok((path, file)) = result {
workspace.add_file(path, file);
}
}
workspace.mark_stdlib_loaded();
Ok(())
}
fn parse_file(path: &PathBuf) -> Result<(PathBuf, SyntaxFile), String> {
file_loader::load_and_parse(path).map(|file| (path.clone(), file))
}