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]
15pub fn suppressions_from_text(source: &str) -> Vec<fallow_types::suppress::Suppression> {
16 fallow_extract::suppress::parse_suppressions_from_source(source).suppressions
17}
18
19pub mod similar_code {
21 use std::path::Path;
22
23 pub use fallow_types::similar_code::{
24 ExtractedSimilarCodeFunction, SIMILAR_CODE_EXTRACTION_SEMANTICS_VERSION,
25 SimilarCodeExtraction, SimilarCodeExtractionLimits, SimilarCodeExtractionSkip,
26 SimilarCodeExtractionSkipReason, SimilarCodeFunctionKind, SimilarCodeFunctionLocation,
27 SimilarCodeSideEffectHint, SimilarCodeSourceDigest,
28 };
29
30 #[must_use]
32 pub fn extract(
33 path: &Path,
34 source: &str,
35 limits: SimilarCodeExtractionLimits,
36 ) -> SimilarCodeExtraction {
37 fallow_extract::extract_similar_code_functions(path, source, limits)
38 }
39}
40
41pub mod inventory {
43 use std::path::Path;
44
45 use rustc_hash::FxHashMap;
46
47 #[derive(Debug, Clone, PartialEq, Eq)]
53 pub struct InventoryEntry {
54 pub name: String,
56 pub line: u32,
58 pub start_column: u32,
60 pub end_line: u32,
62 pub end_column: u32,
64 pub source_hash: Option<String>,
67 pub is_callback: bool,
71 }
72
73 impl From<fallow_extract::inventory::InventoryEntry> for InventoryEntry {
74 fn from(entry: fallow_extract::inventory::InventoryEntry) -> Self {
75 Self {
76 name: entry.name,
77 line: entry.line,
78 start_column: entry.start_column,
79 end_line: entry.end_line,
80 end_column: entry.end_column,
81 source_hash: entry.source_hash,
82 is_callback: entry.is_callback,
83 }
84 }
85 }
86
87 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
89 pub struct InventoryComplexity {
90 pub cyclomatic: u16,
92 pub cognitive: u16,
94 }
95
96 impl From<fallow_extract::inventory::InventoryComplexity> for InventoryComplexity {
97 fn from(complexity: fallow_extract::inventory::InventoryComplexity) -> Self {
98 Self {
99 cyclomatic: complexity.cyclomatic,
100 cognitive: complexity.cognitive,
101 }
102 }
103 }
104
105 #[must_use]
107 pub fn walk_source(path: &Path, source: &str) -> Vec<InventoryEntry> {
108 fallow_extract::inventory::walk_source(path, source)
109 .into_iter()
110 .map(InventoryEntry::from)
111 .collect()
112 }
113
114 #[must_use]
116 pub fn walk_source_with_complexity(
117 path: &Path,
118 source: &str,
119 ) -> (Vec<InventoryEntry>, FxHashMap<String, InventoryComplexity>) {
120 let (entries, complexity) =
121 fallow_extract::inventory::walk_source_with_complexity(path, source);
122 let entries = entries.into_iter().map(InventoryEntry::from).collect();
123 let complexity = complexity
124 .into_iter()
125 .map(|(hash, metrics)| (hash, InventoryComplexity::from(metrics)))
126 .collect();
127 (entries, complexity)
128 }
129}
130
131#[must_use]
142pub(crate) fn parse_all_files(
143 files: &[DiscoveredFile],
144 cache: Option<&CacheStore>,
145 need_complexity: bool,
146 cancellation: Option<&AtomicBool>,
147 flag_patterns: &fallow_types::extract::FlagPatterns,
148) -> ParseResult {
149 fallow_extract::parse_all_files_cancellable(
150 files,
151 cache,
152 need_complexity,
153 cancellation,
154 flag_patterns,
155 )
156}