use crate::context::{ProjectMetadata, StagedFile};
pub trait FileAnalyzer: Send + Sync {
fn analyze(&self, file: &str, staged_file: &StagedFile) -> Vec<String>;
fn get_file_type(&self) -> &'static str;
fn extract_metadata(&self, file: &str, content: &str) -> ProjectMetadata;
}
mod c;
mod cpp;
mod gradle;
mod java;
mod javascript;
mod json;
mod kotlin;
mod markdown;
mod python;
mod rust;
mod yaml;
pub fn get_analyzer(file: &str) -> Box<dyn FileAnalyzer + Send + Sync> {
if file.ends_with(".c") || file == "Makefile" {
Box::new(c::CAnalyzer)
} else if file.ends_with(".cpp") || file.ends_with(".cc") || file.ends_with(".cxx") || file == "CMakeLists.txt" {
Box::new(cpp::CppAnalyzer)
} else if file.ends_with(".rs") {
Box::new(rust::RustAnalyzer)
} else if file.ends_with(".js") || file.ends_with(".ts") {
Box::new(javascript::JavaScriptAnalyzer)
} else if file.ends_with(".py") {
Box::new(python::PythonAnalyzer)
} else if file.ends_with(".yaml") || file.ends_with(".yml") {
Box::new(yaml::YamlAnalyzer)
} else if file.ends_with(".json") {
Box::new(json::JsonAnalyzer)
} else if file.ends_with(".md") {
Box::new(markdown::MarkdownAnalyzer)
} else if file.ends_with(".java") {
Box::new(java::JavaAnalyzer)
} else if file.ends_with(".kt") {
Box::new(kotlin::KotlinAnalyzer)
} else if file.ends_with(".gradle") || file.ends_with(".gradle.kts") {
Box::new(gradle::GradleAnalyzer)
} else {
Box::new(DefaultAnalyzer)
}
}
struct DefaultAnalyzer;
impl FileAnalyzer for DefaultAnalyzer {
fn analyze(&self, _file: &str, _staged_file: &StagedFile) -> Vec<String> {
vec![]
}
fn get_file_type(&self) -> &'static str {
"Unknown file type"
}
fn extract_metadata(&self, _file: &str, _content: &str) -> ProjectMetadata {
let mut metadata = ProjectMetadata::default();
metadata.language = Some("Unknown".to_string());
metadata
}
}