use context_creator::cli::Config;
use context_creator::core::walker::{walk_directory, WalkOptions, perform_semantic_analysis};
use context_creator::core::cache::FileCache;
use std::fs;
use std::path::PathBuf;
use std::sync::Arc;
use tempfile::TempDir;
fn main() {
let temp_dir = TempDir::new().unwrap();
let root = temp_dir.path();
fs::write(
root.join("main.rs"),
r#"
mod lib;
mod utils;
fn main() {
lib::hello();
utils::helper();
}
"#,
)
.unwrap();
fs::write(
root.join("lib.rs"),
r#"
pub fn hello() {
println!("Hello from lib!");
}
"#,
)
.unwrap();
fs::write(
root.join("utils.rs"),
r#"
pub fn helper() {
println!("Helper function");
}
"#,
)
.unwrap();
let config = Config {
paths: Some(vec![root.to_path_buf()]),
trace_imports: true,
include_callers: false,
include_types: false,
semantic_depth: 3,
..Config::default()
};
let walk_options = WalkOptions::from_config(&config).unwrap();
let cache = Arc::new(FileCache::new());
let mut files = walk_directory(root, walk_options).unwrap();
println!("Found {} files", files.len());
for file in &files {
println!("File: {:?}", file.relative_path);
}
perform_semantic_analysis(&mut files, &config, &cache).unwrap();
for file in &files {
println!("\nFile: {:?}", file.relative_path);
println!(" Imports: {:?}", file.imports);
println!(" Imported by: {:?}", file.imported_by);
println!(" Function calls: {:?}", file.function_calls);
println!(" Type references: {:?}", file.type_references);
}
}