use crate::analysis::parse::ParsedFile;
use std::collections::HashSet;
use tree_sitter::Tree;
mod common;
mod go;
mod jvm;
pub mod lines;
mod python;
mod rust;
mod ts;
pub fn extract_imports(content: &str, language: Option<&str>) -> Vec<String> {
extract_imports_from(&ParsedFile::new(content, language), language)
}
pub(crate) fn extract_imports_from(parsed: &ParsedFile, language: Option<&str>) -> Vec<String> {
let content = parsed.content();
let set: HashSet<String> = match language {
Some("Rust") => from_tree(parsed, |tree| rust::extract(tree, content)),
Some("TypeScript")
| Some("TypeScript React")
| Some("JavaScript")
| Some("JavaScript React") => from_tree(parsed, |tree| ts::extract(tree, content)),
Some("Python") => from_tree(parsed, |tree| python::extract(tree, content)),
Some("Go") => go::extract(content),
Some("Java") => jvm::extract_java(content),
Some("Kotlin") => jvm::extract_kotlin(content),
_ => return Vec::new(),
};
set.into_iter().collect()
}
fn from_tree(parsed: &ParsedFile, visit: impl FnOnce(&Tree) -> HashSet<String>) -> HashSet<String> {
parsed.tree().map(visit).unwrap_or_default()
}