refactor: deepen modules, consolidate inference, delete dead code
- Extract build_graph/load_config/create_renderer in presentation (393→~250 lines) - Move module inference into ModuleName::from_path(), delete 3 scattered copies - Move resolve_relationships/filter_external_imports into CodeGraph - Add LanguageExtractor trait in tree-sitter adapter - Add CodeGraph::elements_by_module(), replace 6 identical grouping loops - Delete dead RenderDiagrams query
This commit is contained in:
5
crates/adapters/tree-sitter/src/language_extractor.rs
Normal file
5
crates/adapters/tree-sitter/src/language_extractor.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
use archlens_domain::{AnalysisResult, DomainError, FilePath};
|
||||
|
||||
pub trait LanguageExtractor {
|
||||
fn analyze(&self, source: &str, file_path: &FilePath) -> Result<AnalysisResult, DomainError>;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod language_extractor;
|
||||
mod python;
|
||||
mod rust;
|
||||
mod tree_sitter_analyzer;
|
||||
|
||||
@@ -7,6 +7,16 @@ use archlens_domain::{
|
||||
Relationship, RelationshipKind,
|
||||
};
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn analyze(source: &str, file_path: &FilePath) -> Result<AnalysisResult, DomainError> {
|
||||
let mut parser = Parser::new();
|
||||
parser
|
||||
|
||||
@@ -42,6 +42,16 @@ use archlens_domain::{
|
||||
Relationship, RelationshipKind, Visibility,
|
||||
};
|
||||
|
||||
use crate::language_extractor::LanguageExtractor;
|
||||
|
||||
pub struct RustExtractor;
|
||||
|
||||
impl LanguageExtractor for RustExtractor {
|
||||
fn analyze(&self, source: &str, file_path: &FilePath) -> Result<AnalysisResult, DomainError> {
|
||||
analyze(source, file_path)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn analyze(source: &str, file_path: &FilePath) -> Result<AnalysisResult, DomainError> {
|
||||
let mut parser = Parser::new();
|
||||
parser
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
use archlens_domain::{AnalysisResult, DomainError, Language, SourceFile, ports::SourceAnalyzer};
|
||||
|
||||
use crate::{python, rust};
|
||||
use crate::language_extractor::LanguageExtractor;
|
||||
use crate::python::PythonExtractor;
|
||||
use crate::rust::RustExtractor;
|
||||
|
||||
pub struct TreeSitterAnalyzer;
|
||||
pub struct TreeSitterAnalyzer {
|
||||
rust: RustExtractor,
|
||||
python: PythonExtractor,
|
||||
}
|
||||
|
||||
impl Default for TreeSitterAnalyzer {
|
||||
fn default() -> Self {
|
||||
@@ -12,7 +17,18 @@ impl Default for TreeSitterAnalyzer {
|
||||
|
||||
impl TreeSitterAnalyzer {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
Self {
|
||||
rust: RustExtractor,
|
||||
python: PythonExtractor,
|
||||
}
|
||||
}
|
||||
|
||||
fn extractor_for(&self, language: Language) -> Option<&dyn LanguageExtractor> {
|
||||
match language {
|
||||
Language::Rust => Some(&self.rust),
|
||||
Language::Python => Some(&self.python),
|
||||
Language::CSharp => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +37,9 @@ impl SourceAnalyzer for TreeSitterAnalyzer {
|
||||
let source = std::fs::read_to_string(file.path().as_str())
|
||||
.map_err(|e| DomainError::IoError(e.to_string()))?;
|
||||
|
||||
match file.language() {
|
||||
Language::Rust => rust::analyze(&source, file.path()),
|
||||
Language::Python => python::analyze(&source, file.path()),
|
||||
Language::CSharp => Ok(AnalysisResult::empty()),
|
||||
match self.extractor_for(file.language()) {
|
||||
Some(extractor) => extractor.analyze(&source, file.path()),
|
||||
None => Ok(AnalysisResult::empty()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user