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
12#[must_use]
17pub fn suppressions_from_text(
18 path: &std::path::Path,
19 source: &str,
20) -> Vec<fallow_types::suppress::Suppression> {
21 fallow_extract::parse_suppressions_for_file(path, source).suppressions
22}
23
24pub mod similar_code {
26 use std::path::Path;
27
28 pub use fallow_types::similar_code::{
29 ExtractedSimilarCodeFunction, SIMILAR_CODE_EXTRACTION_SEMANTICS_VERSION,
30 SimilarCodeExtraction, SimilarCodeExtractionLimits, SimilarCodeExtractionSkip,
31 SimilarCodeExtractionSkipReason, SimilarCodeFunctionKind, SimilarCodeFunctionLocation,
32 SimilarCodeSideEffectHint, SimilarCodeSourceDigest,
33 };
34
35 #[must_use]
37 pub fn extract(
38 path: &Path,
39 source: &str,
40 limits: SimilarCodeExtractionLimits,
41 ) -> SimilarCodeExtraction {
42 fallow_extract::extract_similar_code_functions(path, source, limits)
43 }
44}
45
46#[must_use]
49pub fn is_generated_file(path: &std::path::Path, source: &str) -> bool {
50 fallow_extract::is_generated_file(path, source)
51}
52
53pub mod inventory {
55 use std::path::Path;
56
57 use rustc_hash::FxHashMap;
58
59 #[derive(Debug, Clone, PartialEq, Eq)]
65 pub struct InventoryEntry {
66 pub name: String,
68 pub line: u32,
70 pub start_column: u32,
72 pub end_line: u32,
74 pub end_column: u32,
76 pub source_hash: Option<String>,
79 pub is_callback: bool,
83 }
84
85 impl From<fallow_extract::inventory::InventoryEntry> for InventoryEntry {
86 fn from(entry: fallow_extract::inventory::InventoryEntry) -> Self {
87 Self {
88 name: entry.name,
89 line: entry.line,
90 start_column: entry.start_column,
91 end_line: entry.end_line,
92 end_column: entry.end_column,
93 source_hash: entry.source_hash,
94 is_callback: entry.is_callback,
95 }
96 }
97 }
98
99 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
101 pub struct InventoryComplexity {
102 pub cyclomatic: u16,
104 pub cognitive: u16,
106 }
107
108 impl From<fallow_extract::inventory::InventoryComplexity> for InventoryComplexity {
109 fn from(complexity: fallow_extract::inventory::InventoryComplexity) -> Self {
110 Self {
111 cyclomatic: complexity.cyclomatic,
112 cognitive: complexity.cognitive,
113 }
114 }
115 }
116
117 #[must_use]
119 pub fn walk_source(path: &Path, source: &str) -> Vec<InventoryEntry> {
120 fallow_extract::inventory::walk_source(path, source)
121 .into_iter()
122 .map(InventoryEntry::from)
123 .collect()
124 }
125
126 #[must_use]
128 pub fn walk_source_with_complexity(
129 path: &Path,
130 source: &str,
131 ) -> (Vec<InventoryEntry>, FxHashMap<String, InventoryComplexity>) {
132 let (entries, complexity) =
133 fallow_extract::inventory::walk_source_with_complexity(path, source);
134 let entries = entries.into_iter().map(InventoryEntry::from).collect();
135 let complexity = complexity
136 .into_iter()
137 .map(|(hash, metrics)| (hash, InventoryComplexity::from(metrics)))
138 .collect();
139 (entries, complexity)
140 }
141}
142
143#[must_use]
154pub(crate) fn parse_all_files(
155 files: &[DiscoveredFile],
156 cache: Option<&CacheStore>,
157 needs: fallow_extract::ParseNeeds,
158 cancellation: Option<&AtomicBool>,
159 flag_patterns: &fallow_types::extract::FlagPatterns,
160 mode: fallow_types::shared_state::ExtractionMode,
161) -> ParseResult {
162 fallow_extract::parse_all_files_with_mode(
163 files,
164 cache,
165 needs,
166 cancellation,
167 flag_patterns,
168 mode,
169 )
170}