1pub mod languages;
15pub mod parser;
16
17pub use languages::{get_extractor, LanguageExtractor};
18pub use parser::AstParser;
19
20use serde::{Deserialize, Serialize};
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(rename_all = "snake_case")]
25pub enum SymbolKind {
26 Function,
28 Method,
30 Class,
32 Struct,
34 Interface,
36 Trait,
38 Enum,
40 EnumVariant,
42 Constant,
44 Variable,
46 TypeAlias,
48 Module,
50 Namespace,
52 Property,
54 Field,
56 Impl,
58}
59
60impl std::fmt::Display for SymbolKind {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 match self {
63 Self::Function => write!(f, "function"),
64 Self::Method => write!(f, "method"),
65 Self::Class => write!(f, "class"),
66 Self::Struct => write!(f, "struct"),
67 Self::Interface => write!(f, "interface"),
68 Self::Trait => write!(f, "trait"),
69 Self::Enum => write!(f, "enum"),
70 Self::EnumVariant => write!(f, "enum_variant"),
71 Self::Constant => write!(f, "constant"),
72 Self::Variable => write!(f, "variable"),
73 Self::TypeAlias => write!(f, "type_alias"),
74 Self::Module => write!(f, "module"),
75 Self::Namespace => write!(f, "namespace"),
76 Self::Property => write!(f, "property"),
77 Self::Field => write!(f, "field"),
78 Self::Impl => write!(f, "impl"),
79 }
80 }
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
85#[serde(rename_all = "snake_case")]
86pub enum Visibility {
87 #[default]
89 Public,
90 Private,
92 Protected,
94 Internal,
96 Crate,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct Parameter {
103 pub name: String,
105 pub type_info: Option<String>,
107 pub default_value: Option<String>,
109 pub is_rest: bool,
111 pub is_optional: bool,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct ExtractedSymbol {
118 pub name: String,
120 pub qualified_name: Option<String>,
122 pub kind: SymbolKind,
124 pub start_line: usize,
126 pub end_line: usize,
128 pub start_col: usize,
130 pub end_col: usize,
132 pub signature: Option<String>,
134 pub visibility: Visibility,
136 pub doc_comment: Option<String>,
138 pub parent: Option<String>,
140 pub type_info: Option<String>,
142 pub parameters: Vec<Parameter>,
144 pub return_type: Option<String>,
146 pub exported: bool,
148 pub is_async: bool,
150 pub is_static: bool,
152 pub generics: Vec<String>,
154}
155
156impl ExtractedSymbol {
157 pub fn new(name: String, kind: SymbolKind, start_line: usize, end_line: usize) -> Self {
159 Self {
160 name,
161 qualified_name: None,
162 kind,
163 start_line,
164 end_line,
165 start_col: 0,
166 end_col: 0,
167 signature: None,
168 visibility: Visibility::default(),
169 doc_comment: None,
170 parent: None,
171 type_info: None,
172 parameters: Vec::new(),
173 return_type: None,
174 exported: false,
175 is_async: false,
176 is_static: false,
177 generics: Vec::new(),
178 }
179 }
180
181 pub fn with_qualified_name(mut self, name: impl Into<String>) -> Self {
183 self.qualified_name = Some(name.into());
184 self
185 }
186
187 pub fn with_columns(mut self, start_col: usize, end_col: usize) -> Self {
189 self.start_col = start_col;
190 self.end_col = end_col;
191 self
192 }
193
194 pub fn with_signature(mut self, sig: impl Into<String>) -> Self {
196 self.signature = Some(sig.into());
197 self
198 }
199
200 pub fn with_visibility(mut self, vis: Visibility) -> Self {
202 self.visibility = vis;
203 self
204 }
205
206 pub fn with_doc_comment(mut self, doc: impl Into<String>) -> Self {
208 self.doc_comment = Some(doc.into());
209 self
210 }
211
212 pub fn with_parent(mut self, parent: impl Into<String>) -> Self {
214 self.parent = Some(parent.into());
215 self
216 }
217
218 pub fn with_return_type(mut self, ret: impl Into<String>) -> Self {
220 self.return_type = Some(ret.into());
221 self
222 }
223
224 pub fn exported(mut self) -> Self {
226 self.exported = true;
227 self
228 }
229
230 pub fn async_fn(mut self) -> Self {
232 self.is_async = true;
233 self
234 }
235
236 pub fn static_fn(mut self) -> Self {
238 self.is_static = true;
239 self
240 }
241
242 pub fn add_parameter(&mut self, param: Parameter) {
244 self.parameters.push(param);
245 }
246
247 pub fn add_generic(&mut self, generic: impl Into<String>) {
249 self.generics.push(generic.into());
250 }
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize)]
255pub struct Import {
256 pub source: String,
258 pub names: Vec<ImportedName>,
260 pub is_default: bool,
262 pub is_namespace: bool,
264 pub line: usize,
266}
267
268#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct ImportedName {
271 pub name: String,
273 pub alias: Option<String>,
275}
276
277#[derive(Debug, Clone, Serialize, Deserialize)]
279pub struct FunctionCall {
280 pub caller: String,
282 pub callee: String,
284 pub line: usize,
286 pub is_method: bool,
288 pub receiver: Option<String>,
290}