1use fallow_types::discover::DiscoveredFile;
4#[cfg(test)]
5pub use fallow_types::extract::{ExportName, MemberKind, VisibilityTag};
6pub use fallow_types::extract::{ModuleInfo, ParseResult};
7
8type CacheStore = fallow_extract::cache::CacheStore;
9
10pub mod inventory {
12 use std::path::Path;
13
14 use rustc_hash::FxHashMap;
15
16 #[derive(Debug, Clone, PartialEq, Eq)]
22 pub struct InventoryEntry {
23 pub name: String,
25 pub line: u32,
27 pub start_column: u32,
29 pub end_line: u32,
31 pub end_column: u32,
33 pub source_hash: String,
35 }
36
37 impl From<fallow_extract::inventory::InventoryEntry> for InventoryEntry {
38 fn from(entry: fallow_extract::inventory::InventoryEntry) -> Self {
39 Self {
40 name: entry.name,
41 line: entry.line,
42 start_column: entry.start_column,
43 end_line: entry.end_line,
44 end_column: entry.end_column,
45 source_hash: entry.source_hash,
46 }
47 }
48 }
49
50 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
52 pub struct InventoryComplexity {
53 pub cyclomatic: u16,
55 pub cognitive: u16,
57 }
58
59 impl From<fallow_extract::inventory::InventoryComplexity> for InventoryComplexity {
60 fn from(complexity: fallow_extract::inventory::InventoryComplexity) -> Self {
61 Self {
62 cyclomatic: complexity.cyclomatic,
63 cognitive: complexity.cognitive,
64 }
65 }
66 }
67
68 #[must_use]
70 pub fn walk_source(path: &Path, source: &str) -> Vec<InventoryEntry> {
71 fallow_extract::inventory::walk_source(path, source)
72 .into_iter()
73 .map(InventoryEntry::from)
74 .collect()
75 }
76
77 #[must_use]
79 pub fn walk_source_with_complexity(
80 path: &Path,
81 source: &str,
82 ) -> (Vec<InventoryEntry>, FxHashMap<String, InventoryComplexity>) {
83 let (entries, complexity) =
84 fallow_extract::inventory::walk_source_with_complexity(path, source);
85 let entries = entries.into_iter().map(InventoryEntry::from).collect();
86 let complexity = complexity
87 .into_iter()
88 .map(|(hash, metrics)| (hash, InventoryComplexity::from(metrics)))
89 .collect();
90 (entries, complexity)
91 }
92}
93
94#[must_use]
100pub fn parse_all_files(
101 files: &[DiscoveredFile],
102 cache: Option<&CacheStore>,
103 need_complexity: bool,
104) -> ParseResult {
105 fallow_extract::parse_all_files(files, cache, need_complexity)
106}