use fallow_types::discover::DiscoveredFile;
#[cfg(test)]
pub use fallow_types::extract::{ExportName, MemberKind, VisibilityTag};
pub use fallow_types::extract::{ModuleInfo, ParseResult, SourceReadFailure};
type CacheStore = fallow_extract::cache::CacheStore;
pub mod similar_code {
use std::path::Path;
pub use fallow_types::similar_code::{
ExtractedSimilarCodeFunction, SIMILAR_CODE_EXTRACTION_SEMANTICS_VERSION,
SimilarCodeExtraction, SimilarCodeExtractionLimits, SimilarCodeExtractionSkip,
SimilarCodeExtractionSkipReason, SimilarCodeFunctionKind, SimilarCodeFunctionLocation,
SimilarCodeSideEffectHint, SimilarCodeSourceDigest,
};
#[must_use]
pub fn extract(
path: &Path,
source: &str,
limits: SimilarCodeExtractionLimits,
) -> SimilarCodeExtraction {
fallow_extract::extract_similar_code_functions(path, source, limits)
}
}
pub mod inventory {
use std::path::Path;
use rustc_hash::FxHashMap;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InventoryEntry {
pub name: String,
pub line: u32,
pub start_column: u32,
pub end_line: u32,
pub end_column: u32,
pub source_hash: String,
}
impl From<fallow_extract::inventory::InventoryEntry> for InventoryEntry {
fn from(entry: fallow_extract::inventory::InventoryEntry) -> Self {
Self {
name: entry.name,
line: entry.line,
start_column: entry.start_column,
end_line: entry.end_line,
end_column: entry.end_column,
source_hash: entry.source_hash,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InventoryComplexity {
pub cyclomatic: u16,
pub cognitive: u16,
}
impl From<fallow_extract::inventory::InventoryComplexity> for InventoryComplexity {
fn from(complexity: fallow_extract::inventory::InventoryComplexity) -> Self {
Self {
cyclomatic: complexity.cyclomatic,
cognitive: complexity.cognitive,
}
}
}
#[must_use]
pub fn walk_source(path: &Path, source: &str) -> Vec<InventoryEntry> {
fallow_extract::inventory::walk_source(path, source)
.into_iter()
.map(InventoryEntry::from)
.collect()
}
#[must_use]
pub fn walk_source_with_complexity(
path: &Path,
source: &str,
) -> (Vec<InventoryEntry>, FxHashMap<String, InventoryComplexity>) {
let (entries, complexity) =
fallow_extract::inventory::walk_source_with_complexity(path, source);
let entries = entries.into_iter().map(InventoryEntry::from).collect();
let complexity = complexity
.into_iter()
.map(|(hash, metrics)| (hash, InventoryComplexity::from(metrics)))
.collect();
(entries, complexity)
}
}
#[must_use]
pub(crate) fn parse_all_files(
files: &[DiscoveredFile],
cache: Option<&CacheStore>,
need_complexity: bool,
) -> ParseResult {
fallow_extract::parse_all_files(files, cache, need_complexity)
}