infiniloom_engine/index/builder/
types.rs1use crate::parser::Parser;
6use crate::types::Visibility as TypesVisibility;
7use crate::SymbolKind;
8use once_cell::sync::Lazy;
9use regex::Regex;
10use std::cell::RefCell;
11use std::collections::HashSet;
12use std::path::PathBuf;
13use thiserror::Error;
14
15use super::super::types::{Import, Language};
16
17thread_local! {
19 pub(super) static THREAD_PARSER: RefCell<Parser> = RefCell::new(Parser::new());
20}
21
22#[derive(Error, Debug)]
24pub enum BuildError {
25 #[error("IO error: {0}")]
26 Io(#[from] std::io::Error),
27
28 #[error("Parse error in {file}: {message}")]
29 Parse { file: String, message: String },
30
31 #[error("Repository not found: {0}")]
32 RepoNotFound(PathBuf),
33
34 #[error("Git error: {0}")]
35 Git(String),
36}
37
38pub(super) static IDENT_RE: Lazy<Regex> = Lazy::new(|| {
39 Regex::new(r"[A-Za-z_][A-Za-z0-9_]*").expect("IDENT_RE: invalid regex pattern")
40});
41
42pub(super) static COMMON_KEYWORDS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
43 [
44 "if",
45 "else",
46 "for",
47 "while",
48 "return",
49 "break",
50 "continue",
51 "match",
52 "case",
53 "switch",
54 "default",
55 "try",
56 "catch",
57 "throw",
58 "finally",
59 "yield",
60 "await",
61 "async",
62 "new",
63 "in",
64 "of",
65 "do",
66 "fn",
67 "function",
68 "def",
69 "class",
70 "struct",
71 "enum",
72 "trait",
73 "interface",
74 "type",
75 "impl",
76 "let",
77 "var",
78 "const",
79 "static",
80 "public",
81 "private",
82 "protected",
83 "internal",
84 "use",
85 "import",
86 "from",
87 "package",
88 "module",
89 "export",
90 "super",
91 "self",
92 "this",
93 "crate",
94 "pub",
95 "mod",
96 ]
97 .into_iter()
98 .collect()
99});
100
101#[derive(Debug, Clone)]
103pub struct BuildOptions {
104 pub respect_gitignore: bool,
106 pub max_file_size: u64,
108 pub include_extensions: Vec<String>,
110 pub exclude_dirs: Vec<String>,
112 pub compute_pagerank: bool,
114}
115
116impl Default for BuildOptions {
117 fn default() -> Self {
118 Self {
119 respect_gitignore: true,
120 max_file_size: 10 * 1024 * 1024, include_extensions: vec![],
122 exclude_dirs: vec![
123 "node_modules".into(),
124 ".git".into(),
125 "target".into(),
126 "build".into(),
127 "dist".into(),
128 "__pycache__".into(),
129 ".venv".into(),
130 "venv".into(),
131 ],
132 compute_pagerank: true,
133 }
134 }
135}
136
137pub(super) struct ParsedFile {
139 pub path: String,
140 pub language: Language,
141 pub content_hash: [u8; 32],
142 pub lines: u32,
143 pub tokens: u32,
144 pub symbols: Vec<ParsedSymbol>,
145 pub imports: Vec<Import>,
146}
147
148pub(super) struct ParsedSymbol {
150 pub name: String,
151 pub kind: SymbolKind,
152 pub start_line: u32,
153 pub end_line: u32,
154 pub signature: Option<String>,
155 pub docstring: Option<String>,
156 pub parent: Option<String>,
157 pub visibility: TypesVisibility,
158 pub calls: Vec<String>,
159}