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 pub is_callback: bool,
63 }
64
65 impl From<fallow_extract::inventory::InventoryEntry> for InventoryEntry {
66 fn from(entry: fallow_extract::inventory::InventoryEntry) -> Self {
67 Self {
68 name: entry.name,
69 line: entry.line,
70 start_column: entry.start_column,
71 end_line: entry.end_line,
72 end_column: entry.end_column,
73 source_hash: entry.source_hash,
74 is_callback: entry.is_callback,
75 }
76 }
77 }
78
79 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
81 pub struct InventoryComplexity {
82 pub cyclomatic: u16,
84 pub cognitive: u16,
86 }
87
88 impl From<fallow_extract::inventory::InventoryComplexity> for InventoryComplexity {
89 fn from(complexity: fallow_extract::inventory::InventoryComplexity) -> Self {
90 Self {
91 cyclomatic: complexity.cyclomatic,
92 cognitive: complexity.cognitive,
93 }
94 }
95 }
96
97 #[must_use]
99 pub fn walk_source(path: &Path, source: &str) -> Vec<InventoryEntry> {
100 fallow_extract::inventory::walk_source(path, source)
101 .into_iter()
102 .map(InventoryEntry::from)
103 .collect()
104 }
105
106 #[must_use]
108 pub fn walk_source_with_complexity(
109 path: &Path,
110 source: &str,
111 ) -> (Vec<InventoryEntry>, FxHashMap<String, InventoryComplexity>) {
112 let (entries, complexity) =
113 fallow_extract::inventory::walk_source_with_complexity(path, source);
114 let entries = entries.into_iter().map(InventoryEntry::from).collect();
115 let complexity = complexity
116 .into_iter()
117 .map(|(hash, metrics)| (hash, InventoryComplexity::from(metrics)))
118 .collect();
119 (entries, complexity)
120 }
121}
122
123#[must_use]
134pub(crate) fn parse_all_files(
135 files: &[DiscoveredFile],
136 cache: Option<&CacheStore>,
137 need_complexity: bool,
138 cancellation: Option<&AtomicBool>,
139 flag_patterns: &fallow_types::extract::FlagPatterns,
140) -> ParseResult {
141 fallow_extract::parse_all_files_cancellable(
142 files,
143 cache,
144 need_complexity,
145 cancellation,
146 flag_patterns,
147 )
148}