Add code analyzers (Python, JS, Go, Rust) with tree-sitter
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled

This commit is contained in:
2026-02-05 08:42:30 +00:00
parent 3345f2c1c9
commit 1c3399e46c

View File

@@ -0,0 +1,55 @@
"""Code analyzers for extracting functions, classes, and imports from source code."""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Protocol
from ..utils.path_utils import PathUtils
class CodeAnalyzer(Protocol):
"""Protocol for code analyzers."""
def can_analyze(self, path: Path) -> bool: ...
def analyze(self, path: Path) -> dict: ...
class BaseAnalyzer(ABC):
"""Abstract base class for code analyzers."""
@abstractmethod
def can_analyze(self, path: Path) -> bool:
"""Check if this analyzer can handle the file."""
pass
@abstractmethod
def analyze(self, path: Path) -> dict:
"""Analyze the file and return extracted information."""
pass
def _get_file_content(self, path: Path) -> str | None:
"""Safely read file content."""
try:
if PathUtils.get_file_size(path) > 1024 * 1024:
return None
with open(path, "r", encoding="utf-8", errors="ignore") as f:
return f.read()
except OSError:
return None
from .python_analyzer import PythonAnalyzer
from .javascript_analyzer import JavaScriptAnalyzer
from .go_analyzer import GoAnalyzer
from .rust_analyzer import RustAnalyzer
from .analyzer_factory import CodeAnalyzerFactory
__all__ = [
"CodeAnalyzer",
"BaseAnalyzer",
"PythonAnalyzer",
"JavaScriptAnalyzer",
"GoAnalyzer",
"RustAnalyzer",
"CodeAnalyzerFactory",
]