use gitcortex_core::schema::{EdgeKind, NodeKind, Visibility};
pub(super) fn kind_from_str(s: &str) -> NodeKind {
s.parse().unwrap_or(NodeKind::Function)
}
pub(super) fn edge_kind_from_str(s: &str) -> EdgeKind {
match s {
"calls" => EdgeKind::Calls,
"implements" => EdgeKind::Implements,
"inherits" => EdgeKind::Inherits,
"uses" => EdgeKind::Uses,
"imports" => EdgeKind::Imports,
"annotated" => EdgeKind::Annotated,
"throws" => EdgeKind::Throws,
"references" => EdgeKind::References,
_ => EdgeKind::Contains,
}
}
pub(super) fn vis_str(v: &Visibility) -> String {
match v {
Visibility::Pub => "pub".into(),
Visibility::PubCrate => "pub_crate".into(),
Visibility::Private => "private".into(),
}
}
pub(super) fn vis_from_str(s: &str) -> Visibility {
s.parse().unwrap_or(Visibility::Private)
}
pub(super) fn language_extensions(file: &str) -> Option<&'static [&'static str]> {
let ext = file.rsplit('.').next()?;
match ext {
"rs" => Some(&[".rs"]),
"py" => Some(&[".py"]),
"ts" | "tsx" | "js" | "jsx" | "mjs" | "cjs" => {
Some(&[".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"])
}
"go" => Some(&[".go"]),
"java" => Some(&[".java"]),
_ => None,
}
}
pub(super) fn lang_scope_clause(caller_file: &str, var: &str) -> String {
let Some(exts) = language_extensions(caller_file) else {
return String::new();
};
let parts: Vec<String> = exts
.iter()
.map(|e| format!("ends_with({var}.file, '{e}')"))
.collect();
format!(" AND ({})", parts.join(" OR "))
}