mod go;
mod jvm;
mod python;
mod rust;
mod ts;
use std::collections::HashSet;
use std::path::{Component, Path, PathBuf};
pub fn resolve_import(
raw_import: &str,
from_file: &Path,
root: &Path,
known_files: &HashSet<PathBuf>,
) -> Option<PathBuf> {
let ext = from_file.extension().and_then(|e| e.to_str()).unwrap_or("");
match ext {
"rs" => rust::resolve_rust(raw_import, from_file, root, known_files),
"ts" | "tsx" | "js" | "jsx" | "mjs" | "cjs" => {
ts::resolve_ts(raw_import, from_file, root, known_files)
}
"py" => python::resolve_python(raw_import, from_file, root, known_files),
"go" => go::resolve_go(raw_import, root, known_files),
"java" => jvm::resolve_jvm(raw_import, root, known_files, &["java"]),
"kt" | "kts" => jvm::resolve_jvm(raw_import, root, known_files, &["kt", "java"]),
_ => None,
}
}
fn probe(candidates: &[PathBuf], known_files: &HashSet<PathBuf>) -> Option<PathBuf> {
for candidate in candidates {
let normalized = normalize_path(candidate);
if known_files.contains(&normalized) {
return Some(normalized);
}
}
None
}
pub(crate) fn normalize_path(path: &Path) -> PathBuf {
let mut out = PathBuf::new();
for component in path.components() {
match component {
Component::ParentDir => {
out.pop();
}
Component::CurDir => {}
other => out.push(other),
}
}
out
}