agentic_codebase/parse/
mod.rs1pub mod cpp;
7pub mod go;
8pub mod parser;
9pub mod python;
10pub mod rust;
11pub mod treesitter;
12pub mod typescript;
13
14pub use parser::{ParseOptions, ParseResult, ParseStats, Parser};
15
16use std::collections::HashMap;
17use std::path::{Path, PathBuf};
18
19use crate::types::{AcbResult, CodeUnitType, Language, Span, Visibility};
20
21#[derive(Debug, Clone)]
23pub struct RawCodeUnit {
24 pub temp_id: u64,
26 pub unit_type: CodeUnitType,
28 pub language: Language,
30 pub name: String,
32 pub qualified_name: String,
34 pub file_path: PathBuf,
36 pub span: Span,
38 pub signature: Option<String>,
40 pub doc: Option<String>,
42 pub visibility: Visibility,
44 pub is_async: bool,
46 pub is_generator: bool,
48 pub complexity: u32,
50 pub references: Vec<RawReference>,
52 pub children: Vec<u64>,
54 pub parent: Option<u64>,
56 pub metadata: HashMap<String, String>,
58}
59
60impl RawCodeUnit {
61 pub fn new(
63 unit_type: CodeUnitType,
64 language: Language,
65 name: String,
66 file_path: PathBuf,
67 span: Span,
68 ) -> Self {
69 let qualified_name = name.clone();
70 Self {
71 temp_id: 0,
72 unit_type,
73 language,
74 name,
75 qualified_name,
76 file_path,
77 span,
78 signature: None,
79 doc: None,
80 visibility: Visibility::Unknown,
81 is_async: false,
82 is_generator: false,
83 complexity: 0,
84 references: Vec::new(),
85 children: Vec::new(),
86 parent: None,
87 metadata: HashMap::new(),
88 }
89 }
90}
91
92#[derive(Debug, Clone)]
94pub struct RawReference {
95 pub name: String,
97 pub kind: ReferenceKind,
99 pub span: Span,
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq)]
105pub enum ReferenceKind {
106 Import,
108 Call,
110 TypeUse,
112 Inherit,
114 Implement,
116 Access,
118}
119
120#[derive(Debug, Clone)]
122pub struct ParseFileError {
123 pub path: PathBuf,
125 pub span: Option<Span>,
127 pub message: String,
129 pub severity: Severity,
131}
132
133#[derive(Debug, Clone, Copy, PartialEq, Eq)]
135pub enum Severity {
136 Error,
138 Warning,
140 Info,
142}
143
144pub trait LanguageParser: Send + Sync {
146 fn extract_units(
148 &self,
149 tree: &tree_sitter::Tree,
150 source: &str,
151 file_path: &Path,
152 ) -> AcbResult<Vec<RawCodeUnit>>;
153
154 fn is_test_file(&self, path: &Path, source: &str) -> bool;
156}