agentic_codebase/parse/
mod.rs1pub mod go;
7pub mod parser;
8pub mod python;
9pub mod rust;
10pub mod treesitter;
11pub mod typescript;
12
13pub use parser::{ParseOptions, ParseResult, ParseStats, Parser};
14
15use std::collections::HashMap;
16use std::path::{Path, PathBuf};
17
18use crate::types::{AcbResult, CodeUnitType, Language, Span, Visibility};
19
20#[derive(Debug, Clone)]
22pub struct RawCodeUnit {
23 pub temp_id: u64,
25 pub unit_type: CodeUnitType,
27 pub language: Language,
29 pub name: String,
31 pub qualified_name: String,
33 pub file_path: PathBuf,
35 pub span: Span,
37 pub signature: Option<String>,
39 pub doc: Option<String>,
41 pub visibility: Visibility,
43 pub is_async: bool,
45 pub is_generator: bool,
47 pub complexity: u32,
49 pub references: Vec<RawReference>,
51 pub children: Vec<u64>,
53 pub parent: Option<u64>,
55 pub metadata: HashMap<String, String>,
57}
58
59impl RawCodeUnit {
60 pub fn new(
62 unit_type: CodeUnitType,
63 language: Language,
64 name: String,
65 file_path: PathBuf,
66 span: Span,
67 ) -> Self {
68 let qualified_name = name.clone();
69 Self {
70 temp_id: 0,
71 unit_type,
72 language,
73 name,
74 qualified_name,
75 file_path,
76 span,
77 signature: None,
78 doc: None,
79 visibility: Visibility::Unknown,
80 is_async: false,
81 is_generator: false,
82 complexity: 0,
83 references: Vec::new(),
84 children: Vec::new(),
85 parent: None,
86 metadata: HashMap::new(),
87 }
88 }
89}
90
91#[derive(Debug, Clone)]
93pub struct RawReference {
94 pub name: String,
96 pub kind: ReferenceKind,
98 pub span: Span,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub enum ReferenceKind {
105 Import,
107 Call,
109 TypeUse,
111 Inherit,
113 Implement,
115 Access,
117}
118
119#[derive(Debug, Clone)]
121pub struct ParseFileError {
122 pub path: PathBuf,
124 pub span: Option<Span>,
126 pub message: String,
128 pub severity: Severity,
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq)]
134pub enum Severity {
135 Error,
137 Warning,
139 Info,
141}
142
143pub trait LanguageParser: Send + Sync {
145 fn extract_units(
147 &self,
148 tree: &tree_sitter::Tree,
149 source: &str,
150 file_path: &Path,
151 ) -> AcbResult<Vec<RawCodeUnit>>;
152
153 fn is_test_file(&self, path: &Path, source: &str) -> bool;
155}