Trait for language-specific AST entity extraction. Each language parser implements this trait, providing entity extraction (functions, classes, interfaces, etc.) and optionally reference extraction (function calls, variable usages). # Implementation Notes - Parsers are **stateful** (they hold a `tree_sitter::Parser` instance). Create one per thread or per request, not globally. - `extract()` sh
| 182 | /// - Entity names should be the *simple* name (e.g., `greet`, not `module.greet`). |
| 183 | /// - Line numbers are 1-based (matching editor conventions). |
| 184 | pub trait LanguageParser: Send { |
| 185 | /// The language this parser handles. |
| 186 | fn language(&self) -> Language; |
| 187 | |
| 188 | /// Parse a full source file for structural inspection. Error nodes remain |
| 189 | /// visible; callers must not treat a recovered syntax tree as a clean parse. |
| 190 | /// External entity-only parsers can leave this unsupported. |
| 191 | fn parse_tree(&mut self, _source: &str) -> Option<tree_sitter::Tree> { |
| 192 | None |
| 193 | } |
| 194 | |
| 195 | /// Extract AST entities (functions, classes, etc.) from source code. |
| 196 | /// |
| 197 | /// # Arguments |
| 198 | /// |
| 199 | /// * `source` - The source code text. |
| 200 | /// * `file_path` - The file path (for Entity.file field). |
| 201 | /// |
| 202 | /// # Returns |
| 203 | /// |
| 204 | /// A list of entities found in the source code. |
| 205 | fn extract(&mut self, source: &str, file_path: &str) -> Vec<Entity>; |
| 206 | |
| 207 | /// Reuse a registered grammar's tree when enriching existing entities. |
| 208 | /// Entity-only adapters may fall back to their ordinary extraction path. |
| 209 | fn extract_from_tree( |
| 210 | &mut self, |
| 211 | _tree: &tree_sitter::Tree, |
| 212 | source: &str, |
| 213 | file_path: &str, |
| 214 | ) -> Vec<Entity> { |
| 215 | self.extract(source, file_path) |
| 216 | } |
| 217 | |
| 218 | /// Extract references (function calls, variable usages) from source code. |
| 219 | /// |
| 220 | /// The default implementation returns an empty list. Languages that |
| 221 | /// support reference extraction should override this. |
| 222 | /// |
| 223 | /// # Arguments |
| 224 | /// |
| 225 | /// * `source` - The source code text. |
| 226 | /// * `file_path` - The file path (for Reference.file field). |
| 227 | /// |
| 228 | /// # Returns |
| 229 | /// |
| 230 | /// A list of references found in the source code. |
| 231 | fn extract_references(&mut self, source: &str, file_path: &str) -> Vec<Reference> { |
| 232 | let _ = (source, file_path); |
| 233 | Vec::new() |
| 234 | } |
| 235 | |
| 236 | /// Visit references without reparsing. The tree must use this parser's |
| 237 | /// configured grammar and correspond to `source`. |
| 238 | fn extract_references_from_tree( |
| 239 | &mut self, |
| 240 | _tree: &tree_sitter::Tree, |
| 241 | source: &str, |
nothing calls this directly
no outgoing calls
no test coverage detected