use crate::calls::graph::{CallEdge, CallKindCompat, CallTarget, CallableMeta, Confidence, Qn, TypeMeta};
use crate::core::ImportBinding;
use std::path::{Path, PathBuf};
pub struct FilePass {
pub file: PathBuf,
pub defined: Vec<Qn>,
pub callable_locations: Vec<CallableMeta>,
pub imports: Vec<ImportBinding>,
pub raw_edges: Vec<RawEdge>,
pub types: Vec<(Qn, TypeMeta)>,
}
#[derive(Debug, Clone)]
pub struct RawEdge {
pub source: Qn,
pub bare_name: String,
pub receiver: Option<String>,
pub kind: CallKindCompat,
pub line: u32,
}
pub fn qn_from(rel_file: &str, parents: &[String]) -> Qn {
let scope = parents.join("::");
if scope.is_empty() {
Qn::new(rel_file.to_string())
} else {
Qn::new(format!("{}::{}", rel_file, scope))
}
}
pub fn file_rel(root: &Path, file: &Path) -> String {
file.strip_prefix(root)
.unwrap_or(file)
.components()
.map(|c| c.as_os_str().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join("/")
}
pub(crate) fn raw_to_edge(
raw: RawEdge,
target: CallTarget,
confidence: Confidence,
file: PathBuf,
candidates: Vec<Qn>,
) -> CallEdge {
CallEdge {
source: raw.source,
target,
kind: raw.kind,
line: raw.line,
file,
confidence,
receiver: raw.receiver,
candidates,
}
}