reflex/pulse/extract/surface/
mod.rs1pub mod go;
8pub mod python;
9pub mod rust;
10
11use crate::parsers::api::{ApiItem, DocComment};
12use std::collections::BTreeMap;
13
14#[derive(Debug, Clone, Default)]
16pub struct Surface {
17 pub packages: Vec<Package>,
18}
19
20#[derive(Debug, Clone)]
21pub struct Package {
23 pub name: String,
25 pub lang: crate::models::Language,
26 pub sep: &'static str,
28 pub package: String,
30 pub manifest: String,
31 pub is_lib: bool,
32 pub root_file: String,
33 pub modules: Vec<SurfaceModule>,
35}
36
37#[derive(Debug, Clone)]
38pub struct SurfaceModule {
39 pub path: String,
41 pub name: String,
42 pub file: String,
43 pub public: bool,
44 pub doc: Option<DocComment>,
45 pub items: Vec<SurfaceItem>,
46 pub children: Vec<usize>,
47 pub parent: Option<usize>,
48}
49
50#[derive(Debug, Clone)]
51pub struct SurfaceItem {
52 pub item: ApiItem,
54 pub file: String,
55 pub public: bool,
56 pub path: String,
58 pub defined_at: Option<String>,
60 pub impl_files: BTreeMap<usize, String>,
62}
63
64impl Surface {
65 pub fn libraries(&self) -> impl Iterator<Item = &Package> {
67 self.packages.iter().filter(|c| c.is_lib)
68 }
69
70 pub fn extend(&mut self, other: Surface) {
71 self.packages.extend(other.packages);
72 }
73}
74
75impl Package {
76 pub fn join(&self, a: &str, b: &str) -> String {
78 format!("{a}{}{b}", self.sep)
79 }
80
81 pub fn lang_id(&self) -> String {
83 serde_json::to_value(self.lang)
84 .ok()
85 .and_then(|v| v.as_str().map(str::to_string))
86 .unwrap_or_else(|| "text".into())
87 }
88}