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 pub definition_start_line: Option<usize>,
158}
159
160impl ExtractedSymbol {
161 pub fn new(name: String, kind: SymbolKind, start_line: usize, end_line: usize) -> Self {
163 Self {
164 name,
165 qualified_name: None,
166 kind,
167 start_line,
168 end_line,
169 start_col: 0,
170 end_col: 0,
171 signature: None,
172 visibility: Visibility::default(),
173 doc_comment: None,
174 parent: None,
175 type_info: None,
176 parameters: Vec::new(),
177 return_type: None,
178 exported: false,
179 is_async: false,
180 is_static: false,
181 generics: Vec::new(),
182 definition_start_line: None,
183 }
184 }
185
186 pub fn with_qualified_name(mut self, name: impl Into<String>) -> Self {
188 self.qualified_name = Some(name.into());
189 self
190 }
191
192 pub fn with_columns(mut self, start_col: usize, end_col: usize) -> Self {
194 self.start_col = start_col;
195 self.end_col = end_col;
196 self
197 }
198
199 pub fn with_signature(mut self, sig: impl Into<String>) -> Self {
201 self.signature = Some(sig.into());
202 self
203 }
204
205 pub fn with_visibility(mut self, vis: Visibility) -> Self {
207 self.visibility = vis;
208 self
209 }
210
211 pub fn with_doc_comment(mut self, doc: impl Into<String>) -> Self {
213 self.doc_comment = Some(doc.into());
214 self
215 }
216
217 pub fn with_parent(mut self, parent: impl Into<String>) -> Self {
219 self.parent = Some(parent.into());
220 self
221 }
222
223 pub fn with_return_type(mut self, ret: impl Into<String>) -> Self {
225 self.return_type = Some(ret.into());
226 self
227 }
228
229 pub fn exported(mut self) -> Self {
231 self.exported = true;
232 self
233 }
234
235 pub fn async_fn(mut self) -> Self {
237 self.is_async = true;
238 self
239 }
240
241 pub fn static_fn(mut self) -> Self {
243 self.is_static = true;
244 self
245 }
246
247 pub fn add_parameter(&mut self, param: Parameter) {
249 self.parameters.push(param);
250 }
251
252 pub fn add_generic(&mut self, generic: impl Into<String>) {
254 self.generics.push(generic.into());
255 }
256
257 pub fn with_definition_start_line(mut self, line: usize) -> Self {
260 self.definition_start_line = Some(line);
261 self
262 }
263}
264
265#[derive(Debug, Clone, Serialize, Deserialize)]
267pub struct Import {
268 pub source: String,
270 pub names: Vec<ImportedName>,
272 pub is_default: bool,
274 pub is_namespace: bool,
276 pub line: usize,
278}
279
280#[derive(Debug, Clone, Serialize, Deserialize)]
282pub struct ImportedName {
283 pub name: String,
285 pub alias: Option<String>,
287}
288
289#[derive(Debug, Clone, Serialize, Deserialize)]
291pub struct FunctionCall {
292 pub caller: String,
294 pub callee: String,
296 pub line: usize,
298 pub is_method: bool,
300 pub receiver: Option<String>,
302}