refactor: LanguageExtractor gains explicit 3-phase trait + run_extraction pipeline
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
use tree_sitter::{Node, Parser};
|
||||
use tree_sitter::Node;
|
||||
|
||||
use archlens_domain::{
|
||||
AnalysisResult, CodeElement, CodeElementKind, DomainError, FilePath, Relationship,
|
||||
RelationshipKind,
|
||||
};
|
||||
use archlens_domain::{CodeElement, CodeElementKind, Relationship, RelationshipKind};
|
||||
|
||||
use crate::extraction_context::ExtractionContext;
|
||||
use crate::language_extractor::LanguageExtractor;
|
||||
@@ -11,28 +8,23 @@ use crate::language_extractor::LanguageExtractor;
|
||||
pub struct PythonExtractor;
|
||||
|
||||
impl LanguageExtractor for PythonExtractor {
|
||||
fn analyze(&self, source: &str, file_path: &FilePath) -> Result<AnalysisResult, DomainError> {
|
||||
analyze(source, file_path)
|
||||
fn tree_sitter_language(&self) -> tree_sitter::Language {
|
||||
tree_sitter_python::LANGUAGE.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn analyze(source: &str, file_path: &FilePath) -> Result<AnalysisResult, DomainError> {
|
||||
let mut parser = Parser::new();
|
||||
parser
|
||||
.set_language(&tree_sitter_python::LANGUAGE.into())
|
||||
.map_err(|e| DomainError::AnalysisError(e.to_string()))?;
|
||||
fn extract_types(&self, root: &Node, source: &str, ctx: &mut ExtractionContext) {
|
||||
// collect_classes handles class elements, inheritance, and field compositions
|
||||
// in a single pass — Python's relationship extraction is interleaved with type extraction
|
||||
collect_classes(root, source, ctx);
|
||||
}
|
||||
|
||||
let tree = parser
|
||||
.parse(source, None)
|
||||
.ok_or_else(|| DomainError::AnalysisError("failed to parse".to_string()))?;
|
||||
fn extract_relationships(&self, _root: &Node, _source: &str, _ctx: &mut ExtractionContext) {
|
||||
// Relationships are collected inside collect_classes for Python
|
||||
}
|
||||
|
||||
let mut ctx = ExtractionContext::new(file_path.clone());
|
||||
let root = tree.root_node();
|
||||
|
||||
collect_classes(&root, source, &mut ctx);
|
||||
collect_imports(&root, source, &mut ctx);
|
||||
|
||||
ctx.into_result()
|
||||
fn extract_imports(&self, root: &Node, source: &str, ctx: &mut ExtractionContext) {
|
||||
collect_imports(root, source, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_classes(node: &Node, source: &str, ctx: &mut ExtractionContext) {
|
||||
|
||||
Reference in New Issue
Block a user