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