use crate::ide::AnalysisHost;
use crate::project::file_loader;
use crate::syntax::SyntaxFile;
use rayon::prelude::*;
use std::path::PathBuf;
pub fn load_into_host(stdlib_path: &PathBuf, host: &mut AnalysisHost) -> Result<(), String> {
if !stdlib_path.exists() {
return Err(format!(
"stdlib path does not exist: {}",
stdlib_path.display()
));
}
if !stdlib_path.is_dir() {
return Err(format!(
"stdlib path is not a directory: {}",
stdlib_path.display()
));
}
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 {
host.set_file(path, file);
}
}
Ok(())
}
fn parse_file(path: &PathBuf) -> Result<(PathBuf, SyntaxFile), String> {
file_loader::load_and_parse(path).map(|file| (path.clone(), file))
}