1use lasso::Spur;
9use std::path::PathBuf;
10
11pub type InternedString = Spur;
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16pub struct SymbolId(pub u32);
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub struct FileId(pub u32);
21
22#[derive(Debug, Clone)]
28pub enum TopologyNode {
29 Crate {
31 name: String,
32 path: PathBuf,
33 is_workspace: bool,
34 },
35 Module {
37 name: String,
38 path: PathBuf,
39 is_inline: bool,
40 },
41 File { path: PathBuf, file_id: FileId },
43}
44
45#[derive(Debug, Clone)]
47pub enum TopologyEdge {
48 Contains,
50 Imports { use_path: String, is_glob: bool },
52 ReExports { original_path: String },
54}
55
56#[derive(Debug, Clone, Default)]
58pub struct TopologyMetrics {
59 pub relevance_score: f64,
61 pub churn_count: u32,
63 pub coverage: Option<f32>,
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Hash)]
73pub struct Location {
74 pub file: PathBuf,
75 pub start_byte: usize,
76 pub end_byte: usize,
77 pub start_line: usize,
78 pub start_col: usize,
79 pub end_line: usize,
80 pub end_col: usize,
81}
82
83impl Location {
84 pub fn new(file: PathBuf, start_byte: usize, end_byte: usize) -> Self {
85 Self {
86 file,
87 start_byte,
88 end_byte,
89 start_line: 0,
90 start_col: 0,
91 end_line: 0,
92 end_col: 0,
93 }
94 }
95
96 pub fn with_positions(
97 mut self,
98 start_line: usize,
99 start_col: usize,
100 end_line: usize,
101 end_col: usize,
102 ) -> Self {
103 self.start_line = start_line;
104 self.start_col = start_col;
105 self.end_line = end_line;
106 self.end_col = end_col;
107 self
108 }
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
113pub enum SymbolKind {
114 Function,
115 Method,
116 Struct,
117 Enum,
118 Trait,
119 Impl,
120 Const,
121 Static,
122 Module,
123 TypeAlias,
124 Macro,
125 Field,
126 Variant,
127}
128
129impl SymbolKind {
130 pub fn as_str(&self) -> &'static str {
131 match self {
132 Self::Function => "function",
133 Self::Method => "method",
134 Self::Struct => "struct",
135 Self::Enum => "enum",
136 Self::Trait => "trait",
137 Self::Impl => "impl",
138 Self::Const => "const",
139 Self::Static => "static",
140 Self::Module => "module",
141 Self::TypeAlias => "type",
142 Self::Macro => "macro",
143 Self::Field => "field",
144 Self::Variant => "variant",
145 }
146 }
147}
148
149#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
151pub enum Visibility {
152 #[default]
153 Private,
154 Crate,
156 Super,
158 Restricted,
160 Public,
162}
163
164#[derive(Debug, Clone, Default)]
166pub struct Signature {
167 pub params: Vec<String>,
168 pub return_type: Option<String>,
169 pub is_async: bool,
170 pub is_unsafe: bool,
171 pub is_const: bool,
172 pub generics: Option<String>,
173 pub where_clause: Option<String>,
174}
175
176#[derive(Debug, Clone)]
178pub struct SymbolDef {
179 pub name: InternedString,
181 pub scoped_name: InternedString,
183 pub kind: SymbolKind,
185 pub location: Location,
187 pub signature: Option<Signature>,
189 pub visibility: Visibility,
191 pub attributes: Vec<String>,
193 pub doc_comment: Option<String>,
195 pub parent: Option<InternedString>,
197}
198
199#[derive(Debug, Clone)]
201pub struct CallEdge {
202 pub caller: InternedString,
204 pub callee_name: String,
206 pub location: Location,
208 pub is_method_call: bool,
210}
211
212#[derive(Debug, Clone)]
214pub struct ImportInfo {
215 pub path: String,
217 pub name: String,
219 pub is_glob: bool,
221 pub location: Location,
223}
224
225#[derive(Debug, Clone)]
231pub struct SemanticEntry {
232 pub symbol_id: SymbolId,
233 pub scoped_name: InternedString,
234 pub embedding: EmbeddingData,
236}
237
238#[derive(Debug, Clone)]
240pub enum EmbeddingData {
241 Float32(Vec<f32>),
243 Binary(Vec<u8>),
245}
246
247impl EmbeddingData {
248 pub fn dimension(&self) -> usize {
249 match self {
250 Self::Float32(v) => v.len(),
251 Self::Binary(v) => v.len() * 8,
252 }
253 }
254}
255
256#[derive(Debug, Clone)]
262pub struct DeadCodeReport {
263 pub dead_symbols: Vec<InternedString>,
265 pub entry_points: Vec<InternedString>,
267 pub potentially_live: Vec<InternedString>,
269}
270
271#[derive(Debug, Clone)]
273pub struct SymbolCoverage {
274 pub symbol: InternedString,
275 pub lines_covered: u32,
276 pub lines_total: u32,
277 pub branches_covered: u32,
278 pub branches_total: u32,
279}
280
281#[derive(Debug, Clone, Copy, PartialEq, Eq)]
287pub enum InterventionSeverity {
288 Info,
290 Warning,
292 Block,
294}
295
296#[derive(Debug, Clone)]
298pub struct Intervention {
299 pub severity: InterventionSeverity,
300 pub message: String,
301 pub existing_symbol: InternedString,
302 pub existing_location: Location,
303 pub similarity_score: f32,
304 pub recommendation: String,
305}
306
307#[derive(Debug, Clone)]
309pub struct SimilarityMatch {
310 pub symbol: InternedString,
311 pub location: Location,
312 pub score: f32,
313 pub kind: SymbolKind,
314}
315
316#[derive(Debug, Clone, Default)]
322pub struct SearchOptions {
323 pub limit: Option<usize>,
325 pub kind_filter: Option<Vec<SymbolKind>>,
327 pub file_pattern: Option<String>,
329 pub include_private: bool,
331 pub context_before: usize,
333 pub context_after: usize,
335}
336
337#[derive(Debug, Clone)]
339pub struct SearchResult {
340 pub symbol: InternedString,
341 pub kind: SymbolKind,
342 pub location: Location,
343 pub score: f32,
344 pub snippet: Option<String>,
345}