1use std::sync::atomic::AtomicBool;
4
5use fallow_types::discover::DiscoveredFile;
6#[cfg(test)]
7pub use fallow_types::extract::{ExportName, MemberKind, VisibilityTag};
8pub use fallow_types::extract::{ModuleInfo, ParseResult, SourceReadFailure};
9
10type CacheStore = fallow_extract::cache::CacheStore;
11
12pub mod similar_code {
14 use std::path::Path;
15
16 pub use fallow_types::similar_code::{
17 ExtractedSimilarCodeFunction, SIMILAR_CODE_EXTRACTION_SEMANTICS_VERSION,
18 SimilarCodeExtraction, SimilarCodeExtractionLimits, SimilarCodeExtractionSkip,
19 SimilarCodeExtractionSkipReason, SimilarCodeFunctionKind, SimilarCodeFunctionLocation,
20 SimilarCodeSideEffectHint, SimilarCodeSourceDigest,
21 };
22
23 #[must_use]
25 pub fn extract(
26 path: &Path,
27 source: &str,
28 limits: SimilarCodeExtractionLimits,
29 ) -> SimilarCodeExtraction {
30 fallow_extract::extract_similar_code_functions(path, source, limits)
31 }
32}
33
34pub mod inventory {
36 use std::path::Path;
37
38 use rustc_hash::FxHashMap;
39
40 #[derive(Debug, Clone, PartialEq, Eq)]
46 pub struct InventoryEntry {
47 pub name: String,
49 pub line: u32,
51 pub start_column: u32,
53 pub end_line: u32,
55 pub end_column: u32,
57 pub source_hash: String,
59 }
60
61 impl From<fallow_extract::inventory::InventoryEntry> for InventoryEntry {
62 fn from(entry: fallow_extract::inventory::InventoryEntry) -> Self {
63 Self {
64 name: entry.name,
65 line: entry.line,
66 start_column: entry.start_column,
67 end_line: entry.end_line,
68 end_column: entry.end_column,
69 source_hash: entry.source_hash,
70 }
71 }
72 }
73
74 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
76 pub struct InventoryComplexity {
77 pub cyclomatic: u16,
79 pub cognitive: u16,
81 }
82
83 impl From<fallow_extract::inventory::InventoryComplexity> for InventoryComplexity {
84 fn from(complexity: fallow_extract::inventory::InventoryComplexity) -> Self {
85 Self {
86 cyclomatic: complexity.cyclomatic,
87 cognitive: complexity.cognitive,
88 }
89 }
90 }
91
92 #[must_use]
94 pub fn walk_source(path: &Path, source: &str) -> Vec<InventoryEntry> {
95 fallow_extract::inventory::walk_source(path, source)
96 .into_iter()
97 .map(InventoryEntry::from)
98 .collect()
99 }
100
101 #[must_use]
103 pub fn walk_source_with_complexity(
104 path: &Path,
105 source: &str,
106 ) -> (Vec<InventoryEntry>, FxHashMap<String, InventoryComplexity>) {
107 let (entries, complexity) =
108 fallow_extract::inventory::walk_source_with_complexity(path, source);
109 let entries = entries.into_iter().map(InventoryEntry::from).collect();
110 let complexity = complexity
111 .into_iter()
112 .map(|(hash, metrics)| (hash, InventoryComplexity::from(metrics)))
113 .collect();
114 (entries, complexity)
115 }
116}
117
118#[must_use]
128pub(crate) fn parse_all_files(
129 files: &[DiscoveredFile],
130 cache: Option<&CacheStore>,
131 need_complexity: bool,
132 cancellation: Option<&AtomicBool>,
133) -> ParseResult {
134 fallow_extract::parse_all_files_cancellable(files, cache, need_complexity, cancellation)
135}