mod cache;
mod extract;
mod facts;
mod imports;
mod resolve;
pub use veridikt_intent::PackSpec;
pub fn custom_strategy_names() -> &'static [&'static str] {
&["rust_use_paths"]
}
use std::path::PathBuf;
use veridikt_intent::{IntentNode, QName, Span};
pub struct SourceUnit {
pub path: PathBuf,
pub text: String,
pub module: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateSymbol {
pub qname: QName,
pub identifier: String,
pub file: PathBuf,
pub module: String,
}
pub struct DeriveConfig {
pub roots: Vec<String>,
pub cache_dir: Option<PathBuf>,
pub manifests: Vec<(PathBuf, String)>,
}
pub struct DerivePack {
pub spec: PackSpec,
pub grammar: tree_sitter::Language,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DerivedEdgeKind {
Calls,
Affects,
Reads,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DerivedConfidence {
Exact,
Resolved,
Heuristic,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DerivedEdge {
pub from: QName,
pub to: QName,
pub kind: DerivedEdgeKind,
pub confidence: DerivedConfidence,
pub loc: Span,
}
pub struct DeriveResult {
pub nodes: Vec<IntentNode>,
pub edges: Vec<DerivedEdge>,
pub unresolved_calls: usize,
pub ambiguous_names: usize,
pub scope: Vec<PathBuf>,
}
pub fn derive(
config: &DeriveConfig,
packs: &[DerivePack],
files: &[SourceUnit],
states: &[StateSymbol],
) -> DeriveResult {
let compiled: Vec<extract::CompiledPack> = packs
.iter()
.filter(|p| p.spec.derive_scm.is_some())
.map(extract::CompiledPack::new)
.collect();
let cache = config.cache_dir.as_deref().map(cache::Cache::new);
let mut extracted = Vec::new();
for file in files {
let Some(cp) = compiled.iter().find(|c| c.claims(&file.path)) else {
continue; };
let key = cache::key(&cp.id, file, &config.roots, states);
let facts = cache
.as_ref()
.and_then(|c| c.load(&key))
.unwrap_or_else(|| {
let facts = extract::extract(cp, file, states);
if let Some(c) = &cache {
c.store(&key, &facts);
}
facts
});
extracted.push((file, cp, facts));
}
let manifests: std::collections::HashMap<PathBuf, String> =
config.manifests.iter().cloned().collect();
resolve::resolve(&extracted, states, &config.roots, &manifests)
}