Add code analyzers (Python, JS, Go, Rust) with tree-sitter
This commit is contained in:
39
src/auto_readme/analyzers/analyzer_factory.py
Normal file
39
src/auto_readme/analyzers/analyzer_factory.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"""Code analyzer factory for routing to correct analyzer."""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from . import CodeAnalyzer
|
||||||
|
from .python_analyzer import PythonAnalyzer
|
||||||
|
from .javascript_analyzer import JavaScriptAnalyzer
|
||||||
|
from .go_analyzer import GoAnalyzer
|
||||||
|
from .rust_analyzer import RustAnalyzer
|
||||||
|
|
||||||
|
|
||||||
|
class CodeAnalyzerFactory:
|
||||||
|
"""Factory for creating appropriate code analyzers."""
|
||||||
|
|
||||||
|
ANALYZERS = [
|
||||||
|
PythonAnalyzer(),
|
||||||
|
JavaScriptAnalyzer(),
|
||||||
|
GoAnalyzer(),
|
||||||
|
RustAnalyzer(),
|
||||||
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_analyzer(cls, path: Path) -> Optional[CodeAnalyzer]:
|
||||||
|
"""Get the appropriate analyzer for a file."""
|
||||||
|
for analyzer in cls.ANALYZERS:
|
||||||
|
if analyzer.can_analyze(path):
|
||||||
|
return analyzer
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all_analyzers(cls) -> list[CodeAnalyzer]:
|
||||||
|
"""Get all available analyzers."""
|
||||||
|
return cls.ANALYZERS.copy()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def can_analyze(cls, path: Path) -> bool:
|
||||||
|
"""Check if any analyzer can handle the file."""
|
||||||
|
return cls.get_analyzer(path) is not None
|
||||||
Reference in New Issue
Block a user